Please specify the product's option(s). config

2019-09-18 07:26发布

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条回答
姐就是有狂的资本
2楼-- · 2019-09-18 07:51

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,
      );
查看更多
登录 后发表回答