Showing results for 
Search instead for 
Did you mean: 

Magento2: add custom quote extension attribute

Magento2: add custom quote extension attribute



I am trying to add an extension attribute to a quote through a custom REST API, and I would like to retrieve this info later.

But when I try to get the value, is always null.

The code will explain better than me.



<?xml version="1.0"?>
<config xmlns:xsi=""
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
    <attribute code="order_platform" type="string"/>


I have checked in /var/generation that CartExtensionInterface exists and has the getOrderPlatform() and setOrderPlatform() methods.


Now, in a custom REST API I am trying to set this value:

      $quote = $this->quoteRepository->getActive($cartId);
      // [..] Quote validation tests here, it' fine
      $extensions = $quote->getExtensionAttributes();

No errors given.

After this, I try to get back this value in another REST API call (but I will need to take the value even later in a plugin): 

      $quote = $this->quoteRepository->getActive($cartId);
      $extensions = $quote->getExtensionAttributes();
      if ($extensions->getOrderPlatform() != null) {
               // Sadly I never enter here!

 No errors here, but the value I am looking for is always NULL.


Any help please?


Thanks a lot,



Re: Magento2: add custom quote extension attribute

Hi, I think that in order to achieve that you need to place a plugin where you would pick up the data and save it somewhere (if it's another call since REST is supposed to be stateless) and another one for retrieving it on load.


If you want an example in the core you can check how stock_item is saved on product.