2014-04-21 200 views
0

我正在使用可配置產品,我創建了顯示可配置產品的自定義視圖。我在將可配置產品添加到購物車時出現錯誤(請指定產品的選項)。 只有使用可配置產品纔會出現此錯誤。請指定產品的選項。可配置產品magento

我使用此代碼爲在上面的代碼添加到購物車

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

數組包含我所選擇的產品屬性值。 我不知道爲什麼會發生這種情況。

回答

0

經過很多嘗試,我發現錯誤,我錯過了$params陣列中的兩個參數uencform_key。它應該是這樣的

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