2012-01-04 26 views
6

Tôi đã thêm thuộc tính tùy chỉnh với mã "my_price" với "Loại đầu vào danh mục cho Chủ cửa hàng" được đặt thành "Giá" và gán nó cho "Mặc định" (chỉ) tập hợp thuộc tính.Magento API v2 và C# - đặt thuộc tính tùy chỉnh trong khi thêm sản phẩm

Bây giờ, tôi muốn đặt giá trị của nó, mỗi khi tôi thêm/cập nhật sản phẩm với API v2 (C#). Đây là mã không hoạt động (giá trị không được đặt):

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

Tôi đang làm gì sai?

+0

làm thế nào về myPrice thay vì my_price? Bạn đã thử chưa? –

+0

Tôi có cùng một vấn đề, bạn có tìm ra nó không. My catalogProductCrateEntity không bao giờ chuyển bất kỳ dữ liệu nào, –

Trả lời

5

Magento 1.6.1.0 có một lỗi mà kết quả với lỗi thuộc tính bổ sung.

Tôi đã nâng cấp Magento lên 1.6.2.0 và sự cố đã biến mất và các thuộc tính bổ sung hoạt động hoàn hảo.

dụ nhanh về cách hoạt động:

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; 

Hy vọng nó sẽ giúp một ai đó.

2

Hãy thử điều này và cho tôi biết kết quả.

AdditionalAttributes.key = "myPrice"; 
+0

Vẫn không có gì ... Tôi có phải làm mới tài liệu tham khảo dịch vụ không? Tôi thực sự không muốn làm điều đó, bởi vì có một số loại lỗi và Visual Studio không tạo ra mã yêu cầu đúng cách. – Cleankod

+0

@Spyro Tôi sẽ cung cấp cho bạn một liên kết cũ nhưng tôi chắc chắn bạn có thể giúp đỡ để có được và thiết lập các thuộc tính sản phẩm. [.net C# API tới Magento qua XML-RPC] (http://www.molotovbliss.com/net-c-api-to-magento-via-xml-rpc) –

+0

đây là liên kết khác [.NET C# Object Library cho API XML-RPC của Magento] (http://code.google.com/p/csharlibformagexmlrpcapi/) –

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

Cung cấp số lần xem trang hợp lệ thay vì mặc định ví dụ: hãy thử điều này:

handler.catalogProductCreate(session_id, "simple", attributeset_id, sku, mageProduct, "1"); 
Các vấn đề liên quan