Hi,
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.
etc/extension_attributes.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Quote\Api\Data\CartInterface">
<attribute code="order_platform" type="string"/>
</extension_attributes>
</config>
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();
$extensions->setOrderPlatform("test");
$quote->setExtensionAttributes($extensions);
$this->quoteRepository->save($quote);
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,
Lorenzo