开发者

Magento API in C#.Net: catalogProductRequestAttributes problem

开发者 https://www.devze.com 2023-01-17 20:07 出处:网络
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.

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();
        MagentoServic开发者_如何学JAVAeHelper 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
    }


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:

// assumes sessionId, sku and storeView are defined already
catalogProductRequestAttributes fetchattrib = new catalogProductRequestAttributes();
// it will only populate the attributes that you ask for
fetchattrib.attributes = new string[] { "name", "description", "short_description"};
fetchattrib.additional_attributes = new string[] { "number_of_legs", "can_jump"};
catalogProductReturnEntity prod = m_magentoClient.catalogProductInfo(
    sessionId, sku, storeView, fetchattrib, "sku");


try setting the last attribute in catalogProductInfo to "nothing"

objResource = magentoAPI.catalogProductInfo(gbl_strSession, productID, setStoreviewName, mc_filter, nothing)

Magento 1.4 productIdentifierType


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消