0

As you know you can add products to the cart even if you're not logged in.

I need to retrieve what a user has added to the cart in a given browsing session. Then i need to edit it (add/remove to/from cart).

Are there APIs to do this, maybe by utilizing the session id stored in cookies?

Thanks

1 Answer 1

0

Magento doesn't store Quote Id in session or in Local Storage. During checkout the quote id available with window.checkoutConfig.quoteId.

The data is coming from \Magento\Checkout\Model\DefaultConfigProvider

If you want to pass quest cart from front to cookie or something else you can use following logic

// instances
$quoteIdMaskFactory = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Quote\Model\QuoteIdMaskFactory');
$checkoutSession = \Magento\Framework\App\ObjectManager::getInstance()->get('Magento\Checkout\Model\Session');

$quote = $checkoutSession->getQuote();

if (!$quote->getCustomer()->getId()) {
    $quoteIdMask = $quoteIdMaskFactory->create()
        ->load($quote->getId(), 'quote_id')
        ->getMaskedId();
}

If you want to create guest quote with API you can call

POST <host>/rest/<store_core_or_all>/V1/guest-carts

Manage Cart Items

-- List items that are assigned to a specified cart.
GET ​<host>/rest/<store_core_or_all>/V1​/guest-carts​/{cartId}​/items

--- Add/update the specified cart item.
POST <host>/rest/<store_core_or_all>​/V1​/guest-carts​/{cartId}​/items

--- Add/update the specified cart item.
PUT <host>/rest/<store_core_or_all>​/V1​/guest-carts​/{cartId}​/items​/{itemId}

-- Remove the specified item from the specified cart.
DELETE <host>/rest/<store_core_or_all>​/V1​/guest-carts​/{cartId}​/items​/{itemId}

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.