replaceContextToken example


    public function restoreByToken(string $token, string $customerId, SalesChannelContext $currentContext): SalesChannelContext
    {
        $customerPayload = $this->contextPersister->load(
            $token,
            $currentContext->getSalesChannel()->getId(),
        );

        if (empty($customerPayload) || !empty($customerPayload['permissions'])) {
            return $this->replaceContextToken($customerId$currentContext$token);
        }

        $customerContext = $this->factory->create($customerPayload['token']$currentContext->getSalesChannel()->getId()$customerPayload);
        if ($customerPayload['expired'] ?? false) {
            $customerContext = $this->replaceContextToken($customerId$customerContext$token);
        }

        return $this->enrichCustomerContext($customerContext$currentContext$token$customerId);
    }

    /** * This function restores the context by the given customer id. If a context with this customer id doesn't exist, the context will * create with the customer id in the main customerId table column. * So, the context is directly referenced to the customer. */
Home | Imprint | This part of the site doesn't use cookies.