createCustomerWishlist example

$response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        $errors = $response['errors'][0];
        static::assertSame(403, $this->browser->getResponse()->getStatusCode());
        static::assertEquals('CHECKOUT__CUSTOMER_NOT_LOGGED_IN', $errors['code']);
        static::assertEquals('Forbidden', $errors['title']);
        static::assertEquals('Customer is not logged in.', $errors['detail']);
    }

    public function testAddProductShouldThrowDuplicateWishlistProductException(): void
    {
        $productData = $this->createProduct($this->context);
        $this->createCustomerWishlist($this->context, $this->customerId, $productData[0]);
        $this->browser
            ->request(
                'POST',
                '/store-api/customer/wishlist/add/' . $productData[0]
            );

        $response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);

        $errors = $response['errors'][0];
        unset($errors['meta']);

        


    public function testWishlistIndex(): void
    {
        $browser = $this->login();

        $salesChannelId = $browser->getRequest()->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_ID);

        $productId = $this->createProduct($salesChannelId);

        // add product to wishlist         $this->createCustomerWishlist($productId$salesChannelId);

        $browser->request('GET', '/wishlist');
        $response = $browser->getResponse();

        static::assertSame(200, $response->getStatusCode()$response->getContent() ?: '');
        static::assertInstanceOf(StorefrontResponse::class$response);
        static::assertInstanceOf(WishlistPage::class$response->getData()['page']);
    }

    public function testWishlistGuestIndex(): void
    {
        
static::assertNotEmpty($contextToken);

        $this->browser->setServerParameter('HTTP_SW_CONTEXT_TOKEN', $contextToken);
    }

    public function testDeleteProductShouldReturnSuccess(): void
    {
        $productId = $this->createProduct($this->context);
        $dispatcher = $this->getContainer()->get('event_dispatcher');
        $eventWasThrown = false;

        $this->createCustomerWishlist($this->context, $this->customerId, $productId);

        $listener = static function DWishlistProductRemovedEvent $event) use ($productId, &$eventWasThrown): void {
            static::assertSame($productId$event->getProductId());
            $eventWasThrown = true;
        };
        $dispatcher->addListener(WishlistProductRemovedEvent::class$listener);

        $this->browser
            ->request(
                'DELETE',
                '/store-api/customer/wishlist/delete/' . $productId
            );
// After login successfully, the context token will be set in the header         $contextToken = $response->headers->get(PlatformRequest::HEADER_CONTEXT_TOKEN) ?? '';
        static::assertNotEmpty($contextToken);

        $this->browser->setServerParameter('HTTP_SW_CONTEXT_TOKEN', $contextToken);
    }

    public function testLoadShouldReturnSuccess(): void
    {
        $productId = $this->createProduct($this->context);
        $customerWishlistId = $this->createCustomerWishlist($this->context, $this->customerId, $productId);

        $this->browser
            ->request(
                'POST',
                '/store-api/customer/wishlist'
            );
        $response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        $wishlist = $response['wishlist'];
        $products = $response['products'];

        static::assertNotEmpty($response);
        
public function testItLoadsWishlistPage(): void
    {
        $request = new Request();
        $context = $this->createSalesChannelContextWithLoggedInCustomerAndWithNavigation();

        $this->systemConfigService->set('core.cart.wishlistEnabled', true);

        $product = $this->getRandomProduct($context);
        $customer = $context->getCustomer();
        static::assertInstanceOf(CustomerEntity::class$customer);
        $this->createCustomerWishlist($customer->getId()$product->getId()$context->getSalesChannel()->getId());

        $event = null;
        $this->catchEvent(WishlistPageLoadedEvent::class$event);
        $page = $this->getPageLoader()->load($request$context$customer);

        static::assertInstanceOf(PageLoadedEvent::class$event);

        static::assertInstanceOf(WishlistPage::class$page);
        static::assertSame(1, $page->getWishlist()->getProductListing()->getTotal());
        static::assertSame($context->getContext()$page->getWishlist()->getProductListing()->getContext());
        self::assertPageEvent(WishlistPageLoadedEvent::class$event$context$request$page);
    }
$response = json_decode((string) $this->browser->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
        static::assertSame(200, $this->browser->getResponse()->getStatusCode());
        static::assertTrue($response['success']);

        $wishlistProduct = $this->wishlistProductRepository->search(new Criteria()$this->context);
        static::assertNull($wishlistProduct->getEntities()->first());
    }

    public function testMergeProductShouldReturnSuccessAlreadyWishlistExisted(): void
    {
        $productData = $this->createProduct($this->context);
        $this->createCustomerWishlist($productData);

        $this->browser
            ->request(
                'POST',
                '/store-api/customer/wishlist/merge',
                [
                    'productIds' => [
                        'id' => $productData,
                    ],
                ]
            );
        
Home | Imprint | This part of the site doesn't use cookies.