Please specify the product's option(s). configurable product magento

蓝咒 提交于 2019-12-25 12:08:24

问题


I am working with configurable product, I have created custom view for displaying configurable product. I am getting error (Please specify the product's option(s)) while adding configurable product to cart. This error occurs only with configurable product.

I am using this code for add to cart

 $params = array(
          'product' => $product->getId(),
          'super_attribute' => array (
                                133 => '3',
                                143 => '19',
                                142 => '18',
                                141 => '16',
                                140 => '14',
                                139 => '12',
                                138 => '10',
                                137 => '22',
                                136 => '9',
                                135 => '6',
                                144 => '21',
                              ),
          'qty' => 2,
      );


      $cart = Mage::getSingleton('checkout/cart');
      $cart->addProduct($product, $params);
      $cart->save();
      Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

in above code

  'super_attribute' => array (
                            133 => '3',
                            143 => '19',
                            142 => '18',
                            141 => '16',
                            140 => '14',
                            139 => '12',
                            138 => '10',
                            137 => '22',
                            136 => '9',
                            135 => '6',
                            144 => '21',
                          )

Array contains attributes value which I have selected for product. I don`t know why this is happening.


回答1:


After a lot of try I found the error, I was missing two parameter uenc and form_key in $params array. it should be like this

$params = array(
          'product' => $product->getId(),
          'form_key'=>$form_key,
          'uenc' =>Mage::app()->getRequest()->getParam('uenc', 1),
          'super_attribute' => $super_attribute,
          'qty' => $qty,
      );


来源:https://stackoverflow.com/questions/23199152/please-specify-the-products-options-configurable-product-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!