How to retrieve Masked id from the cart id Magento 2?

Retrieve Masked id (guest cart hash) from the cart id in Magento 2, You required the cart quote id.

masked_id is stored in the quote_id_mask table, it’s the randomly generated string for the guest customer quote in Magento 2.

You can retrieve masked id string by using an interface,
Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface

Call method,

If cart id has available masked id it will return the masked hash string as a result.

On Error,

The cart has no masked hash, It will throw an error, the current user does not have an active cart.

Output
String

Leave a Reply