Magento Code order creation process
look directly at the code. The following code is how to create a perfect order from a program.
<?php
Require_once ' app/mage.php ';
Mage::app (' default ');//Initialize the program, set the current store
$store = Mage::app ()->getstore (' Default ');
Get users by e-mail, and of course not get, create guest orders
$customer = Mage::getmodel (' Customer/customer ');
$customer->setstore ($store);
$customer->loadbyemail (' [email protected] ');
The Quote,magento order is initialized by quote to transform the past
$quote = Mage::getmodel (' sales/quote ');
$quote->setstore ($store);
$quote->assigncustomer ($customer);//If a user performs this
$product 1 = Mage::getmodel (' catalog/product ')->load (166); /* HTC Touch Diamond */
$buyInfo 1 = Array (' qty ' = + 1);
$product 2 = Mage::getmodel (' catalog/product ')->load (18); /* Sony Ericsson w810i */
$buyInfo 2 = Array (' qty ' = + 3);
//Add items to quote
$quote->addproduct ($product 1, New Varien_object ($buyInfo 1));
$quote->addproduct ($product 2, New Varien_object ($buyInfo 2));
Set up billing and delivery addresses
$billingAddress = $quote->getbillingaddress ()->adddata ($customer->getprimarybillingaddress ());
$shippingAddress = $quote->getshippingaddress ()->adddata ($customer->getprimaryshippingaddress ());
//Set up shipping and payment methods
$shippingAddress->setcollectshippingrates (True)->collectshippingrates ()
->setshippingmethod (' flatrate_flatrate ')
->setpaymentmethod (' Checkmo ');
$quote->getpayment ()->importdata (Array (' method ' = ' checkmo '));
//quote Calculate freight
$quote->collecttotals ()->save ();
//Convert Quote to Orders
$service = Mage::getmodel (' sales/service_quote ', $quote);
$service->submitall ();
er = $service->getorder ();
/*** This order has been successfully generated, here is the registration payment information ***/
$invoice = Mage::getmodel (' Sales/service_order ', er)->prepareinvoice ();
$invoice->setrequestedcapturecase (Mage_sales_model_order_invoice::capture_online);
$invoice->register ();
$transaction = Mage::getmodel (' core/resource_transaction ')
->addobject ($invoice)
->addobject ($invoice->getorder ());
$transaction->save ();
?>
Magento Code order creation process