Modifying Shipping Methods for Admins Creating Orders in Magento

adminhtmlevent-observersales-order

I am trying to apply changes to the shipping information that gets displayed once the admin clicks on the link to "Get Shipping Methods & Rates".

Obviously I need to grab the product and address info before the order is ever saved. I need to trigger this data when the shipping link is clicked. Grabbing the data after the order is saved will not work for me.

I have tried adminhtml_sales_order_create_process_data However, this doesn't seem to be returning anything relevant. The only thing I can seem to return with this event is the following:

$observer->getEvent()->getRequest()

Which returns:

Array
(
    [collect_shipping_rates] => 1
    [customer_id] => 2
    [store_id] => 1
    [currency_id] => false
    [form_key] => 0Is4G9KJ2XYer2c7
    [json] => true
)

Am I grabbing the data wrong or is there a better observer?

I also tried $observer->getEvent()->getOrder(); but that does not return anything.

Update: Not sure why people mark a question as a possible duplicate when in fact the two questions are completely different. This question has to do with properly grabbing the correct data, not observer placement like the other question asked and before the order is submitted.

Best Answer

The adminhtml_sales_order_create_process_data event also contains the order creation model, which you can access like this:

/** @var Mage_Adminhtml_Model_Sales_Order_Create $model */
$model = $observer->getEvent()->getOrderCreateModel();

From there you should be able to modify the quote to suit your needs.


If you're looking to modify the shipping form template (or it's data), then you'll need to add/modify blocks and/or templates instead of using an event observer.

The adminhtml_sales_order_create_load_block_shipping_method layout handle is added whenever Magento needs to display the shipping method form. This handle is used to load two blocks:

<adminhtml_sales_order_create_load_block_shipping_method>
    <reference name="content">
        <block type="adminhtml/sales_order_create_shipping_method" template="sales/order/create/abstract.phtml" name="shipping_method">
            <block type="adminhtml/sales_order_create_shipping_method_form" template="sales/order/create/shipping/method/form.phtml" name="form" />
        </block>
    </reference>
</adminhtml_sales_order_create_load_block_shipping_method>

If you're familiar with layouts, you should have no problem making whatever changes you need to. For example, if you wanted to override the form block, you could create your own adminhtml layout file with the following contents:

<?xml version="1.0"?>
<layout>
    <adminhtml_sales_order_create_load_block_shipping_method>
        <reference name="shipping_method">
            <remove name="form" />
            <block type="yourmodule/overrides_sales_order_create_shipping_method_form" template="yourmodule/sales/order/create/shipping/method/form.phtml" name="form" />
        </reference>
    </adminhtml_sales_order_create_load_block_shipping_method>
</layout>

Hope that helps!

Related Topic