1

I am interested in passing additional order data from Magento to our shipping solution - ShipStation.

I need to calculate the total discount applied and store it as what I believe would be an order attribute. Once it exists, getting it into ShipStation seems relatively straight forward.

My question then would be: How would I begin to calculate and store the total discount applied to an order?

2 Answers 2

2

Could you not use the base_discount_amount or discount_amount columns that are default to Magento.

  1. base_discount_amount is the discount stored with the default currency,
  2. discount_amount is the discount stored in the currency that the order was placed in,

Note: these fields are stored as negative values against the sales_flat_order table

2
  • Yes, that is exactly the field I need. For whatever reason, my 3rd party shipping software is not seeing this field. Does it have to be "included" somehow? Is there another step necessary in order for this information to be accessible through the API?
    – sparecycle
    May 20, 2014 at 15:25
  • @deeperDATA I am not sure about the API but magento will be able to get these whenever it has the order object May 20, 2014 at 15:26
1

I guess you want to create your own input type:

In /app/code/local/Custom/CustomOrderStatus/etc/config.xml

1.1

<global> 
     <fieldsets>
        <sales_convert_quote>                           
            <my_custom_input_field><to_order>*</to_order></my_custom_input_field>
        </sales_convert_quote>

        <sales_convert_order>                                              
            <my_custom_input_field><to_quote>*</to_quote></my_custom_input_field>
        </sales_convert_order>
    </fieldsets>
    <helpers>
        <customorderstatus>
            <class>Custom_CustomOrderStatus_Helper</class>
        </customorderstatus>            
    </helpers>

    <models>
        <customorderstatus>
            <class>Custom_CustomOrderStatus_Model</class>
            <resourceModel>customorderstatus_mysql4</resourceModel>
        </customorderstatus>
    </models>
    <resources>
        <customorderstatus_setup>
            <setup>
                <module>Custom_CustomOrderStatus</module>
                <class>Mage_Sales_Model_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </customorderstatus_setup>
        <customorderstatus_write>
            <connection>
                <use>core_write</use>
            </connection>
        </customorderstatus_write>
        <customorderstatus_read>
            <connection>
                <use>core_read</use>
            </connection>
        </customorderstatus_read>
    </resources>

    <events>
        <adminhtml_sales_order_create_process_data_before>
            <observers>
                <customorderstatus>
                    <type>singleton</type>
                    <class>customorderstatus/observer</class>
                    <method>saveCustomData</method>
                </customorderstatus>
            </observers>
        </adminhtml_sales_order_create_process_data_before>
    </events>

    <blocks>
        <customorderstatus>
            <class>Custom_CustomOrderStatus_Block</class>
        </customorderstatus>
    </blocks>
</global>

/app/code/local/Custom/CustomOrderStatus/sql/customorderstatus_setup/mysql4-install-1.1.php

 <?php
    $installer = $this;
    $installer->startSetup();

    $installer->addAttribute("order", "my_custom_input_field", array("type"=>"varchar"));
    $installer->addAttribute("quote", "my_custom_input_field", array("type"=>"varchar"));
    $installer->endSetup(); 

In /app/code/local/Custom/CustomOrderStatus/Model/Observer.php

class Custom_CustomOrderStatus_Model_Observer 
{
    public function saveCustomData($event)
    {
        $quote = $event->getSession()->getQuote();
        $quote->setData('my_custom_input_field', $event->getRequestModel()->getPost('my_custom_input_field'));

        return $this;
    }
}

In /app/design/adminhtml/default/default/template/sales/order/view/info.phtml

My Custom Input Field In php tags: echo $_order->getMyCustomInputField()

In sales/order/form/account.phtml

echo Mage::getSingleton('adminhtml/session_quote')->getQuote()->getMyCustomInputField()

Use this in your field. For the area where i used core files, you should make your own files, just to make sure that core files are not modified.

1
  • I followed your way but unfortunately its not reaching to my observer ? any reason why ? Aug 24, 2015 at 6:24

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.