Advertisement
Guest User

Untitled

a guest
Oct 16th, 2012
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. require_once 'app/Mage.php';
  4.  
  5. Mage::app();
  6.  
  7. $quote = Mage::getModel('sales/quote')
  8.     ->setStoreId(Mage::app()->getStore('default')->getId());
  9.  
  10. if ('do customer orders') {
  11.     // for customer orders:
  12.     $customer = Mage::getModel('customer/customer')
  13.         ->setWebsiteId(1)
  14.         ->loadByEmail('customer@example.com');
  15.     $quote->assignCustomer($customer);
  16. } else {
  17.     // for guesr orders only:
  18.     $quote->setCustomerEmail('customer@example.com');
  19. }
  20.  
  21. // add product(s)
  22. $product = Mage::getModel('catalog/product')->load(8);
  23. $buyInfo = array(
  24.     'qty' => 1,
  25.     // custom option id => value id
  26.     // or
  27.     // configurable attribute id => value id
  28. );
  29.  
  30. /* [adamw] Bundled product options would look like this:
  31.  
  32. $buyInfo = array(
  33.     "qty" => 1,
  34.     "bundle_option" = array(
  35.         "123" => array(456), //optionid => array( selectionid )
  36.         "124" => array(235)
  37.     )
  38. );
  39.  
  40. */
  41. $quote->addProduct($product, new Varien_Object($buyInfo));
  42.  
  43. $addressData = array(
  44.     'firstname' => 'Test',
  45.     'lastname' => 'Test',
  46.     'street' => 'Sample Street 10',
  47.     'city' => 'Somewhere',
  48.     'postcode' => '123456',
  49.     'telephone' => '123456',
  50.     'country_id' => 'US',
  51.     'region_id' => 12, // id from directory_country_region table
  52. );
  53.  
  54. $billingAddress = $quote->getBillingAddress()->addData($addressData);
  55. $shippingAddress = $quote->getShippingAddress()->addData($addressData);
  56.  
  57. $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
  58.         ->setShippingMethod('flatrate_flatrate')
  59.         ->setPaymentMethod('checkmo');
  60.  
  61.  
  62. /* [adamw] Free shipping would look like this:
  63.  
  64. $shippingAddress->setFreeShipping( true )
  65.     ->setCollectShippingRates(true)->collectShippingRates()
  66.     ->setShippingMethod('freeshipping_freeshipping')
  67.     ->setPaymentMethod('checkmo');
  68.  
  69. */
  70. $quote->getPayment()->importData(array('method' => 'checkmo'));
  71.  
  72. $quote->collectTotals()->save();
  73.  
  74. $service = Mage::getModel('sales/service_quote', $quote);
  75. $service->submitAll();
  76. $order = $service->getOrder();
  77.  
  78. printf("Created order %s\n", $order->getIncrementId());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement