cancel
Showing results for 
Search instead for 
Did you mean: 

Any help on Extension Attributes and how to use it

Any help on Extension Attributes and how to use it

Hi 

 

I was trying to develop a module where I need to take some extra information about from the about reason for that item purchase. I have developed separate table and want this table to linked to order he placed. This table contains information about the itemid and which line on order it is linked to. I want this information to be exported to API. I was wondering if this information I can expose using extension attributes. if Yes, is there any document how to use this extension attributes to export this information in standard Order REST APIs? or only by developing the custom rest api only option ?

 

thanks in advance.

2 REPLIES

Re: Any help on Extension Attributes and how to use it

I have the same problem and, just to say, the documentation on Magento is all but clear on the topic.

Let's resume what I tried:

  • I created an additional table through InstallSchema.php
  • I wrote all the required classes, resource models, to handle this additional data. The classes are working: I managed to read and write data.
  • I created the extension_attributes.xml, where "\FiloBlu\OrderAdditionalData\Model\OrderData" is my custom model
<?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\Sales\Api\Data\OrderInterface">
        <attribute code="oad_additional_data" type="\FiloBlu\OrderAdditionalData\Model\OrderData">
           <join reference_table="sales_oad_order" reference_field="order_id" join_on_field="entity_id">
              <field column="additional_data">oad_additional_data</field>
           </join>            
        </attribute>
    </extension_attributes>
</config>
  • I lauched compilation and checked that the set and get methods were added to var/generation/Magento/Sales/Api/Data/OrderExtension.php and var/generation/Magento/Sales/Api/Data/OrderExtensionInterface.php 
  • I manually created a FiloBlu\OrderAdditionalData\Model\OrderData linked to an existing order. However I cannot see my extension attribute neither loading the order with repository nor accessing it calling the REST Api. 

What am I doing wrong? Srinithin did you manage to get extension attributes working in these 6 months?

Thanks in advance!

 

Re: Any help on Extension Attributes and how to use it

A small advance on the topic.
According to this answer on Magento StackExchange, it seems that set and get need to be implemented extensively for orders.