1

I am trying to get the cart_id in my controller but it seems to only be available on the frontend in knockoutjs.

Does anyone know how to access this value which is an alpha numeric string used to place and order when calling GuestPaymentInformationManagement it passes $cart_id as a variable to the savePaymentInformationAndPlaceOrder function but I cannot find this variable in the backend but it is available on the frontend checkout as quote.quoteId() But I need to get this item in the backend if anyone knows how I'd really appreciate it.

$cart_id = 'd8sXVE1acGcxJpNnleA3e2gkSq6Zo4ae'
2

The cart_id you are talking about corresponds to the masked quote id.

In order to get the original quote id from masked quote id you can inject the Magento\Quote\Model\QuoteIdMaskFactory in your construct method and use it like this in a controller (for example):

public function execute()
{
    $data = $this->_jsonHelper->jsonDecode($this->getRequest()->getContent());
    $maskedQuoteId = $data['quoteId'];
    $quoteIdMask = $this->quoteIdMaskFactory->create()->load($maskedQuoteId, 'masked_id');
    $quoteId = $quoteIdMask->getQuoteId();
}
1
  • I literally just found it in: \Magento\Quote\Model\QuoteIdMaskFactory $quoteIdMaskFactory, then came back to answer my own question - thanks! Jun 12 '19 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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