In the One Page Checkout the saveBilling step creates the Shipping Methods insert on the fly from the controller response (when billing[use_for_shipping] is selected), which you can retrieve from an observer like so:

/* @var $response Mage_Core_Controller_Response_Http */
$response = $observer->getControllerAction()->getResponse();
$responseArray = Mage::helper('core')->jsonDecode($response->getBody());

However, the problem I've got is that the shipping value is a table rate based on the value of the shopping cart (e.g. free shipping on orders over £25) and there's a membership pricelist. This is all fine when someone logs into an account but it causes a problem with the guest checkout.

A field was added to the Billing section for customers to enter their membership number. When the saveBilling step is called the observer verifies the membership and recalculates the quote totals ($quote->setTotalsCollectedFlag(false)->collectTotals();) ... this all works fine.

However it's possible that someone over the free shipping threshold drops below it when their pricelist is switched as some items are cheaper but the Shipping Methods insert has already been generated from the controller so the wrong shipping price is displayed.

I can work around it by removing prices from the template or manipulating the form - but those are both hacks. I'd like to be able to recreate the shipping methods response from the controller using the updated quote. Any ideas?

1 Answer 1


Short Answer

If you need to update the values in a quote before the saveBilling event is despatched, to ensure the correct shipping method calculations, you need the predespatch event (which is fairly obvious really)... I was using the postdespatch event.



Firstly I needed to move the membership validation in config.xml so that it's triggered before the controller action; that was a simple matter of changing it from the postdespatch even to predespatch and removing any code that utilised the $observer->getControllerAction() since that hasn't been despatched yet.

Now when the saveBilling controller is despatched it has the updated quote with the membership pricelist applied and the shipping prices are correctly calculated in the JSON response.

However the saveBilling controller seems to automatically set the customer_group_id to 0 when using the guest checkout so I had to add a method to the observer that's called postdespatch to check that the membership validation flag exists on the quote (part of the plugin) and, if so, set the customer group back again to members.

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.