3

While creating order programmatically, attribute of Configurable product are not saved, I have a configurable product which entity id is 64 and having one attribute which id is 136 and the id of option value is 10, When I run this code I see in magento admin panel that the order was placed but attribute are not added and price was default as set for parent product.

$customer_id = 5;
$quote = Mage::getModel('sales/quote');
$customer = Mage::getModel('customer/customer')->load($customer_id);
$quote->assignCustomer($customer);
$quote->setStore(Mage::app()->getStore()); 
$product = Mage::getModel('catalog/product')->load(64);
$quoteItem = Mage::getModel('sales/quote_item')->setProduct($product);
$quoteItem->setQuote($quote);
$quoteItem->setQty(1);
$options = array(
    "product"=>$product, 
    "super_attribute"=>array(
        136=>10 
    )
); 
$quoteItem->addOption(new Varien_Object($options)); //$quoteItem->setProductOptions($options); tried both
$quote->addItem($quoteItem);

Magento Admin Order Page
Parent Product is showing without configurable options and their price. Magento Admin Order Page : Parent Product is showing without configurable options and their price.

1

When Magento adds configurable products to the cart what it actually does is adds two products and links them.

You will get the parent product and the child (selection) product added. So what I think you will need to do is add both products to your quote.

One great way of seeing exactly what you need to do is to step through the normal website functionality when adding the same product to the cart.

As far as I remember what it need to do is take the parent product id and the attributes as part of the request and pass this information into Mage_Checkout_Model_Cart::addProduct

On a slight side not you could always consider investigating using the api for such things.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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