0

I Find this script to create order in Magento programmatically, it works for a sample product and not for a bundle product .

when i launch this script the order has created, but with out price product and total price order ! Here is the script:

 $productids=array(2732);
 $email="mustaphanak@gmailcom";
 $websiteId = Mage::app()->getWebsite()->getId();
 $store = Mage::app()->getStore();
 // Start New Sales Order Quote
 $quote = Mage::getModel('sales/quote')->setStoreId($store->getId());

 // Set Sales Order Quote Currency
 $quote->setCurrency($order->AdjustmentAmount->currencyID);
 $customer = Mage::getModel('customer/customer')
             ->setWebsiteId($websiteId)
             ->loadByEmail($email);
 if($customer->getId()==""){
     $customer = Mage::getModel('customer/customer');
     $customer->setWebsiteId($websiteId)
             ->setStore($store)
             ->setFirstname('Jhon')
             ->setLastname('Deo')
             ->setEmail($email)
             ->setPassword("password");
     $customer->save();
 }

 // Assign Customer To Sales Order Quote
 $quote->assignCustomer($customer);

     // Configure Notification
 $quote->setSendCconfirmation(1);
 foreach($productids as $id){
     $product=Mage::getModel('catalog/product')->load($id);
     $quote->addProduct($product,new Varien_Object(array('qty'   => 1)));
 }

 // Set Sales Order Billing Address
 $billingAddress = $quote->getBillingAddress()->addData(array(
     'customer_address_id' => '',
     'prefix' => '',
     'firstname' => 'john',
     'middlename' => '',
     'lastname' =>'Deo',
     'suffix' => '',
     'company' =>'', 
     'street' => array(
             '0' => 'Noida',
             '1' => 'Sector 64'
         ),
     'city' => 'Noida',
     'country_id' => 'IN',
     'region' => 'UP',
     'postcode' => '201301',
     'telephone' => '78676789',
     'fax' => 'gghlhu',
     'vat_id' => '',
     'save_in_address_book' => 1
 ));

 // Set Sales Order Shipping Address
$shippingAddress = $quote->getShippingAddress()->addData(array(
     'customer_address_id' => '',
     'prefix' => '',
     'firstname' => 'john',
     'middlename' => '',
     'lastname' =>'Deo',
     'suffix' => '',
     'company' =>'', 
     'street' => array(
             '0' => 'Noida',
             '1' => 'Sector 64'
         ),
     'city' => 'Noida',
     'country_id' => 'IN',
     'region' => 'UP',
     'postcode' => '201301',
     'telephone' => '78676789',
     'fax' => 'gghlhu',
     'vat_id' => '',
     'save_in_address_book' => 1
 ));
 if($shipprice==0){
     $shipmethod='freeshipping_freeshipping';
 }

 $quote->setData('overstock_shipping_total', 0);

$quote->setData('overstock_carrier', "UPS");
$quote->setData('overstock_shipmethod', "Ground");

$shippingAddress->setCollectShippingRates(true)->setShippingMethod('overstockshippingrate_overstockshippingrate')->collectShippingRates();
$shippingAddress->setPaymentMethod('overstock');
 $quote->getPayment()->importData(array('method' => 'overstock'));

 // Collect Totals & Save Quote
 $quote->collectTotals()->save();

 // Create Order From Quote
 $service = Mage::getModel('sales/service_quote', $quote);
 $service->submitAll();
 $increment_id = $service->getOrder()->getRealOrderId();

 // Resource Clean-Up
 $quote = $customer = $service = null;
 echo $increment_id;
 // Finished
 return $increment_id;

1 Answer 1

0

you need to add bundle product with more than one parameter:

change

$quote->addProduct($product,new Varien_Object(array('qty'   => 1)));

to

$quote->addProduct($product,$params);

$params explained here: http://inchoo.net/magento/programatically-add-bundle-product-to-cart-n-magento/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.