简体   繁体   English

无法在magento中将可配置产品添加到购物车

[英]cannot add configurable product to cart in magento

i want to add a product to cart in magento , product details is : 我想在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

this configurable product have two color option red and blue, there is two simple product atached to this configurable product. 此可配置产品具有红色和蓝色两个颜色选项,此可配置产品有两个简单的产品。

i try with this code : 我尝试使用此代码:

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

but this code return me this message : 但是这段代码向我返回了此消息:

please specify product option(s) 请指定产品选项

i use this code to add simple product and it`s work fine : 我使用此代码添加简单的产品,它的工作正常:

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

my problem is with configurable product. 我的问题是可配置产品。 i try to add with simple child products but problem of this way is often child products have not price and price is setted to parent product. 我尝试添加简单的子产品,但是这种方式的问题通常是子产品没有价格,而价格被设置为母产品。 what is the problem in my code ? 我的代码有什么问题? is there any way to add configurable product to cart with out using API ? 有什么方法可以不使用API​​将可配置产品添加到购物车中?

this is what i found in product page source: 这是我在产品页面源代码中找到的:

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

Your array must be like below 您的数组必须如下所示

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

             )
));

Your $product array is missing the options key values. 您的$product数组缺少options键值。

You need to add options which should be An array in the form of option_id => content per the documentation. 您需要根据文档添加options ,该options为Option_id => content形式的数组

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM