Pregunta

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'
¿Fue útil?

Solución

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();
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top