cancel
Showing results for 
Search instead for 
Did you mean: 

Auto split order into multiple orders with 1 item per order

Auto split order into multiple orders with 1 item per order

My shipping carrier uses an extension which creates 1 shipping label per order.

This is not ideal because I ship per item, and I need  a shipping label for each item.

 

Because I need a shipping label per item instead of per order, I want to try to auto-split each order into multiple orders of 1 item.

But.. how do I do this?

I've already found out how to split an order into multiple shipments
http://magento.stackexchange.com/questions/12741/auto-split-magento-shipments-based-on-maximum-weigh...

But how do I auto split an order into multiple orders?

7 REPLIES

Re: Auto split order into multiple orders with 1 item per order

you should be able to print shipping labels per shipment, why have to split order?

Re: Auto split order into multiple orders with 1 item per order

Because the extension I got from my shipping carrier (with an API connection) only allows to print shipping labels from the order view, and only creates one shipping label per order. I already asked the developers if they could change that because it's not logical, but they won't / can't .

 

Re: Auto split order into multiple orders with 1 item per order

It should be possible to generate label for each shipment with API. Anyway, you can split orders automatically, but it will be kinda messy, like this one http://magento.stackexchange.com/questions/4682/magento-multiple-order-on-one-checkout-or-order-spli...

Re: Auto split order into multiple orders with 1 item per order

Yes I know that piece of code, just look at my own link in my first post  Smiley Wink

But can that be changed into splitting an order into multiple orders, instead of shipments?

 

The extension uses orders to create the label, and this piece creates shipments, instead of orders (it's a really handy piece of code by the way).

 

 

Re: Auto split order into multiple orders with 1 item per order

???

It is about splitting order into multiple orders, its totally a different link than in your first post

Re: Auto split order into multiple orders with 1 item per order

I'm sorry, I was wrong, must be confused by the many tabs I had opened.


I've combined to pieces of code (from your link and my link) and made this

public function saveOrder()
{
    $quote = $this->getQuote();

    $sortedItems = array();
   $itemqty = Mage::getSingleton('checkout/cart')->getQuote()->getItemsQty(); // <- whatever you need
    if ( $itemqty > 1 )
    foreach ($quote->getAllItems() as $item) {
       for ( $i=0; $i < $itemqty; $i++ )
        $qty = Mage::getSingleton('checkout/cart')->getQuote()->getItemsQty(); // <- whatever you need
        if (! isset($sortedItems[$qty])) {
            $sortedItems[$qty] = $item;
            $sortedItems[$i]['qty'] = 1;
        }
    }
    foreach ($sortedItems as $quantity => $items) {
   
        foreach ($items as $item) {
            $quote->addItem($item);
        }

        $quote->setTotalsCollectedFlag(false)->collectTotals();


        parent::saveOrder();
    }
    return $this;
}

It creates an order, but only with 1 item. Even if I have 3 items in my cart (not 3 orders for 3 items).
What am I doing wrong?

Re: Auto split order into multiple orders with 1 item per order

Your sorting is wrong, actually you don't need to sort items like the SO post, as they need to split orders by vendors while you simply want to split by each item. so just remove the first foreach for sorting and keep the 2nd foreach for splitting