1

I have created custom attribute Barcode. Each simple product has filled unique barcode value.

Where and what should I change to display it for each order items in output of method salesOrderInfo?

I have Magento ver. 1.9.0.1

1 Answer 1

3

This problem can be solved by creating module.

Module files:

app/code/local/YourCompany/Sales/etc/config.xml - module config file

copy app/code/core/Mage/Sales/etc/wsi.xml to app/code/local/YourCompany/Sales/etc/wsi.xml and add your new fields

copy app/code/core/Mage/Sales/etc/wsdl.xml to app/code/local/YourCompany/Sales/etc/wsdl.xml and add your new fields

app/code/local/YourCompany/Sales/Model/Order/Api.php - in my example

I'm adding custom fields: upc, style, color and size

<?php
class YourCompany_Sales_Model_Order_Api extends Mage_Sales_Model_Order_Api{

    protected function _getAttributes($object, $type, array $attributes = null){

        $result = parent::_getAttributes($object, $type, $attributes);

        if( $type === 'order_item' ){
            $result['upc'] = $object->getProduct()->getData('barcode');

            $parent = Mage::getResourceSingleton('catalog/product_type_configurable')
                ->getParentIdsByChild($object->getProduct()->getData('entity_id'));
            if( $parent ) $parent = Mage::getModel('catalog/product')->load($parent[0]);

            $result['style'] = $parent ? $parent->getData('name') : '';

            $result['color'] = $object->getProduct()->getAttributeText('color');

            $result['size'] = $object->getProduct()->getAttributeText('size');

        }elseif( $type === 'order_address' ){
            if( $object->getData('country_id') !== 'US' ){

                $region = Mage::getModel('directory/region')->load($object->getData('region_id'));
                if( $region ) $result['region'] = $region->getCode();

                $country = Mage::getModel('directory/country')->loadByCode($object->getData('country_id'));
                if( $country ) $result['country_id'] = $country->getName();

            }
        }

        return $result;

    }

}
4
  • It's not very good at all. You don't need to copypaste full wsdl/wsi config (because configs are merged). You just need to add your new fields with necessary references.
    – zhartaunik
    Commented Apr 28, 2015 at 14:36
  • Don't modify core files, beside this it looks like a proper solution Commented Jul 18, 2015 at 8:55
  • Why it needs to copy the whole wsdl/wsi configs? Isn't there a way to add only those new fields in our new configs? What will happen if another module do the same thing? Commented Feb 14, 2018 at 11:20
  • Alexandros, thank you fro your answer, but unfortunately I can't test your advice: no backups of that project. It was so long time ago...
    – Taras
    Commented Feb 15, 2018 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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