Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to create a custom event in <code>OnePageController</code> (if you are using Onepage checkout) under <code>saveOrderAction()</code> method.</p> <p>and use the below code to remove the item from current cart and create a new order for physical product.</p> <pre><code>class CompanyName_ModuleName_Model_Order extends Mage_Core_Model_Abstract { public function createOrder() { $quoteID = Mage::getSingleton("checkout/session")-&gt;getQuote()-&gt;getId(); $quote = Mage::getModel("sales/quote")-&gt;load($quoteID); foreach($quote-&gt;getAllItems() as $item){ $itemId = $item-&gt;getId(); $productId = $item-&gt;getProductId(); if(put your condition here){ /* remove the item fro which need to split the order */ $quote-&gt;removeItem($itemId)-&gt;save(); } } $id = Mage::getSingleton('customer/session')-&gt;getCustomer()-&gt;getId(); $customer = Mage::getModel('customer/customer')-&gt;load($id); $transaction = Mage::getModel('core/resource_transaction'); $storeId = $customer-&gt;getStoreId(); $reservedOrderId = Mage::getSingleton('eav/config')-&gt;getEntityType('order')-&gt;fetchNewIncrementId($storeId); $order = Mage::getModel('sales/order') -&gt;setIncrementId($reservedOrderId) -&gt;setStoreId($storeId) -&gt;setQuoteId(0) -&gt;setGlobal_currency_code('USD') -&gt;setBase_currency_code('USD') -&gt;setStore_currency_code('USD') -&gt;setOrder_currency_code('USD'); /* set Customer data */ $order-&gt;setCustomer_email($customer-&gt;getEmail()) -&gt;setCustomerFirstname($customer-&gt;getFirstname()) -&gt;setCustomerLastname($customer-&gt;getLastname()) -&gt;setCustomerGroupId($customer-&gt;getGroupId()) -&gt;setCustomer_is_guest(0) -&gt;setCustomer($customer); /* set Billing Address */ $billing = $customer-&gt;getDefaultBillingAddress(); $billingAddress = Mage::getModel('sales/order_address') -&gt;setStoreId($storeId) -&gt;setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING) -&gt;setCustomerId($customer-&gt;getId()) -&gt;setCustomerAddressId($customer-&gt;getDefaultBilling()) -&gt;setCustomer_address_id($billing-&gt;getEntityId()) -&gt;setPrefix($billing-&gt;getPrefix()) -&gt;setFirstname($billing-&gt;getFirstname()) -&gt;setMiddlename($billing-&gt;getMiddlename()) -&gt;setLastname($billing-&gt;getLastname()) -&gt;setSuffix($billing-&gt;getSuffix()) -&gt;setCompany($billing-&gt;getCompany()) -&gt;setStreet($billing-&gt;getStreet()) -&gt;setCity($billing-&gt;getCity()) -&gt;setCountry_id($billing-&gt;getCountryId()) -&gt;setRegion($billing-&gt;getRegion()) -&gt;setRegion_id($billing-&gt;getRegionId()) -&gt;setPostcode($billing-&gt;getPostcode()) -&gt;setTelephone($billing-&gt;getTelephone()) -&gt;setFax($billing-&gt;getFax()); $order-&gt;setBillingAddress($billingAddress); $shipping = $customer-&gt;getDefaultShippingAddress(); $shippingAddress = Mage::getModel('sales/order_address') -&gt;setStoreId($storeId) -&gt;setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING) -&gt;setCustomerId($customer-&gt;getId()) -&gt;setCustomerAddressId($customer-&gt;getDefaultShipping()) -&gt;setCustomer_address_id($shipping-&gt;getEntityId()) -&gt;setPrefix($shipping-&gt;getPrefix()) -&gt;setFirstname($shipping-&gt;getFirstname()) -&gt;setMiddlename($shipping-&gt;getMiddlename()) -&gt;setLastname($shipping-&gt;getLastname()) -&gt;setSuffix($shipping-&gt;getSuffix()) -&gt;setCompany($shipping-&gt;getCompany()) -&gt;setStreet($shipping-&gt;getStreet()) -&gt;setCity($shipping-&gt;getCity()) -&gt;setCountry_id($shipping-&gt;getCountryId()) -&gt;setRegion($shipping-&gt;getRegion()) -&gt;setRegion_id($shipping-&gt;getRegionId()) -&gt;setPostcode($shipping-&gt;getPostcode()) -&gt;setTelephone($shipping-&gt;getTelephone()) -&gt;setFax($shipping-&gt;getFax()); $order-&gt;setShippingAddress($shippingAddress) -&gt;setShipping_method('freeshipping') -&gt;setShippingDescription('Free Shipping - Free'); /*set payment details here for example */ $orderPayment = Mage::getModel('sales/order_payment') -&gt;setStoreId($storeId) -&gt;setCustomerPaymentId(0) -&gt;setMethod('cybersource_soap') -&gt;setCcType('VI') -&gt;setCcNumber('4111111111111111') -&gt;setCcLast4('1111') -&gt;setCcExpMonth('2') -&gt;setCcExpYear('2013') -&gt;setCcCid('123'); $order-&gt;setPayment($orderPayment); /* let say, we have 2 products */ $subTotal = 0; /* pass the product id and quantity here e.g. */ $products = array( '2' =&gt; array( 'qty' =&gt; 1 ) ); foreach ($products as $productId =&gt; $product) { $_product = Mage::getModel('catalog/product')-&gt;load($productId); $rowTotal = $_product-&gt;getPrice() * $product['qty']; $orderItem = Mage::getModel('sales/order_item') -&gt;setStoreId($storeId) -&gt;setQuoteItemId(0) -&gt;setQuoteParentItemId(NULL) -&gt;setProductId($productId) -&gt;setProductType($_product-&gt;getTypeId()) -&gt;setQtyBackordered(NULL) -&gt;setTotalQtyOrdered($product['qty']) -&gt;setQtyOrdered($product['qty']) -&gt;setName($_product-&gt;getName()) -&gt;setSku($_product-&gt;getSku()) -&gt;setPrice($_product-&gt;getPrice()) -&gt;setBasePrice($_product-&gt;getPrice()) -&gt;setOriginalPrice($_product-&gt;getPrice()) -&gt;setRowTotal($rowTotal) -&gt;setBaseRowTotal($rowTotal); $subTotal += $rowTotal; $order-&gt;addItem($orderItem); } $order-&gt;setSubtotal($subTotal) -&gt;setBaseSubtotal($subTotal) -&gt;setGrandTotal($subTotal) -&gt;setBaseGrandTotal($subTotal); $transaction-&gt;addObject($order); $transaction-&gt;addCommitCallback(array($order, 'place')); $transaction-&gt;addCommitCallback(array($order, 'save')); $transaction-&gt;save(); } } </code></pre> <p>and don't forget to modify this code according your configuration etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COThanks man it's working fine.
      singulars
      1. This table or related slice is empty.
 

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