I am programatically creating order for regsitered user but I keep on getting error. How can I fix it? Below is my code:
Error:
Fatal error: Call to a member function getTypeInstance() on a
non-object in
D:\wamp\www\mournewcs3\app\code\core\Mage\Sales\Model\Quote.php on
line 968
$quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore('default')->getId());
if (1) {
// for customer orders:
$customer = Mage::getModel('customer/customer')
->setWebsiteId(1)
->loadByEmail('gaurav.mishra@abc.com');
$quote->assignCustomer($customer);
}
$product = Mage::getModel('catalog/product')->load(363);
$buyInfo = array(
'qty' => 2,
);
$quote->addProduct($product, new Varien_Object($buyInfo));
$quote->addProduct($product2, new Varien_Object($buyInfo));
$addressData = array(
'firstname' => 'Test',
'lastname' => 'Test',
'street' => 'Sampl',
'city' => 'fff',
'postcode' => '123456',
'telephone' => '123456',
'country_id' => 'IN',
);
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->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());
Best Answer