请指定产品的选项.可配置产品magento [英] Please specify the product's option(s). configurable product magento

查看:91
本文介绍了请指定产品的选项.可配置产品magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

上面的代码

  '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.

推荐答案

经过大量尝试,我发现了错误,我在$params数组中缺少两个参数uencform_key.应该是这样

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

这篇关于请指定产品的选项.可配置产品magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆