0

I am trying to add a new extension attribute to order items to be accessible in the REST API Response in OrderRespository and OrderItemRepository. Y create the etc/extension_attribute.xml and the two plugins:

extension_attribute.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\Sales\Api\Data\OrderItemInterface">
    <attribute code="external_price" type="float" />
  </extension_attributes>
</config>

di.xml

<type name="Magento\Sales\Api\OrderRepositoryInterface">
       <plugin name="get_order_external_price_attribute" type="Morwi\MayoreoOrdenes\Plugin\OrderRepository"/>
  </type>
  <type name="Magento\Sales\Api\OrderItemRepositoryInterface">
       <plugin name="get_order_item_external_price_attribute" type="Morwi\MayoreoOrdenes\Plugin\OrderItemRepository"/>
  </type>

I validate, and my plugin's methods are running. And I print_r the Items object from the return variable of each one, and they had the attribute external_price in extension_attributes:

[extension_attributes] => Magento\Sales\Api\Data\OrderItemExtension Object
    (
        [_data:protected] => Array
            (
                [gw_id] =>
                [gw_base_price] =>
                [gw_price] =>
                [gw_base_tax_amount] =>
                [gw_tax_amount] =>
                [gw_base_price_invoiced] =>
                [gw_price_invoiced] =>
                [gw_base_tax_amount_invoiced] =>
                [gw_tax_amount_invoiced] =>
                [gw_base_price_refunded] =>
                [gw_price_refunded] =>
                [gw_base_tax_amount_refunded] =>
                [gw_tax_amount_refunded] =>
                [external_price] => 10.5
            )

    )

However, when I execute the API from my postman, the extension_attribute node is not in the response on any of the two apis:

{
    "amount_refunded": 0,
    "base_amount_refunded": 0,
    "base_cost": 59.08,
    "base_discount_amount": 0,
    "base_discount_invoiced": 0,
    "base_discount_tax_compensation_amount": 0,
    "base_original_price": 82.37,
    "base_price": 82.37,
    "base_price_incl_tax": 82.37,
    "base_row_invoiced": 0,
    "base_row_total": 82.37,
    "base_row_total_incl_tax": 82.37,
    "base_tax_amount": 0,
    "base_tax_invoiced": 0,
    "created_at": "2021-01-21 22:48:42",
    "discount_amount": 0,
    "discount_invoiced": 0,
    "discount_percent": 0,
    "free_shipping": 0,
    "discount_tax_compensation_amount": 0,
    "is_qty_decimal": 0,
    "is_virtual": 0,
    "item_id": 38,
    "name": "CEPILLO HI-LO",
    "no_discount": 0,
    "order_id": 18,
    "original_price": 82.37,
    "price": 82.37,
    "price_incl_tax": 82.37,
    "product_id": 162302,
    "product_type": "simple",
    "qty_canceled": 0,
    "qty_invoiced": 0,
    "qty_ordered": 1,
    "qty_refunded": 0,
    "qty_returned": 0,
    "qty_shipped": 0,
    "quote_item_id": 134,
    "row_invoiced": 0,
    "row_total": 82.37,
    "row_total_incl_tax": 82.37,
    "row_weight": 0,
    "sku": "5952",
    "store_id": 1,
    "tax_amount": 0,
    "tax_invoiced": 0,
    "tax_percent": 0,
    "updated_at": "2021-01-21 22:48:42",
    "weight": 0
}

How can I resolve this?

1
  • what is the endpoint you are calling? – Diana Botean Mar 23 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.