使用 nopCommerce 设置 ProductVariantAttribute 值
我需要为每次销售的每件商品指定一些值。想象一下能够为购物篮中的每件商品单独添加礼物信息。
如何才能实现这一目标?
我正在使用 nopCommerce 1.6(为了兼容 .net 3.5)。
我添加了三个“产品属性”(目录>产品>产品属性)。创建了一个产品,并在默认产品变体中向该产品添加了三个属性。
这些属性是 TextBox 类型,我相信它允许我输入任何我喜欢的字符串值。
如何以编程方式设置这些值。据我所知 ShoppingCartManager.AddToCart
看起来它需要一个包含属性 XML 的字符串作为第四个参数:
public static List<string> AddToCart(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, decimal customerEnteredPrice, int quantity);
但我看不到任何解释 XML 应如何构造的内容。
请注意:我正在与另一个 CMS 集成,因此我没有使用标准 nopCommerce 控件来显示产品。
I have a requirement to specify some values per-item per-sale. Imagine being able to add a gift message to each item in the basket individually.
How can this be achieved?
I'm using nopCommerce 1.6 (for .net 3.5 compatibility).
I have added three "Product Attributes" (Catalog > Products > Product Attributes). Created a product and in the default product variation, added the three attributes to the product.
The attributes are of type TextBox which, I believe will allow me to enter any value I like as a string.
How do I programatically set these values. From what I can tell ShoppingCartManager.AddToCart
looks like it takes a string containing XML for the attributes as the fourth argument:
public static List<string> AddToCart(ShoppingCartTypeEnum shoppingCartType, int productVariantId, string selectedAttributes, decimal customerEnteredPrice, int quantity);
But I can't see anything that explains how the XML should be structured.
Please note: I'm integrating with another CMS so I'm not using the standard nopCommerce controls for the display of the products.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要手动设置产品变体的产品属性值,您可以使用以下帮助程序方法:
NopSolutions.NopCommerce.BusinessLogic.Products.ProductManager
NopSolutions.NopCommerce.BusinessLogic.Products.Attributes。 ProductAttributeManager
NopSolutions.NopCommerce.BusinessLogic.Products.Attributes.ProductAttributeHelper
NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCartManager
(这假设您的项目基于普通的 nopCommerce示例站点。)
然而,该过程相当简单;我假设 nopCommerce 目录中的产品属性属于 TextBox 类型。这允许将任何字符串设置为属性的值。
流程概述
示例代码
To manually set the value of product attributes on a product variant you can use the helper methods found in :
NopSolutions.NopCommerce.BusinessLogic.Products.ProductManager
NopSolutions.NopCommerce.BusinessLogic.Products.Attributes.ProductAttributeManager
NopSolutions.NopCommerce.BusinessLogic.Products.Attributes.ProductAttributeHelper
NopSolutions.NopCommerce.BusinessLogic.Orders.ShoppingCartManager
(this presumes your project is based on the normal nopCommerce example site.)
The process is fairly straight forward however; I assume the product attributes are of type TextBox in the nopCommerce catalog. This allows any string to be set as the value of the attribute.
Overview of process
Example code
只是添加到这个字符串中。产品属性的 XML 如下所示...
Just to add to this string. The XML for the product attributes look like this...