Я пытаюсь добавить атрибут расширения к цитате через настраиваемый REST API, и я хотел бы получить эту информацию позже.
Но когда я пытаюсь получить значение, оно всегда равно нулю.
Код объяснит лучше меня.
и т.д. / di.xml
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
[...]
<preference for="Wow\Orderplatform\Api\Data\CartInterface"
type="Wow\Orderplatform\Model\Cart" />
</config>
и т.д. / 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="Wow\Orderplatform\Api\Data\CartInterface"/>
</extension_attributes>
</config>
Корзина
interface CartInterface extends ExtensibleDataInterface
{
const ORDER_PLATFORM = 'order_platform';
/**
* Retrieve order platform
*
* @return string
*/
public function getOrderPlatform();
/**
* Set order platform
*
* @param string $orderPlatform
* @return $this
*/
public function setOrderPlatform($orderPlatform);
}
Реализация:
class Cart extends AbstractExtensibleModel implements CartInterface
{
/**
* {inheritdoc}
*/
public function getOrderPlatform()
{
return $this->getData(self::ORDER_PLATFORM);
}
/**
* {inheritdoc}
*/
public function setOrderPlatform($orderPlatform)
{
return $this->setData(self::ORDER_PLATFORM, $orderPlatform);
}
}
Я пытаюсь сохранить атрибут расширения в REST API:
$quote = $this->quoteRepository->getActive($cartId);
$extensions = $quote->getExtensionAttributes();
$platformExt = $this->wowCartExtInterfaceFactory->create();
$platformExt->setOrderPlatform($platform);
$extensions->setOrderPlatform($platformExt);
$quote->setExtensionAttributes($extensions);
$this->quoteRepository->save($quote);
Никаких ошибок в этой процедуре.
Проблема в том, что я не могу вернуть значение из цитаты:
$quote = $this->quoteRepository->getActive($cartId);
$extensions = $quote->getExtensionAttributes();
$extensions->getOrderPlatform(); // Always null
Есть подсказки?
Спасибо