Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is a workaround to do this. It's limited and it should be corrected because I don't know if it takes into account promotions and other special rules. It explodes order items with qty > 1 and create new lines with qty = 1;</p> <ol> <li><p>Create a module with an observer that checks the sales_order_place_after:</p> <pre><code> &lt;events&gt; &lt;sales_order_place_after&gt; &lt;observers&gt; &lt;explodeitems&gt; &lt;type&gt;singleton&lt;/type&gt; &lt;class&gt;Company_OrderObservers_Model_ExplodeOrderItem&lt;/class&gt; &lt;method&gt;explodeOrderItems&lt;/method&gt; &lt;/explodeitems&gt; &lt;/observers&gt; &lt;/sales_order_place_after&gt; &lt;events&gt; </code></pre></li> <li><p>The observer gets the ids/qty and deletes the current order items. Then it creates new ones with the parameters we got:</p> <pre><code>function explodeOrderItems($observer) { $order= $observer-&gt;getEvent()-&gt;getOrder(); $items = $order-&gt;getAllVisibleItems(); $products = array(); foreach ( $items as $k =&gt; $item ) { if ( $item-&gt;getProductType() == Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) { $itemqty = $item-&gt;getQtyOrdered(); if ( $itemqty &gt; 1 ) { for ( $i=0; $i &lt; $itemqty; $i++ ) { $products[$i]['id'] = $item-&gt;getProductId(); $products[$i]['qty'] = 1; } $item-&gt;delete(); } } else $item-&gt;delete(); } $customer = Mage::getSingleton('customer/session')-&gt;getCustomer(); $storeId = $customer-&gt;getStoreId(); if ( $products ) { foreach ( $products as $product ) { $_product = Mage::getModel('catalog/product')-&gt;load($product['id']); $price = $_product-&gt;getPrice(); $orderItem = Mage::getModel('sales/order_item') -&gt;setStoreId($storeId) -&gt;setQuoteItemId(0) -&gt;setQuoteParentItemId(NULL) -&gt;setProductId($product['id']) -&gt;setProductType($_product-&gt;getTypeId()) -&gt;setQtyBackordered(NULL) -&gt;setTotalQtyOrdered(1) -&gt;setQtyOrdered(1) -&gt;setName($_product-&gt;getName()) -&gt;setSku($_product-&gt;getSku()) -&gt;setPrice($price) -&gt;setBasePrice($price) -&gt;setOriginalPrice($price) -&gt;setRowTotal($price) -&gt;setBaseRowTotal($price); $order-&gt;addItem($orderItem); } $order-&gt;save(); } </code></pre></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload