扩展Spree :: Product模型/类

rod*_*ves 5 ruby-on-rails e-commerce spree

我在我的Rails 3.2应用程序中使用Spree,我想扩展Spree的Product类以更好地满足我的需求,例如在我的应用程序中与另一个模型建立关系.最好的方法是什么?我在项目文档中找不到任何相关内容

如果我想向Product资源添加新属性/字段该怎么办?我也找不到它的迁移:/

提前致谢 :)

Mar*_*ang 17

这里最好的办法是在您的应用中创建product_decorator.rb.

这将如下所示:

Spree::Product.class_eval do

end
Run Code Online (Sandbox Code Playgroud)

在那里,你可以随意修改你想要的任何东西!

这是以下文档:

https://guides.spreecommerce.com/developer/logic.html

要向现有模型添加新字段,请运行如下迁移:

移民

class AddSubscribableFieldToVariants < ActiveRecord::Migration
  def change
    add_column :spree_variants, :subscribable, :boolean, default: false
  end
end
Run Code Online (Sandbox Code Playgroud)

然后在模型中添加以下内容:

大礼包/ variants_decorator.rb

Spree::Variant.class_eval do
  attr_accessible :subscribable
end
Run Code Online (Sandbox Code Playgroud)