2012-01-04 7 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

my_priceの代わりにmyPriceはどうですか?試しましたか? –

+0

私は同じ問題を抱えています。あなたはそれを理解しましたか?私のcatalogProductCrateEntityは何もデータを渡すことはありません。 –

答えて

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

+0

@Spyro古いものですが、製品の属性を取得して設定するのに役立つことは間違いありません。 [XML-RPC経由でMagentoに接続するC#API](http://www.molotovbliss.com/net-c-api-to-magento-via-xml-rpc) –

+0

これは他のリンクです[.NET C#Object Library MagentoのXML-RPC API用](http://code.google.com/p/csharlibformagexmlrpcapi/) –

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

代わりデフォルト例えば、有効なstoreviewを与えますこれを試してみてください:

handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "1"); 
関連する問題