Try the Demo

Magento Forum

   
creating order programmatically with configurable product
 
webrod
Jr. Member
 
Total Posts:  23
Joined:  2012-09-03
 

HI,

I want to create by code, an order with products.
I did it with simple product.
it looks very well.

But when I add a simple product, that is actually linked to a configurable, then I can see only one item in the table sales_flat_order_item , while there shall be 2 (as when you do a real order of a simple linked to a configurable)
=> 1 item (the configurable)
=< 1 item (the simple product) with the parent_item_id set the the configurable above.
In the order, of course magento shows only one.

How to reproduce this?

Here is my code

//21454 is the simple product
$products = array(
\'21454\' => array(
\'qty\' => 1
)
);
$rowTotal $_product->getPrice() * $product[\'qty\'];
$orderItem Mage::getModel(\'sales/order_item\')
->
setStoreId($storeId)
->
setQuoteItemId(0)
->
setQuoteParentItemId(NULL)
->
setProductId($productId)
->
setProductType($_product->getTypeId())
->
setQtyBackordered(NULL)
->
setTotalQtyOrdered($product[\'rqty\'])
->
setQtyOrdered($product[\'qty\'])
->
setName($_product->getName())
->
setSku($_product->getSku())
->
setPrice($_product->getPrice())
->
setBasePrice($_product->getPrice())
->
setOriginalPrice($_product->getPrice())
->
setRowTotal($rowTotal)
->
setBaseRowTotal($rowTotal);

$subTotal += $rowTotal;
$order->addItem($orderItem);

Note that I googled, and found some post, they are talking about options, but they show the options ID and have no idea how to get them.
And I do not understand while I should do that, as the simple product is already a specific option (or combination of option)

Thanks,
Rod

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top