Extending the Spree::Product model/class

馋奶兔 提交于 2019-12-04 08:16:47
Martin Lang

The best thing to do here is to create a product_decorator.rb in your app.

This will look like the following:

Spree::Product.class_eval do

end

In there, you can feel free to modify whatever you want!

Here's the Documentation for that:

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

To add a new field to an already existing Model, run a migration like this:

migration

class AddSubscribableFieldToVariants < ActiveRecord::Migration
  def change
    add_column :spree_variants, :subscribable, :boolean, default: false
  end
end

And then in the model add following:

spree/variants_decorator.rb

Spree::Variant.class_eval do
  attr_accessible :subscribable
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!