Guest User

Untitled

a guest
Aug 1st, 2011
500
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $customer = Mage::getModel('customer/customer');
  2.  
  3. $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
  4.  
  5. $customer->loadByEmail('d3fragg3d@gmail.com');
  6.  
  7. // Check whether the customer not exists
  8. if(!$customer->getId())
  9. {
  10. // Create the customer
  11. $customer->setEmail('d3fragg3d@gmail.com');
  12. $customer->setFirstname('chris');
  13. $customer->setLastname('king');
  14. $customer->save();
  15. }
  16.  
  17. $store = Mage::app()->getStore();
  18.  
  19. $quote = Mage::getModel('sales/quote');
  20.  
  21. $quote->setStore($store);
  22. $quote->assignCustomer($customer);
  23.  
  24. $product1 = Mage::getModel('catalog/product')->load(5610);
  25. $buyInfo1 = array('qty' => 1);
  26.  
  27. $product2 = Mage::getModel('catalog/product')->load(5609);
  28. $buyInfo2 = array('qty' => 3);
  29.  
  30. $quote->addProduct($product1, new Varien_Object($buyInfo1));
  31. $quote->addProduct($product2, new Varien_Object($buyInfo2));
  32.  
  33. $addressData = array(
  34. 'firstname' => 'Test',
  35. 'lastname' => 'Test',
  36. 'street' => 'Sample Street 10',
  37. 'city' => 'Somewhere',
  38. 'postcode' => '123456',
  39. 'telephone' => '123456',
  40. 'country_id' => 'US',
  41. 'region_id' => 12,
  42. );
  43.  
  44. $billingAddress = $quote->getBillingAddress()->addData($addressData);
  45. $shippingAddress = $quote->getShippingAddress()->addData($addressData);
  46.  
  47. $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
  48. ->setShippingMethod('freeshipping_freeshipping')
  49. ->setPaymentMethod('checkmo');
  50.  
  51. $quote->getPayment()->importData(array('method' => 'checkmo'));
  52.  
  53. $quote->collectTotals()->save();
  54.  
  55. $service = Mage::getModel('sales/service_quote', $quote);
  56. $service->submitAll();
  57. $order = $service->getOrder();
  58.  
  59. $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
  60. $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::CAPTURE_ONLINE);
  61. $invoice->register();
  62.  
  63. $transaction = Mage::getModel('core/resource_transaction')
  64. ->addObject($invoice)
  65. ->addObject($invoice->getOrder());
  66.  
  67. $transaction->save();
  68.  
  69. return true;
RAW Paste Data