CustomerBuilder example

protected function assertLineItemInCart(Cart $cart, string $id): void
    {
        $item = $cart->get($id);

        static::assertInstanceOf(LineItem::class$item, \sprintf('Can not find line item with id %s', $id));
    }

    protected function login(SalesChannelContext $context, ?string $customerId = null): SalesChannelContext
    {
        if ($customerId === null) {
            $customer = new CustomerBuilder(
                new IdsCollection(),
                Uuid::randomHex(),
                $context->getSalesChannelId()
            );

            $this->getContainer()->get('customer.repository')->create(
                [$customer->build()],
                Context::createDefaultContext()
            );

            $customerId = $customer->id;
        }
$this->getContainer()
            ->get(SystemConfigService::class)
            ->set('core.loginRegistration.unusedGuestCustomerLifetime', 86400);
    }

    public function testItDeletesUnusedGuestCustomer(): void
    {
        $context = Context::createDefaultContext();
        $customerRepository = $this->getContainer()->get('customer.repository');

        $customer = (new CustomerBuilder($this->ids, '10000'))
            ->add('guest', true)
            ->add('createdAt', new \DateTime('- 25 hours'));

        $customerRepository->create([$customer->build()]$context);

        static::assertEquals(1, $this->service->countUnusedCustomers($context));

        $this->service->deleteUnusedCustomers($context);

        static::assertEquals(0, $this->service->countUnusedCustomers($context));

        
$this->eventDispatcher->addListener(SalesChannelContextRestorerOrderCriteriaEvent::class$this->callbackFn);
        $this->contextRestorer->restoreByOrder($ids->create('order')$context);

        static::assertArrayHasKey(SalesChannelContextRestorerOrderCriteriaEvent::class$this->events);
        $salesChannelContextRestorerCriteriaEvent = $this->events[SalesChannelContextRestorerOrderCriteriaEvent::class];
        static::assertInstanceOf(SalesChannelContextRestorerOrderCriteriaEvent::class$salesChannelContextRestorerCriteriaEvent);
    }

    private function createOrder(TestDataCollection $ids): void
    {
        $customer = (new CustomerBuilder($ids, '10000'))
            ->add('guest', true)
            ->add('createdAt', new \DateTime('- 25 hours'))->build();

        $data = [
            'id' => $ids->create('order'),
            'itemRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'totalRounding' => json_decode(json_encode(new CashRoundingConfig(2, 0.01, true), \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR),
            'orderNumber' => Uuid::randomHex(),
            'billingAddressId' => $ids->create('billing-address'),
            'currencyId' => Defaults::CURRENCY,
            'languageId' => Defaults::LANGUAGE_SYSTEM,
            
$firstCustomer = $customers->get($this->ids->get('c1'));
        static::assertInstanceOf(CustomerEntity::class$firstCustomer);
        static::assertEquals(1, $firstCustomer->getReviewCount());

        $secondCustomer = $customers->get($this->ids->get('c2'));
        static::assertInstanceOf(CustomerEntity::class$secondCustomer);
        static::assertEquals(1, $secondCustomer->getReviewCount());
    }

    private function createCustomer(string $customerNumber): void
    {
        $customer = (new CustomerBuilder(
            $this->ids,
            $customerNumber
        ))->build();

        $customerRepo = $this->getContainer()->get('customer.repository');
        $customerRepo->create([$customer], Context::createDefaultContext());
    }

    private function createProduct(string $productNumber): void
    {
        $product = new ProductBuilder(
            
private function createProduct(): void
    {
        $builder = new ProductBuilder($this->ids, 'product');
        $builder->price(10);

        $this->productRepository->create([$builder->build()], Context::createDefaultContext());
    }

    private function createCustomer(): void
    {
        $builder = new CustomerBuilder($this->ids, 'customer');

        $this->customerRepository->create([$builder->build()], Context::createDefaultContext());
    }

    private function createReviews(): void
    {
        $this->productReviewRepository->create([
            [
                'id' => $this->ids->create('review'),
                'productId' => $this->ids->get('product'),
                'customerId' => $this->ids->get('customer'),
                
$commandTester = new CommandTester($this->command);
        $commandTester->execute([]);

        $string = $commandTester->getDisplay();
        static::assertIsInt(\mb_strpos($string, 'No unused guest customers found.'));
    }

    public function testExecuteWithoutConfirm(): void
    {
        $customerRepository = $this->getContainer()->get('customer.repository');

        $customerGuestWithOrder = (new CustomerBuilder($this->ids, '10000'))
            ->add('guest', true)
            ->add('createdAt', new \DateTime('- 25 hours'));

        $customerGuest = (new CustomerBuilder($this->ids, '10001'))
            ->add('guest', true)
            ->add('createdAt', new \DateTime('- 25 hours'));

        $customer = (new CustomerBuilder($this->ids, '10002'))
            ->add('guest', false)
            ->add('createdAt', new \DateTime('- 25 hours'));

        
$this->app = $app;
        $this->ids = new IdsCollection();

        $this->resetHistory();
    }

    protected function createCustomer(): string
    {
        $customerId = $this->ids->get('customer');
        $addressId = $this->ids->get('address');

        $customer = (new CustomerBuilder($this->ids, '1337'))
            ->firstName('Max')
            ->lastName('Mustermann')
            ->add('id', $this->ids->get('customer'))
            ->add('email', Uuid::randomHex() . '@example.com')
            ->add('salesChannelId', TestDefaults::SALES_CHANNEL)
            ->add('password', 'shopware')
            ->add('defaultPaymentMethodId', $this->getValidPaymentMethodId())
            ->defaultShippingAddress('address')
            ->defaultBillingAddress('address', [
                'id' => $addressId,
                'customerId' => $customerId,
                
Home | Imprint | This part of the site doesn't use cookies.