C#.Net 中的 Magento API:catalogProductRequestAttributes 问题
我有下面的代码,试图返回具有所有相关属性的产品。
我没有收到任何错误,但我在“prod”变量中没有看到任何属性。
private void frmProductDetail_Load(object sender, EventArgs e)
{
MagentoService service = new MagentoService();
MagentoServiceHelper help = MagentoServiceHelper.Instance;
catalogAttributeEntity[] attributes = service.catalogProductAttributeList(help.SessionID, AttributeSet); //AttributeSet is a property of the form
catalogProductRequestAttributes att = new catalogProductRequestAttributes();
string[] attlist = new string[attributes.Length];
for (int i = 0; i < attributes.Length; i++)
{
attlist[i] = attributes[i].code;
}
att.attributes = attlist;
catalogProductReturnEntity prod = service.catalogProductInfo(help.SessionID,
ProductId, "default", att, "sku"); //ProductId is a property of the form
}
I have the code below, trying to get a product returned with all the relevant attributes.
I get no errors but I don't see any attributes in the "prod" variable.
private void frmProductDetail_Load(object sender, EventArgs e)
{
MagentoService service = new MagentoService();
MagentoServiceHelper help = MagentoServiceHelper.Instance;
catalogAttributeEntity[] attributes = service.catalogProductAttributeList(help.SessionID, AttributeSet); //AttributeSet is a property of the form
catalogProductRequestAttributes att = new catalogProductRequestAttributes();
string[] attlist = new string[attributes.Length];
for (int i = 0; i < attributes.Length; i++)
{
attlist[i] = attributes[i].code;
}
att.attributes = attlist;
catalogProductReturnEntity prod = service.catalogProductInfo(help.SessionID,
ProductId, "default", att, "sku"); //ProductId is a property of the form
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您想要获取标准(内置)属性还是自定义属性?
请注意,
catalogProductRequestAttributes
对象(它告诉 Magento 您想要获取哪些属性)有两个集合 - 一个用于标准属性,一个用于自定义属性。像这样的东西应该有效:
Are you trying to get the standard (built in) attributes, or custom ones?
Note that
catalogProductRequestAttributes
object (which tells Magento which attributes you want to be get) has two collections - one for standard attributes and one for custom.Something like this should work:
尝试将catalogProductInfo中的最后一个属性设置为“nothing”
Magento 1.4 ProductIdentifierType
try setting the last attribute in catalogProductInfo to "nothing"
Magento 1.4 productIdentifierType
Dennis,
基于相当多的试验和错误,以下内容对我有用:
1)对catalogProductAttributeList()的调用中的AttributeSet参数应该是一个整数,Magento可以将其识别为一组已知的属性。我使用 Magento Go 附带的默认数据,数字 9、38、39、40、41、42、44、45、46、58、59、60、61 和 62 有效。按此顺序,返回的属性总数为 63、67、71、68、66、68、67、65、63、63、61、63、66 和 64。我发现值 9 应该足以满足大多数产品。
2) 调用catalogProductInfo() 时的第二个参数必须对应于真正的Magento Product_id。例如,如果您要枚举销售订单,则该参数可以是 salesOrderItemEntity.product_id 的值。
3) 除了上面的第 2 点之外,catalogProductInfo() 调用中的最后一个参数必须为 null。
如果您使用 SKU 而不是 Product_id,则第二个参数必须是产品的 SKU(而不是产品 ID),最后一个参数必须是“sku”。
希望这有帮助。
PS:所有属性集(例如对应于上面给出的 14 个 ID)都可以使用 CatalogProductAttributeSetList() 进行枚举,该方法返回 objcatalogProductAttributeSetEntity 对象的数组。
Dennis,
Based on quite a bit of trial and error, the following worked for me:
1) The AttributeSet parameter in the call to catalogProductAttributeList() should be an integer that Magento can identify as a known set of attributes. I worked with the default data that comes with Magento Go and the numbers 9, 38, 39, 40, 41, 42, 44, 45, 46, 58, 59, 60, 61, and 62 worked. In that order, the total number of attributes returned was 63, 67, 71, 68, 66, 68, 67, 65, 63, 63, 61, 63, 66, and 64. I see that the value 9 should be sufficient for most products.
2) The second parameter in the call to catalogProductInfo() must correspond to a genuine Magento product_id. For instance, if you are enumerating sales orders, the parameter could be the value of salesOrderItemEntity.product_id.
3) In addition to point #2 above, the last parameter in the call to catalogProductInfo() must be null.
In case you are using SKU instead of product_id, then the second parameter MUST BE the SKU of the product (not the product ID) and the last parameter must be "sku".
Hope this helps.
PS: All of the attribute sets (corresponding to the 14 IDs given above, for instance) can be enumerated by using catalogProductAttributeSetList(), which returns an array of objcatalogProductAttributeSetEntity objects.