2

I tried to get full list of order item attributes by this url: api/rest/orders/25/items . There are:

    "item_id": "62",
    "parent_item_id": null,
    "product_type": "simple",
    "sku": "89110065",
    "name": "Diamond Glow Nourishing Mud Mask",
    "qty_canceled": "0.0000",
    "qty_invoiced": "0.0000",
    "qty_ordered": "1.0000",
    "qty_refunded": "0.0000",
    "qty_shipped": "0.0000",
    "price": "277.3100",
    "base_price": "277.3100",
    "original_price": "330.0000",
    "base_original_price": "330.0000",
    "tax_percent": "19.0000",
    "tax_amount": "52.6900",
    "base_tax_amount": "52.6900",
    "discount_amount": "0.0000",
    "base_discount_amount": "0.0000",
    "row_total": "277.3100",
    "base_row_total": "277.3100",
    "price_incl_tax": "330.0000",
    "base_price_incl_tax": "330.0000",
    "row_total_incl_tax": "330.0000",
    "base_row_total_incl_tax": "330.0000"

If you look at the order item object, you will see that it has more attributes. Is it possible to add a custom attribute to this list? Or I have to overwrite the existing API to add a custom attribute?

3

The attributes you see there are defined in api2.xml file of the sales module.
Here they are
This api2.xml works like any other XML in magento. It is merged with all the other api2.xml files in all the modules.
So In order to add your own attributes you can create your own module that contains the file etc/api2.xml where you can add your attributes, but keep the tag structure.

Your etc/api2.xml could look like this.

<?xml version="1.0"?>
<config>
    <api2>
        <resources>
            <order_item>
                <attributes>
                    <attr_one_code_here>Attr One Label</attr_one_code_here>
                    <attr_two_code_here>Attr Two Label</attr_two_code_here>
                </attributes>
            </order_item>
        </resources>    
    </api2>
</config>

Clear the cache when you are done.
You may need to give access to the new attributes in the api user roles section, but not sure.

  • I tried it. It started to work only when I set attribute rules for Admin Role to "All". When I had checked manually all options, custom attributes didn't work. – Oboroten Jun 22 '17 at 10:19

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.