C# 获取制造商';在C中使用Magento SOAP API V2的给定产品ID的名称#
我需要得到制造商的名称,给定一个产品代码。下面的代码存根返回制造商的ID(值如109、120等)。有没有办法用制造商的名字代替ID?我可以看到在PHP中有一些关于这个问题的好例子,但我正在用C#寻找答案。任何帮助都将不胜感激!期待中的感谢 目前的代码是:C# 获取制造商';在C中使用Magento SOAP API V2的给定产品ID的名称#,c#,magento,C#,Magento,我需要得到制造商的名称,给定一个产品代码。下面的代码存根返回制造商的ID(值如109、120等)。有没有办法用制造商的名字代替ID?我可以看到在PHP中有一些关于这个问题的好例子,但我正在用C#寻找答案。任何帮助都将不胜感激!期待中的感谢 目前的代码是: public bool GetProductInfo(salesOrderItemEntity objProduct, ref StructProductInfo structProductInfo) {
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是一个整数“eav_attribute”,这就是您将获得整数值的原因 您将需要获得在Magnetor中设置的制造商数据的连接 不确定如何从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);
}
}
}
谢谢你的洞察力,肖恩。事实证明,catalogProductAttributeOptions派上了用场,我创建了一种根据代码查找制造商名称的机制。我很快就会发布代码。再次感谢您的反馈。嗨,Shaun,在相关工作中,我遇到了中描述的问题。你能看一下吗?你似乎很了解magento。已经度假一段时间了,很抱歉没有回来。不用担心。谢谢你的回复。谢天谢地,上述问题已经解决。如果数据升级到新版本的Magento,“102”可能会在以后发生变化,请注意。当然。谢谢目前,这在1.5.x和1.6.x版本中似乎表现良好。
sManufacturerName = (string) mhtManufacturers[sManufacturerCode];