通过Magento中的SOAP将产品添加到购物车时设置自定义选项 [英] Setting Custom Options while adding a product to cart via SOAP in Magento
问题描述
我正在尝试使用 shoppingCartProductAdd SOAP将带有自定义选项"的产品添加到购物车的API.
I am trying to use the shoppingCartProductAdd SOAP API to add a product with Custom Options to cart.
下面是我要传递给products参数的数组.我有一个自定义选项ID 1,在下拉列表中为其选择的值ID为2.(您可以查看
Below is the array I am passing for the products parameter. I've a custom option id 1 for which the selected value id in the dropdown is 2. (you can view the product here)
array (size=1)
0 =>
array (size=3)
'product_id' => int 25
'qty' => int 1
'options' =>
array (size=1)
1 => int 2
此产品被添加到购物车中,但是当我检索购物车详细信息/总计时,它不反映自定义选项.我还手动检查了在sales_flat_quote_item
和sales_flat_quote_item_option
表中创建的条目,但是行没有与自定义选项相关的任何数据或价格.
This product gets added to the cart but when I retrieve the cart details / totals, it does not reflect the custom options. I've also manually checked the entry created in the sales_flat_quote_item
and the sales_flat_quote_item_option
tables, but rows do not have any data or pricing related to the custom option.
我在做什么错了?
更新时间:2013年12月11日
我将自定义选项更改为必需".现在,当我尝试上述SOAP请求时,它给我一个请指定产品所需的选项." 错误.看起来只是忽略了我在数组中的options键.
I've changed the custom option to be "required". Now when I try the above SOAP request, it gives me a "Please specify the product required option(s)." error. Looks like it is just ignoring my options key in the array.
推荐答案
经过大量调试和摆弄之后,事实证明,选项"必须作为 associativeArray 传递,用SOAP术语来说,定义如下:
After much debugging and fiddling around, it turns out the 'options' must be passed as an associativeArray which in SOAP terms needs to be defined as follows:
array (size=1)
0 =>
array (size=3)
'product_id' => int 25
'qty' => int 1
'options' =>
array (size=1)
0 =>
array (size=2)
'key' => int 1
'value' => int 2
此处提供有关此格式的更多信息- https://stackoverflow.com/a/8963453/515268
More on this format here - https://stackoverflow.com/a/8963453/515268
使用这种格式,我能够通过SOAP成功添加带有自定义选项"的产品.购物车信息和总计中的定价也反映了预期价格.
Using this format, I am able to successfully add Products with Custom Options via SOAP. The pricing in the cart info and totals also reflects the expected price.
这篇关于通过Magento中的SOAP将产品添加到购物车时设置自定义选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!