Magento Code order creation process

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.