Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento : Programmatically create order bundled products and configurable products
    text
    copied!<p>I tried using the following code from <a href="http://netzarbeiter.com/" rel="nofollow">Vinai</a> in creating an order but it only works in simple products. I already tried playing with the keys and values in $buyInfo but it seems the order won't proceed. I might be missing something?</p> <pre><code>$quote = Mage::getModel('sales/quote') -&gt;setStoreId(Mage::app()-&gt;getStore('default')-&gt;getId()); if ('do customer orders') { // for customer orders: $customer = Mage::getModel('customer/customer') -&gt;setWebsiteId(1) -&gt;loadByEmail('customer@example.com'); $quote-&gt;assignCustomer($customer); } else { // for guesr orders only: $quote-&gt;setCustomerEmail('customer@example.com'); } // add product(s) $product = Mage::getModel('catalog/product')-&gt;load(8); $buyInfo = array( 'qty' =&gt; 1, // custom option id =&gt; value id // or // configurable attribute id =&gt; value id ); $quote-&gt;addProduct($product, new Varien_Object($buyInfo)); $addressData = array( 'firstname' =&gt; 'Test', 'lastname' =&gt; 'Test', 'street' =&gt; 'Sample Street 10', 'city' =&gt; 'Somewhere', 'postcode' =&gt; '123456', 'telephone' =&gt; '123456', 'country_id' =&gt; 'US', 'region_id' =&gt; 12, // id from directory_country_region table ); $billingAddress = $quote-&gt;getBillingAddress()-&gt;addData($addressData); $shippingAddress = $quote-&gt;getShippingAddress()-&gt;addData($addressData); $shippingAddress-&gt;setCollectShippingRates(true)-&gt;collectShippingRates() -&gt;setShippingMethod('flatrate_flatrate') -&gt;setPaymentMethod('checkmo'); $quote-&gt;getPayment()-&gt;importData(array('method' =&gt; 'checkmo')); $quote-&gt;collectTotals()-&gt;save(); $service = Mage::getModel('sales/service_quote', $quote); $service-&gt;submitAll(); $order = $service-&gt;getOrder(); </code></pre> <p>Any idea on how to make it work also in bundled and configurable products? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload