简体   繁体   English

使用C#中的Magento SOAP API V2获取给定产品ID的制造商名称

[英]Getting the Manufacturer's Name for a Given Product ID using Magento SOAP API V2 in C#

I am in need of getting the manufacturer's name , given a product code. 给定产品代码,我需要获得制造商的名称 The following code stub returns the manufacturer's ID (values like 109, 120, etc.). 以下代码存根返回制造商的ID(值,如109、120等)。 Is there a way to get the manufacturer's name insted of the ID? 有没有办法让制造商的名称插入ID? I can see that there are some good examples in PHP for this question but I am looking for the answer in C#. 我可以看到在PHP中有一些很好的例子可以解决这个问题,但是我正在C#中寻找答案。 Any help would be greatly appreciated! 任何帮助将不胜感激! Thanks in anticipation! 谢谢您的期待!

The current code is: 当前代码是:

        public bool GetProductInfo(salesOrderItemEntity objProduct, ref StructProductInfo structProductInfo)
        {
            bool bSuccess = false;

            catalogProductRequestAttributes attrib = new catalogProductRequestAttributes();

            attrib.additional_attributes = new string[] { "manufacturer" };

            catalogProductReturnEntity objProductInfo = null;

            objProductInfo = mservice.catalogProductInfo(mlogin, objProduct.product_id, "default", attrib, null);

            if (null != objProductInfo)
            {
                associativeEntity[] assoc = objProductInfo.additional_attributes;
                structProductInfo.ManufacturerCode = assoc[0].value;
                bSuccess = true;
            }

            return bSuccess;
        }

Manufacturer is an integer "eav_attribute" by default, and that is why you will get integer values. 默认情况下,制造商为整数“ eav_attribute”,这就是为什么您将获得整数值的原因。

You will need to get the join to the manufacturers data set up in magneto. 您需要加入以磁电机设置的制造商数据。

Not exactly sure how to do that data from the API end. 不确定从API端获取该数据的方法。

Maybe try attribute options, instead of additional attributes, and then get the label for that option. 也许尝试使用属性选项而不是其他属性,然后获取该选项的标签。

Figured out how to do this. 想通了如何做到这一点。 "102" is the attribute code for "manufacturer". “ 102”是“制造商”的属性代码。 Using this with catalogProductAttributeOptions(), I have built a small hashtable-based lookup for getting a manufacturer's name, given the manufacturer's code. 将其与catalogProductAttributeOptions()结合使用,我建立了一个基于哈希表的小型查询,以获取制造商的名称(给定制造商的代码)。

public void CreateManufacturerLookup()
{
    mhtManufacturers.Clear();  // mhtManufacturers is a hashtable declared with class scope

    catalogAttributeOptionEntity[] caoe = mservice.catalogProductAttributeOptions(mlogin, "102", "default");  // mlogin is the session ID and is available at class scope

    if (caoe.Length > 0)
    {
        for (int i = 0; i < caoe.Length; i++)
        {
            mhtManufacturers.Add(caoe[i].value, caoe[i].label);
        }
    }
}

So, manufacturer's name can be obtained by looking up as follows: 因此,可以通过以下方式获得制造商的名称:

sManufacturerName = (string) mhtManufacturers[sManufacturerCode];

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

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