Spree:定制产品的关键属性
有谁知道是否可以向产品的关键属性集(名称、描述、永久链接、元描述等)添加新属性?我的想法是,我希望在创建产品时使用这些属性,而不是随后通过产品属性添加它们。
谢谢。
Does anyone know if it's possible to add a new attribute to the set of key attributes (Name, Description, Permalink, Meta Description etc) of a product? The idea is that I want to have these attributes available when I create a product instead of adding them afterwards through Product Properties.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是通过迁移将属性直接添加到产品模型中。可以通过使用装饰器来添加验证,装饰器是 Spree 中覆盖模型的首选模式。
另一种选择是为您的扩展字段创建辅助模型。也许 ProductExtension
然后在您的产品创建表单中,您可以使用 fields_for 提供这些字段。我认为需要注意的是,在扩展可用之前,您需要拥有创建的产品模型。您可能可以通过产品控制器创建操作中的一些额外逻辑来解决这个问题。
The simplest way would be to add attributes directly to the Product model through migrations. Validations can be added through the use of the decorators, the preferred pattern within Spree for overriding models.
Another option would be to create a secondary model for your extended fields. Perhaps ProductExtension
Then in your product creation forms you can supply these fields with a fields_for. I think one caveat with this is your going to need to have the created Product model before the extension becomes usable. You could probably get around this with some extra logic in the product controllers create action.
我扩展 Spree 产品模型的方法(通过 delegate_belongs_to):
My way to extend Product model for Spree (via delegate_belongs_to):