2010-09-23 38 views
4

我有下面的代碼,嘗試獲取帶有所有相關屬性的產品。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 
    } 

回答

0

嘗試將最後一個屬性在catalogProductInfo爲 「無」

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

Magento 1.4 productIdentifierType

+0

不,這不起作用。我得到完全相同的結果。 – 2010-09-28 16:06:57

+0

http://code.google.com/p/csharlibformagexmlrpcapi/可以幫忙嗎? – B00MER 2010-09-29 01:21:44

+0

你的意思是「空」而不是「空」嗎? – codeulike 2011-05-09 16:04:40

4

你試圖讓標準(內置)屬性,或者自定義的?

請注意,catalogProductRequestAttributes對象(它告訴Magento你想得到的屬性)有兩個集合 - 一個用於標準屬性,另一個用於自定義。

像這樣的東西應該工作:

// 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"); 
0

丹尼斯,

基於相當多的試驗和錯誤,以下爲我工作:

1)在屬性集中的參數調用catalogProductAttributeList()應該是一個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()調用中的最後一個參數必須爲空。

如果您使用的是SKU而不是product_id,那麼第二個參數必須是產品的SKU(不是產品ID),最後一個參數必須是「sku」。

希望這會有所幫助。 PS:所有屬性集(對應於上面給出的14個ID)可以通過使用catalogProductAttributeSetList()來枚舉,它返回objcatalogProductAttributeSetEntity對象的數組。

+1

我剛剛注意到這個問題是在一年多以前問過的。我很抱歉如果這個迴應太遲了。無論如何,由於這個問題還沒有得到解答,我想對於有類似問題的人來說,它仍然可以派上用場。 – 2012-01-04 08:17:40