Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve product -> master attributes delegation #2474

Merged
merged 6 commits into from
Jan 2, 2018
Merged
25 changes: 19 additions & 6 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,30 @@ def find_or_build_master
end

MASTER_ATTRIBUTES = [
:rebuild_vat_prices, :sku, :price, :currency, :weight, :height, :width, :depth,
:cost_currency, :price_in, :price_for, :amount_in, :cost_price
:cost_currency,
:cost_price,
:depth,
:height,
:price,
:sku,
:weight,
:width,
]
MASTER_ATTRIBUTES.each do |attr|
delegate :"#{attr}", :"#{attr}=", to: :find_or_build_master
end

delegate :display_amount, :display_price, :has_default_price?, to: :find_or_build_master

delegate :images, to: :master, prefix: true
alias_method :images, :master_images
delegate :amount_in,
:display_amount,
:display_price,
:has_default_price?,
:images,
:price_for,
:price_in,
:rebuild_vat_prices=,
to: :find_or_build_master

alias_method :master_images, :images

has_many :variant_images, -> { order(:position) }, source: :images, through: :variants_including_master

Expand Down