我正在使用C#.NET通过SOAP连接到Magento API v2。在我尝试使用等级价格更新产品 - “无效的层级价格”之前,一切正常。
我找到了Magento的内容,并且每个等级价格的两个属性都缺失了 - “数量”和“价格”。这是magento获得的信封:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<q1:catalogProductUpdate xmlns:q1="urn:Magento">
<sessionId xsi:type="xsd:string">142163ba9058d5bc4d3b6b12445163a5</sessionId>
<product xsi:type="xsd:string">R-0.1UF</product>
<productData href="#id1" />
<storeView xsi:type="xsd:string">default</storeView>
</q1:catalogProductUpdate>
<q2:catalogProductCreateEntity id="id1" xsi:type="q2:catalogProductCreateEntity" xmlns:q2="urn:Magento">
<name xsi:type="xsd:string">Tantal PBF</name>
<status xsi:type="xsd:string">1</status>
<price xsi:type="xsd:string">0,25</price>
<tier_price href="#id2" />
</q2:catalogProductCreateEntity>
<q3:Array id="id2" q3:arrayType="q4:catalogProductTierPriceEntity[3]" xmlns:q3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:q4="urn:Magento">
<Item href="#id3" />
<Item href="#id4" />
<Item href="#id5" />
</q3:Array>
<q5:catalogProductTierPriceEntity id="id3" xsi:type="q5:catalogProductTierPriceEntity" xmlns:q5="urn:Magento">
<customer_group_id xsi:type="xsd:string">all</customer_group_id>
<website xsi:type="xsd:string">all</website>
</q5:catalogProductTierPriceEntity>
<q6:catalogProductTierPriceEntity id="id4" xsi:type="q6:catalogProductTierPriceEntity" xmlns:q6="urn:Magento">
<customer_group_id xsi:type="xsd:string">all</customer_group_id>
<website xsi:type="xsd:string">all</website>
</q6:catalogProductTierPriceEntity>
<q7:catalogProductTierPriceEntity id="id5" xsi:type="q7:catalogProductTierPriceEntity" xmlns:q7="urn:Magento">
<customer_group_id xsi:type="xsd:string">all</customer_group_id>
<website xsi:type="xsd:string">all</website>
</q7:catalogProductTierPriceEntity>
</s:Body>
</s:Envelope>
这就是它用C#构建的方式(我知道这很简单,但我只是想让它工作):
private catalogProductTierPriceEntity[] addTierPrices(List<V_prices> prices)
{
catalogProductTierPriceEntity[] mageTierPrices = new catalogProductTierPriceEntity[3];
catalogProductTierPriceEntity mageTierPrice;
int i = 0;
foreach (V_prices price in prices)
{
mageTierPrice = new catalogProductTierPriceEntity();
mageTierPrice.website = "all";
mageTierPrice.customer_group_id = "all";
mageTierPrice.qty = price.quantity;
mageTierPrice.price = (double)price.value; // Conversion from decimal
mageTierPrices[i] = mageTierPrice;
i++;
}
return mageTierPrices;
}
以上方法的结果我将添加到产品/添加请求中:
catalogProductCreateEntity mageProduct = new catalogProductCreateEntity();
// ..
mageProduct.name = product.name_db;
mageProduct.price = product.price.ToString();
mageProduct.status = "1";
mageProduct.tier_price = addTierPrices(prices);
handler.catalogProductUpdate(session_id, sku, mageProduct, "default", null);
PS。我正在使用Magento 1.5,并且WSDL作为服务引用导入到Visual Studio中(自动生成代码)。
答案 0 :(得分:3)
知道了 - 方法应该这样修复:
private catalogProductTierPriceEntity[] addTierPrices(List<V_prices> prices)
{
catalogProductTierPriceEntity[] mageTierPrices = new catalogProductTierPriceEntity[3];
catalogProductTierPriceEntity mageTierPrice;
int i = 0;
foreach (V_prices price in prices)
{
mageTierPrice = new catalogProductTierPriceEntity();
mageTierPrice.website = "all";
mageTierPrice.customer_group_id = "all";
mageTierPrice.qty = price.quantity;
mageTierPrice.price = (double)price.value; // Conversion from decimal
mageTierPrices[i] = mageTierPrice;
// FIX:
mageTierPrice.priceSpecified = true;
mageTierPrice.qtySpecified = true;
i++;
}
return mageTierPrices;
}