Whats the best way to get Cart ID from Mageno2 Checkout
-
04-03-2021 - |
Domanda
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'
Soluzione
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();
}