magentofedex

Increase shipping price and/or add line item for extra cost


I'm implementing a custom FedEx integration solution for a Magento site. Part of this is to add a signature requirement checkbox in the onepage checkout, and add $3 if this is checked. Unfortunately it seems that the FedEx Rate Web Service doesn't take any parameter regarding signature requirements, so I must manually add this cost to the order.

I was thinking about taking one of these two approaches, but I'm not sure will be best nor am I sure how to actually accomplish it:

  1. Add $3 to whatever price FedEx returns

  2. Create a new line item for this

Assuming that I have a handle on the $order, which solution would be best and how would I do it?

The code should run inside an observer method which is called by the checkout_controller_onepage_save_shipping_method event, which is triggered immediately after $this->getOnepage()->saveShippingMethod($data);. This means I can't add $3 when the FedEx API returns a result, as I won't know if the checkbox is checked until afterwards.


Solution

  • I came up with a solution; it's not the best but it works perfectly fine for me:

    1. Magento fires an event when saving the shipping info. I grab the POST data and save it in the db as well as the address object.
    2. If the checkbox has changed, have it reload that same tab instead of moving onto the payment step.
    3. In the shipping quote, check the address object for the checkbox value. If set, add a certain amount to the quote result.