2012-01-04 39 views
6

我已將「my_price」代碼與「商店所有者的目錄輸入類型」設置爲「Price」並將其分配給「Default」(僅限於)屬性集。Magento API v2和C# - 在添加產品時設置自定義屬性

現在,我想設置它的價值,每次我使用API​​ v2(C#)添加/更新產品。這裏是不工作的代碼(值沒有設置):

// Connect & Auth: 
Mage_Api_Model_Server_V2_HandlerPortTypeClient handler = new Mage_Api_Model_Server_V2_HandlerPortTypeClient(); 
session_id = handler.login(username, api_key); 

// Getting attributes set: 
catalogProductAttributeSetEntity[] attributeSets; 
attributeSets = handler.catalogProductAttributeSetList(session_id); 
attributeSet = attributeSets[0]; 
string attributeset_id = attributeSet.set_id.ToString(); 

// Adding product: 
catalogProductCreateEntity mageProduct = new catalogProductCreateEntity(); 
// (...) setting product's name, sku, etc. 
associativeEntity AdditionalAttributes = new associativeEntity(); 
AdditionalAttributes.key = "my_price"; 
AdditionalAttributes.value = "12,33"; 
associativeEntity[] AssociativeEntity = new associativeEntity[1]; 
AssociativeEntity[0] = AdditionalAttributes; 
mageProduct.additional_attributes = AssociativeEntity; 
handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default"); 

我在做什麼錯了?

+0

如何myPrice而不是my_price?你試過了嗎? – 2012-01-04 20:36:48

+0

我有同樣的問題,你知道嗎。我的catalogProductCrateEntity從不傳遞任何數據, – 2012-02-03 20:39:58

回答

5

Magento的1.6.1.0具有與其他屬性的錯誤導致的錯誤。

我已將Magento升級到1.6.2.0,問題消失,其他屬性完美工作。它是如何工作

簡單的例子:

associativeEntity[] AdditionalAttributes = new associativeEntity[1]; 
associativeEntity AdditionalAttribute = new associativeEntity(); 
AdditionalAttribute.key = "myprice"; 
AdditionalAttribute.value = getOriginalPrice(prices).ToString(); 
AdditionalAttributes[0] = AdditionalAttribute; 
catalogProductAdditionalAttributesEntity AdditionalAttributesEntity = new catalogProductAdditionalAttributesEntity(); 
AdditionalAttributesEntity.single_data = AdditionalAttributes; 

mageProduct.additional_attributes = AdditionalAttributesEntity; 

希望它可以幫助別人。

2

試試這個,讓我知道結果。

AdditionalAttributes.key = "myPrice"; 
+0

仍然沒有任何...我是否需要刷新服務參考?我真的不想這樣做,因爲存在某種錯誤,並且Visual Studio不能正確生成所需的代碼。 – Cleankod 2012-01-10 17:06:27

+0

@Spyro我會給你一箇舊的鏈接,但我確定你能幫助獲取和設置產品屬性。 [.net C#API到Magento通過XML-RPC](http://www.molotovbliss.com/net-c-api-to-magento-via-xml-rpc) – 2012-01-10 20:45:54

+0

這是其他鏈接[.NET C#Object Library對於Magento的XML-RPC API](http://code.google.com/p/csharlibformagexmlrpcapi/) – 2012-01-10 20:49:30

0
handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "default"); 

提供有效storeview而不是默認例如試試這個:

handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "1"); 
相關問題