Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. function _order_create($data){
  2. if(is_array($data) and !empty($data['product'])){
  3. $quote = Mage::getModel('sales/quote')
  4. ->setStoreId(Mage::app()->getStore('default')->getId());
  5.  
  6. $customer = Mage::getModel('customer/customer')
  7. ->setWebsiteId(1)
  8. ->loadByEmail($data['customer_email']);
  9. $quote->assignCustomer($customer);
  10.  
  11. // add product(s)
  12. foreach ($data['product'] as $id => $pdata) {
  13.  
  14. $product = Mage::getModel('catalog/product')->load($pdata['id']);
  15. $buyInfo = array('qty' =>$pdata['qty']);
  16. //****************** here set is_in_stock to 1
  17. $quote->addProduct($product, new Varien_Object($buyInfo));
  18. $quote->save(); // without saving the quote here I get error
  19.  
  20. $quoteItem = $quote->getItemByProduct($product);
  21. $quoteItem->setOriginalCustomPrice($pdata['price']);
  22. $quoteItem->setCustomPrice($pdata['price']);
  23. $quoteItem->setIsSuperMode(true);
  24. $quoteItem->save();
  25. // ****************** here set is_in_stock to 0
  26. }
  27.  
  28. foreach ($data['address']['shipping'] as $key => $value) {
  29. $addressDataShipping[$key] = $value;
  30. }
  31.  
  32. foreach ($data['address']['billing'] as $key => $value) {
  33. $addressDataBilling[$key] = $value;
  34. }
  35.  
  36.  
  37. $billingAddress = $quote->getBillingAddress()->addData($addressDataBilling);
  38. $shippingAddress = $quote->getShippingAddress()->addData($addressDataShipping);
  39. $shippingAddress->setCollectShippingRates(true)->collectShippingRates()
  40. ->setShippingMethod($data['methods']['shipping'])
  41. ->setPaymentMethod($data['methods']['payment']);
  42.  
  43. $quote->getPayment()->importData(array('method' => $data['methods']['payment']));
  44. $quote->setTotalsCollectedFlag(false)->collectTotals()->save();
  45.  
  46. $service = Mage::getModel('sales/service_quote', $quote);
  47. $service->submitAll();
  48.  
  49. $order = $service->getOrder();
  50. $order->setCreatedAt($data['order']['createdat']);
  51. $order->setData('state', $data['order']['status']);
  52. $order->setStatus($data['order']['status']);
  53.  
  54. $order->save();
  55. //printf("Created order %sn", $order->getIncrementId());
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement