From d8796d4bd8fe3e36d33e7b32e19286da285090ce Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:04:31 +0100 Subject: [PATCH 1/6] Split product delegated attributes on multiple lines This ensures we can have a better git history for future changes when we'll need to add/change/remove some items in that list. --- core/app/models/spree/product.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index d4adc7f97b3..7f88796514e 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -60,14 +60,28 @@ 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 + :rebuild_vat_prices, + :sku, + :price, + :currency, + :weight, + :height, + :width, + :depth, + :cost_currency, + :price_in, + :price_for, + :amount_in, + :cost_price, ] 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 :display_amount, + :display_price, + :has_default_price?, + to: :find_or_build_master delegate :images, to: :master, prefix: true alias_method :images, :master_images From cc6ed3cd045e5d642100a52444a730a9aa7f208b Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:09:57 +0100 Subject: [PATCH 2/6] Remove Spree::Product#currency getter and setter delegation to master Surprisingly, we do not have this method anymore on products and variants: product.currency NoMethodError: undefined method `currency' for # product.currency = 'EUR' NoMethodError: undefined method `currency=' for # --- core/app/models/spree/product.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 7f88796514e..d586621113b 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -63,7 +63,6 @@ def find_or_build_master :rebuild_vat_prices, :sku, :price, - :currency, :weight, :height, :width, From 3549f42905d2f7715f607fc466441eecfcbeadef Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:19:14 +0100 Subject: [PATCH 3/6] Remove Spree::Product#rebuild_vat_prices getter delegation to master This method has only its attr_writer defined on Spree::Variant --- core/app/models/spree/product.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index d586621113b..a67f72e4092 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -60,7 +60,6 @@ def find_or_build_master end MASTER_ATTRIBUTES = [ - :rebuild_vat_prices, :sku, :price, :weight, @@ -80,6 +79,7 @@ def find_or_build_master delegate :display_amount, :display_price, :has_default_price?, + :rebuild_vat_prices=, to: :find_or_build_master delegate :images, to: :master, prefix: true From 4a295ece8e01ed858376e953f5a8d656cf9d6853 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:21:50 +0100 Subject: [PATCH 4/6] Remove some useless delegation from product to master price_in, price_for and amount_in have no setter methods --- core/app/models/spree/product.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index a67f72e4092..c54b9b0c03c 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -67,18 +67,18 @@ def find_or_build_master :width, :depth, :cost_currency, - :price_in, - :price_for, - :amount_in, :cost_price, ] MASTER_ATTRIBUTES.each do |attr| delegate :"#{attr}", :"#{attr}=", to: :find_or_build_master end - delegate :display_amount, + delegate :amount_in, + :display_amount, :display_price, :has_default_price?, + :price_for, + :price_in, :rebuild_vat_prices=, to: :find_or_build_master From 0fa1d37ded11b2a59abee9594a26cd830d191c2f Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:25:10 +0100 Subject: [PATCH 5/6] Alphabetize Spree::Product::MASTER_ATTRIBUTES --- core/app/models/spree/product.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index c54b9b0c03c..1cde7884d19 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -60,14 +60,14 @@ def find_or_build_master end MASTER_ATTRIBUTES = [ - :sku, + :cost_currency, + :cost_price, + :depth, + :height, :price, + :sku, :weight, - :height, :width, - :depth, - :cost_currency, - :cost_price, ] MASTER_ATTRIBUTES.each do |attr| delegate :"#{attr}", :"#{attr}=", to: :find_or_build_master From 0f51149817d24945a567bfe4c8fba3254711a811 Mon Sep 17 00:00:00 2001 From: Alberto Vena Date: Fri, 22 Dec 2017 15:27:10 +0100 Subject: [PATCH 6/6] Move master_image delegation into main master delegations block --- core/app/models/spree/product.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 1cde7884d19..dd7b964d4b5 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -77,13 +77,13 @@ def find_or_build_master :display_amount, :display_price, :has_default_price?, + :images, :price_for, :price_in, :rebuild_vat_prices=, to: :find_or_build_master - delegate :images, to: :master, prefix: true - alias_method :images, :master_images + alias_method :master_images, :images has_many :variant_images, -> { order(:position) }, source: :images, through: :variants_including_master