Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _order_create($data){
- if(is_array($data) and !empty($data['product'])){
- $quote = Mage::getModel('sales/quote')
- ->setStoreId(Mage::app()->getStore('default')->getId());
- $customer = Mage::getModel('customer/customer')
- ->setWebsiteId(1)
- ->loadByEmail($data['customer_email']);
- $quote->assignCustomer($customer);
- // add product(s)
- foreach ($data['product'] as $id => $pdata) {
- $product = Mage::getModel('catalog/product')->load($pdata['id']);
- $buyInfo = array('qty' =>$pdata['qty']);
- //****************** here set is_in_stock to 1
- $quote->addProduct($product, new Varien_Object($buyInfo));
- $quote->save(); // without saving the quote here I get error
- $quoteItem = $quote->getItemByProduct($product);
- $quoteItem->setOriginalCustomPrice($pdata['price']);
- $quoteItem->setCustomPrice($pdata['price']);
- $quoteItem->setIsSuperMode(true);
- $quoteItem->save();
- // ****************** here set is_in_stock to 0
- }
- foreach ($data['address']['shipping'] as $key => $value) {
- $addressDataShipping[$key] = $value;
- }
- foreach ($data['address']['billing'] as $key => $value) {
- $addressDataBilling[$key] = $value;
- }
- $billingAddress = $quote->getBillingAddress()->addData($addressDataBilling);
- $shippingAddress = $quote->getShippingAddress()->addData($addressDataShipping);
- $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
- ->setShippingMethod($data['methods']['shipping'])
- ->setPaymentMethod($data['methods']['payment']);
- $quote->getPayment()->importData(array('method' => $data['methods']['payment']));
- $quote->setTotalsCollectedFlag(false)->collectTotals()->save();
- $service = Mage::getModel('sales/service_quote', $quote);
- $service->submitAll();
- $order = $service->getOrder();
- $order->setCreatedAt($data['order']['createdat']);
- $order->setData('state', $data['order']['status']);
- $order->setStatus($data['order']['status']);
- $order->save();
- //printf("Created order %sn", $order->getIncrementId());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement