Skip to content

Commit

Permalink
Merge pull request #2474 from nebulab/remove-variants-useless-setters
Browse files Browse the repository at this point in the history
Improve product -> master attributes delegation
  • Loading branch information
kennyadsl authored Jan 2, 2018
2 parents 7cd39e5 + 0f51149 commit 1e1ff30
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit 1e1ff30

Please sign in to comment.