deleteCart example



    public function testDeleteCartCallsDeleteRoute(): void
    {
        $context = $this->createMock(SalesChannelContext::class);

        $this->cartDeleteRoute->expects(static::once())
            ->method('delete')
            ->with($context)
        ;

        $this->cartService->deleteCart($context);
    }

    public function testRemoveItemsCallsRemoveRoute(): void
    {
        $context = $this->createMock(SalesChannelContext::class);
        $cart = new Cart(Uuid::randomHex());

        $id1 = Uuid::randomHex();
        $id2 = Uuid::randomHex();
        $ids = [$id1$id2];

        
'permissions' => [],
            ],
            $currentContext->getSalesChannel()->getId(),
            ($originalToken === null) ? $customerId : null,
        );

        return $currentContext;
    }

    private function deleteGuestContext(SalesChannelContext $guestContext, string $customerId): void
    {
        $this->cartService->deleteCart($guestContext);
        $this->contextPersister->delete($guestContext->getToken()$guestContext->getSalesChannelId()$customerId);
    }

    private function enrichCustomerContext(
        SalesChannelContext $customerContext,
        SalesChannelContext $currentContext,
        string $token,
        string $customerId
    ): SalesChannelContext {
        if (!$customerContext->getDomainId()) {
            $customerContext->setDomainId($currentContext->getDomainId());
        }
public function getDecorated(): AbstractLogoutRoute
    {
        throw new DecorationPatternException(self::class);
    }

    #[Route(path: '/store-api/account/logout', name: 'store-api.account.logout', methods: ['POST'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function logout(SalesChannelContext $context, RequestDataBag $data): ContextTokenResponse
    {
        /** @var CustomerEntity $customer */
        $customer = $context->getCustomer();
        if ($this->shouldDelete($context)) {
            $this->cartService->deleteCart($context);
            $this->contextPersister->delete($context->getToken()$context->getSalesChannelId());

            $event = new CustomerLogoutEvent($context$customer);
            $this->eventDispatcher->dispatch($event);

            return new ContextTokenResponse($context->getToken());
        }

        $newToken = Random::getAlphanumericString(32);
        if ((bool) $data->get('replace-token')) {
            $newToken = $this->contextPersister->replace($context->getToken()$context);
        }
Home | Imprint | This part of the site doesn't use cookies.