Magento API v2 和 C# - 分级价格

发布于 2024-12-21 09:01:30 字数 3748 浏览 3 评论 0原文

我正在使用 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);

附言。我使用的是 Magento 1.5,WSDL 已作为服务引用导入到 Visual Studio(自动生成的代码)。

I am using C#.NET to connect to the Magento API v2 via SOAP. 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". Here's an envelope that magento gets:

<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):

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. I am using Magento 1.5 and the WSDL was imported to Visual Studio as a service reference (the code generated automatically).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我纯我任性 2024-12-28 09:01:30

明白了 - 该方法应该这样修复:

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

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文