Magento2: добавить собственный атрибут расширения цитаты

Я пытаюсь добавить атрибут расширения к цитате через настраиваемый 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

Есть подсказки?

Спасибо


person Lorenzo S    schedule 18.03.2017    source источник


Ответы (1)


Это основная ошибка в magento2, попытался сделать то же самое для некоторых требований и обнаружил

Атрибуты расширения присоединения не добавляются к результатам цитаты Кажется, что есть проблема с атрибутами расширения присоединения согласно моей отладке

ex.

<extension_attributes for="Magento\Quote\Api\Data\CartItemInterface">
    <attribute code="original_catalog_price" type="Magento\NegotiableQuote\Api\Data\NegotiableQuoteItemInterface" >
        <join reference_table="negotiable_quote_item" reference_field="quote_item_id" join_on_field="item_id">
            <field>original_catalog_price</field>
        </join>
    </attribute>
</extension_attributes>

Надеюсь, патч скоро выйдет.

person sandeep mukherjee    schedule 19.04.2018