Ruby on rails 使用SOAP V2(Savon gem)将可配置产品添加到品红购物车
我陷入了一个非常常见的问题,但我找到的所有解决方案都是针对PHP而不是Ruby的 我正在使用savongem()与magentoapi soapv2通信 我尝试将可配置产品添加到购物车() 该产品有两种选择,风味和强度 我的代码是:Ruby on rails 使用SOAP V2(Savon gem)将可配置产品添加到品红购物车,ruby-on-rails,ruby,magento,soap,cart,Ruby On Rails,Ruby,Magento,Soap,Cart,我陷入了一个非常常见的问题,但我找到的所有解决方案都是针对PHP而不是Ruby的 我正在使用savongem()与magentoapi soapv2通信 我尝试将可配置产品添加到购物车() 该产品有两种选择,风味和强度 我的代码是: require 'savon' client = Savon.client(wsdl: 'http://example.com/api/v2_soap/index/wsdl/1') # new session session_id = client.call(:lo
require 'savon'
client = Savon.client(wsdl: 'http://example.com/api/v2_soap/index/wsdl/1')
# new session
session_id = client.call(:login, :message => {:username=> 'username', :apiKey=>'api_key'}).body[:login_response][:login_return]
# new cart
res = client.call(:shopping_cart_create, message: {sessionId: session_id})
quote_id = res.body[:shopping_cart_create_response][:quote_id]
product_id = 6
product_data = {
'product_id' => product_id,
'qty' => 1,
'options' => [{
'key' => 537,
'value' => 51
},
{
'key' => 549,
'value' => 60
},
]
}
res = client.call(:shopping_cart_product_add, message: {sessionId: session_id, quoteId: quote_id, products: {item: [product_data]}})
我有以下错误:
(1022) Please specify the product's option(s).
我认为我的选项参数是不正确的,但我不明白它应该是怎样的?UPD:这不起作用,但我不会因为评论中的信息而删除此答案 尝试将请求更改为此:
res = client.call(:shopping_cart_product_add,message: {
sessionId: session_id,
quoteId: quote_id,
products: [product_data]
})
UPD:这不起作用,但我不会因为评论中的信息而删除此答案 尝试将请求更改为此:
res = client.call(:shopping_cart_product_add,message: {
sessionId: session_id,
quoteId: quote_id,
products: [product_data]
})
终于,我明白了
我在wsi.xml
和wsdl.xml
中添加了shoppingCarteProductEntity
行:
<element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
然后(这是最重要的部分),以下是使用Savon gem的方法:
# ...
# Before we initialize client, session_id, quote_id...
product_data = {
'product_id' => 123,
'sku' => 'MYSKU',
'qty' => 1,
'super_attribute' => [
[
{
key: '537',
value: '57'
},
{
key: '549',
value: '66'
}
]
]
}
res = client.call(:shopping_cart_product_add, message: {sessionId: session_id, quoteId: quote_id, products: {item: [product_data] }})
终于,我明白了
我在wsi.xml
和wsdl.xml
中添加了shoppingCarteProductEntity
行:
<element name="super_attribute" type="typens:associativeArray" minOccurs="0"/>
然后(这是最重要的部分),以下是使用Savon gem的方法:
# ...
# Before we initialize client, session_id, quote_id...
product_data = {
'product_id' => 123,
'sku' => 'MYSKU',
'qty' => 1,
'super_attribute' => [
[
{
key: '537',
value: '57'
},
{
key: '549',
value: '66'
}
]
]
}
res = client.call(:shopping_cart_product_add, message: {sessionId: session_id, quoteId: quote_id, products: {item: [product_data] }})
products
不应该是数组而不是散列吗?我也不知道您从哪里获取了项键,我在API文档的示例中没有找到它。如果我这样做,这对我来说是强制性的:products:[product\u data]
,我得到了(1022)一项产品没有标识符或sku
产品不应该是数组而不是散列吗?我也不知道您从何处获取了项目密钥,我在API文档的示例中没有找到它。如果我有:产品:[product\u data]
,我得到了(1022)一项产品没有标识符或sku
(1022)一项产品没有标识符或sku
您的代码中在哪里分配了产品id
?它有什么价值?您确定第二个版本不需要设置SKU吗?我没有看到第二个版本中没有它的例子。请澄清“不工作”的确切含义。出现什么错误?不工作意味着:(1022)如果我为产品选择阵列,则一项产品没有标识符或sku
,或者(1022)请指定产品的选项。
使用项
键(1022)一项产品没有标识符或sku
在您的代码中指定了产品标识
?它有什么价值?您确定第二个版本不需要设置SKU吗?我没有看到第二个版本中没有它的例子。请澄清“不工作”的确切含义。出现什么错误?不工作意味着:(1022)如果我为产品选择阵列,则一项产品没有标识符或sku
,或者(1022)请使用项键指定产品的选项。