Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once 'app/Mage.php';
- Mage::app();
- $quote = Mage::getModel('sales/quote')
- ->setStoreId(Mage::app()->getStore('default')->getId());
- if ('do customer orders') {
- // for customer orders:
- $customer = Mage::getModel('customer/customer')
- ->setWebsiteId(1)
- $quote->assignCustomer($customer);
- } else {
- // for guesr orders only:
- }
- // add product(s)
- $product = Mage::getModel('catalog/product')->load(8);
- $buyInfo = array(
- 'qty' => 1,
- // custom option id => value id
- // or
- // configurable attribute id => value id
- );
- /* [adamw] Bundled product options would look like this:
- $buyInfo = array(
- "qty" => 1,
- "bundle_option" = array(
- "123" => array(456), //optionid => array( selectionid )
- "124" => array(235)
- )
- );
- */
- $quote->addProduct($product, new Varien_Object($buyInfo));
- $addressData = array(
- 'firstname' => 'Test',
- 'lastname' => 'Test',
- 'street' => 'Sample Street 10',
- 'city' => 'Somewhere',
- 'postcode' => '123456',
- 'telephone' => '123456',
- 'country_id' => 'US',
- 'region_id' => 12, // id from directory_country_region table
- );
- $billingAddress = $quote->getBillingAddress()->addData($addressData);
- $shippingAddress = $quote->getShippingAddress()->addData($addressData);
- $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
- ->setShippingMethod('flatrate_flatrate')
- ->setPaymentMethod('checkmo');
- /* [adamw] Free shipping would look like this:
- $shippingAddress->setFreeShipping( true )
- ->setCollectShippingRates(true)->collectShippingRates()
- ->setShippingMethod('freeshipping_freeshipping')
- ->setPaymentMethod('checkmo');
- */
- $quote->getPayment()->importData(array('method' => 'checkmo'));
- $quote->collectTotals()->save();
- $service = Mage::getModel('sales/service_quote', $quote);
- $service->submitAll();
- $order = $service->getOrder();
- printf("Created order %s\n", $order->getIncrementId());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement