1

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.

  • 1
    This is not a duplicate. Read the question and compare to that one. – Joe78 Aug 6 '14 at 18:39
  • Yeah, definitely duplicated. – mbalparda Aug 6 '14 at 18:39
  • 1
    Read the question @mbalparda. How is it duplicated? The other post only suggested that he placed the event in the wrong place. I have it in the right place. I am trying to return the correct data. – Joe78 Aug 6 '14 at 18:40
  • Could you describe what you're trying to accomplish? There might be a better approach that we could recommend. – Colin O'Dell Aug 6 '14 at 18:47
  • 1
    @mbalparda, this is not a duplicate. Joe78 wants to modify the shipping method data the admin chooses from (not catching submitted order data). – Colin O'Dell Aug 6 '14 at 22:17
3

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!

  • Thanks! Very helpful! Can you provide an example such as grabbing the product ID or customer address? – Joe78 Aug 6 '14 at 21:49
  • Got it! Use sales_quote_load_after for the event instead. Then you can grab the quote like this $observer->getEvent()->getQuote() and the billing address for example like this $observer->getEvent()->getQuote()->getBillingAddress() – Joe78 Aug 6 '14 at 22:16
  • Going off my first example, you can obtain the quote by using $quote = $model->getQuote(). From there you can do $quote->getAllItems() or $quote->getBillingAddress() - whatever you need. – Colin O'Dell Aug 6 '14 at 22: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.