简体   繁体   English

Magento API v2和C#级价格

[英]Magento API v2 and C# - tier prices

I am using C#.NET to connect to the Magento API v2 via SOAP. 我正在使用C#.NET通过SOAP连接到Magento API v2。 Everything is working fine until I try to update product with tier prices - "Invalid Tier Prices". 一切正常,直到我尝试更新层级价格的产品 - “无效的层级价格”。

I debuged what comes to Magento and two attributes of every tier price are missing - "qty" and "price". 我找到了Magento的内容,并且每个等级价格的两个属性都缺失了 - “数量”和“价格”。 Here's an envelope that magento gets: 这是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>

And here's how It's built in C# (trivial way, I know, but I'm just trying to get it working): 这就是它用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;
}

And the result of the above method I am adding to the product/add request: 以上方法的结果我将添加到产品/添加请求中:

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. PS。 I am using Magento 1.5 and the WSDL was imported to Visual Studio as a service reference (the code generated automatically). 我使用的是Magento 1.5,WSDL已作为服务引用导入到Visual Studio(自动生成的代码)。

Got it - the method should be fixed as such: 知道了-该方法应固定为:

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

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

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