Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $customer = Mage::getModel('customer/customer');
- $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
- $customer->loadByEmail('d3fragg3d@gmail.com');
- // Check whether the customer not exists
- if(!$customer->getId())
- {
- // Create the customer
- $customer->setEmail('d3fragg3d@gmail.com');
- $customer->setFirstname('chris');
- $customer->setLastname('king');
- $customer->save();
- }
- $store = Mage::app()->getStore();
- $quote = Mage::getModel('sales/quote');
- $quote->setStore($store);
- $quote->assignCustomer($customer);
- $product1 = Mage::getModel('catalog/product')->load(5610);
- $buyInfo1 = array('qty' => 1);
- $product2 = Mage::getModel('catalog/product')->load(5609);
- $buyInfo2 = array('qty' => 3);
- $quote->addProduct($product1, new Varien_Object($buyInfo1));
- $quote->addProduct($product2, new Varien_Object($buyInfo2));
- $addressData = array(
- 'firstname' => 'Test',
- 'lastname' => 'Test',
- 'street' => 'Sample Street 10',
- 'city' => 'Somewhere',
- 'postcode' => '123456',
- 'telephone' => '123456',
- 'country_id' => 'US',
- 'region_id' => 12,
- );
- $billingAddress = $quote->getBillingAddress()->addData($addressData);
- $shippingAddress = $quote->getShippingAddress()->addData($addressData);
- $shippingAddress->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();
- $invoice = Mage::getModel('sales/service_order', $order)->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();
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement