【问题标题】:cannot add configurable product to cart in magento无法在 magento 中将可配置产品添加到购物车
【发布时间】:2014-11-21 17:21:20
【问题描述】:

我想在magento中添加一个产品到购物车,产品详情是:

type = configurable
product id = 1300
product sku = FCC100
Attribute Code= color
Attribute Label= color
Attribute Id= 152
options value = 28,43
options label = blue,red

此可配置产品有红色和蓝色两种颜色选项,此可配置产品附有两个简单的产品。

我试试这段代码:

 $product = array(
    "product_id" =>"1300",
    "qty" => 2,
    "super_attribute" => array(152 => 28));
    $result = $proxy->shoppingCartProductAdd($sessionID, $cartID, array($product));

但是这段代码给我返回了这条消息:

请指定产品选项

我使用此代码添加简单的产品,它工作正常:

$result = $proxy->shoppingCartProductAdd($sessionID, $cartID, array(array(
        'product_id' =>   $productID  ,
        'sku' =>  $sku  ,
        'qty' => $qty,
        'options' =>array(0 =>array('key' => $option1id ,'value' => $option1value),1 =>array('key' => $option2id ,'value' => $option2value)),

        'bundle_option' => null,
        'bundle_option_qty' => null,
        'links' => null
        )));    

我的问题在于可配置产品。我尝试添加简单的子产品,但这种方式的问题通常是子产品没有价格并且价格设置为父产品。 我的代码有什么问题?有什么方法可以在不使用 API 的情况下将可配置产品添加到购物车?

这是我在产品页面源中找到的:

Product.Config({"attributes":{"152":{"id":"152","code":"color","label":"\u0631\u0646\u06af","options":[{"id":"28","label":"\u0622\u0628\u06cc","price":"0","oldPrice":"0","products":["1301"]},{"id":"47","label":"\u0632\u0631\u0634\u06a9\u06cc","price":"0","oldPrice":"0","products":["1302"]}]}},"template":"#{price}\u00a0\u0631\u06cc\u0627\u0644","basePrice":"550000","oldPrice":"550000","productId":"1300","chooseText":"\u0627\u0646\u062a\u062e\u0627\u0628 \u06cc\u06a9 \u06af\u0632\u06cc\u0646\u0647...","taxConfig":{"includeTax":false,"showIncludeTax":false,"showBothPrices":false,"defaultTax":0,"currentTax":0,"inclTaxTitle":"\u0634\u0627\u0645\u0644 \u0645\u0627\u0644\u06cc\u0627\u062a"}});

【问题讨论】:

  • 错误很明显,您没有传入 Magento 将商品添加到购物车所需的 options
  • @Alex i 传递选项的值,28 是蓝色的值

标签: php magento shopping-cart configurable-product


【解决方案1】:

您的数组必须如下所示

$arrProducts = array(
array(
    "product_id" =>"21",
    "qty" => 2,
            "super_attribute" => array(         
                92 => 162

             )
));

【讨论】:

    【解决方案2】:

    您的 $product 数组缺少 options 键值。

    您需要根据文档添加options,它应该是option_id => content 形式的数组

    $product = array(
                  "product_id" => "1300",
                  "qty" => 2,
                  "options" => array(         
                                    152 => 28
                               )
                  );
    

    文档:http://www.magentocommerce.com/api/soap/checkout/cartProduct/cart_product.add.html

    【讨论】:

    • 我用选项更改了 supper_attribute 但我仍然收到相同的消息
    • 我在问题中添加了产品属性信息,请看一下,谢谢
    • @mahdi,你有解决这个问题的办法吗?
    • 我也遇到了同样的错误,有没有人解决的方法。请帮忙。
    猜你喜欢
    • 2014-12-17
    • 1970-01-01
    • 2014-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多