I am adding configurable product in cart programmatically.
$parentId = $post['parrent_product'];
$values = '';
foreach ($post['simple_product_id'] as $id) {
$values .= $id . ',';
}
$params = array(
'product' => $parentId,
'super_attribute' => array(
132 => $values, //132 - super_attribute_code, $values - its a string with simple products(options) ids
),
'qty' => $post['qty'],
);
$cart = Mage::getSingleton('checkout/cart');
$product = new Mage_Catalog_Model_Product();
$product->load($parentId);
$cart->addProduct($product, $params);
$cart->save();
I need to add configurable product with 2 options in cart. For example conf product is "pizza" and 2 options: cheese and tomato. Currently my code adding what i need but the price of options not calculating in cart.
This is not currently working because the product is a configurable product that is configured by a single attribute. This attribute can only have one value, it can not have multiple.
In order to get what you want out of this, you should create a product with Custom Options instead of having the user select configurable attributes. This will allow the user to select any of the options, adjusting the price along the way.
If you wanted to keep it as a configurable with attributes you'd need a new attribute for every topping and they would have to select (Full, left Half, Right Half, or None as the options) for their topping amount. This would then allow you to select more than one topping.
This should work on the product page before you try to make it work with a custom UI.
Cheers!