[英]Getting the Manufacturer's Name for a Given Product ID using Magento SOAP API V2 in C#
给定产品代码,我需要获得制造商的名称 。 以下代码存根返回制造商的ID(值,如109、120等)。 有没有办法让制造商的名称插入ID? 我可以看到在PHP中有一些很好的例子可以解决这个问题,但是我正在C#中寻找答案。 任何帮助将不胜感激! 谢谢您的期待!
当前代码是:
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;
}
默认情况下,制造商为整数“ eav_attribute”,这就是为什么您将获得整数值的原因。
您需要加入以磁电机设置的制造商数据。
不确定从API端获取该数据的方法。
也许尝试使用属性选项而不是其他属性,然后获取该选项的标签。
想通了如何做到这一点。 “ 102”是“制造商”的属性代码。 将其与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);
}
}
}
因此,可以通过以下方式获得制造商的名称:
sManufacturerName = (string) mhtManufacturers[sManufacturerCode];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.