0

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.

user3162709
  • 159
  • 1
  • 3
  • 17
  • How are the price of options normally calculated? Outside of your PHP code, does the user see the price updated on the front-end as they select options before it adds to cart? Or does it normally only calculate the cost after it's added to the cart? EDIT: Depending on what you've got setup for configurable, this could be done a million different ways. – Mikel Bitson Nov 03 '15 at 17:56
  • Hello Mikel, thank you for your answer. Here is the [link](http://enzinger.rockforweb.com/yes-sir-pizza.html) try to choose 2 options – user3162709 Nov 03 '15 at 19:05
  • Howdy! This site appears to only have your customized way of adding to cart. Can you link me to the Family Pizza product page? This is the page that should work out of the box and we're trying to imitate. – Mikel Bitson Nov 03 '15 at 19:17
  • here you are [family pizza](http://enzinger_two.dev/index.php/main-conf-product.html) but on product page all working fine because there you can to choose only one option.......actualy on my page all working fine too if you choose only one option....but i need to choose few options – user3162709 Nov 03 '15 at 19:34
  • try to use a bundle product – chefjuanpi Nov 04 '15 at 04:21

1 Answers1

1

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!

Mikel Bitson
  • 3,583
  • 1
  • 18
  • 23
  • yes i think you are right...the best solution is simple products with custom options. could you please show me the code which will add simple product in cart with choosed options ? – user3162709 Nov 03 '15 at 21:09
  • here is new question about that [link](http://stackoverflow.com/questions/33509436/magento-how-to-add-simple-product-in-cart-programmatically-with-custom-options). THANK YOU FOR HELP ! – user3162709 Nov 03 '15 at 21:31
  • @user3162709 Excellent job noticing the end of one question and starting a new one. I'll go post on that one as soon as I get a minute :) – Mikel Bitson Nov 03 '15 at 21:44