简体   繁体   中英

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.). Is there a way to get the manufacturer's name insted of the ID? I can see that there are some good examples in PHP for this question but I am looking for the answer in 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.

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.

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". Using this with catalogProductAttributeOptions(), I have built a small hashtable-based lookup for getting a manufacturer's name, given the manufacturer's code.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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