Split Order into Separate Orders and Calculate Shipping Separately with UPS and FedEx

checkoutshipping

When a customer comes to our store and goes to check out on multiple items, I need to write a module to calculate shipping based on several factors. I have determined from my research that the following should happen:

First, I need to separate the cart items into different orders for shipping calculation. I want the orders to be sorted by "vendor" attribute value. "Vendor" is an attribute that we added to the system that is applicable for all simple products. So say in the cart there is a pink shirt with "vendor" value "1", a pencil with "vendor" value "1", and a blue shirt with "vendor" value "2". All items with "vendor" value "1" need to be one order, while the item with "vendor" value "2" need to be a different order. I see this other question answers this dilemma, but then raises another. How do I do this but display the seperate orders as one order during checkout to customers and only collect payment once?

Second, I need to calculate shipping with Magento's default UPS and Fedex shipping functionalities but with an origin address that is determined by the "vendor" value number (stored in a separate database table). Any suggestions welcome!

I am using code snippets to get me started from here and here.

I will probably have several questions, but the first ones are those in bold above.

UPDATE
I decided it would be best to override the multiple shipments magento core module to do what I'm trying to do. Please help me find where and what to put to manipulate the multishipping Magento functionality to break up an order's items into shipments based on the "vendor" attribute! I'm struggling with this.

Best Answer

Something to consider here is that you may only need to apply some cosmetic front-end changes to the multishipping templates (template/checkout/multishipping/) so that the two orders simply appear as one order to the customer. The shipping.phtml and overview.phtml templates split the two orders, each with a header (Address 1 of 2, etc) and other copy to show it is two orders.

Instead of the default, I might suggest being a little creative on these templates so that the two orders are simply split so they simply appear as two separate line items.

The next bit would be to handle different shipping origins based on the vendor attribute. This could maybe be done in Mage_Shipping_Model_Shipping. You can see right at the top is where Magento is grabbing the shipping origin address from the config and then further down in the requestToShipment() method, the origin address elements are assigned to the shipping request (which I assume would be used later depending on the shipping method called).

That might at least be a direction to head in. Reading over your question and your update I get the impression that you are making this more difficult than is necessary. Always remember that it is generally best to let Magento do what it wants to do, and only modify small bits to handle your specific cases. A majority of what you require is already done in core, so it seems a bit silly to rewrite the multi-shipping components when there may be simpler options.

Related Topic