0

我正在使用可配置产品,我创建了用于显示可配置产品的自定义视图。在将可配置产品添加到购物车时出现错误(请指定产品的选项)。此错误仅发生在可配置产品中。

我正在使用此代码添加到购物车

 $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);

在上面的代码中

  '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',
                          )

数组包含我为产品选择的属性值。我不知道为什么会这样。

4

1 回答 1

0

经过大量尝试后,我发现了错误,我缺少两个参数uenc和数组form_key$params应该是这样的

$params = array(
          'product' => $product->getId(),
          'form_key'=>$form_key,
          'uenc' =>Mage::app()->getRequest()->getParam('uenc', 1),
          'super_attribute' => $super_attribute,
          'qty' => $qty,
      );
于 2014-04-22T11:28:57.330 回答