From c7cdca3e311f740a0a98bc213eff276f640f539b Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 17 Dec 2024 14:50:57 +0100 Subject: [PATCH 1/6] Update Ruby versions in circleCI config A year has passed, and we should update Ruby versions. --- .circleci/config.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9761924..9db6077 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -33,7 +33,7 @@ jobs: lint-code: executor: name: solidusio_extensions/sqlite - ruby_version: "3.0" + ruby_version: "3.1" steps: - solidusio_extensions/lint-code @@ -43,15 +43,15 @@ workflows: - run-specs: name: &name "run-specs-solidus-<< matrix.solidus >>-ruby-<< matrix.ruby >>-db-<< matrix.db >>" matrix: - parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } + parameters: { solidus: ["main"], ruby: ["3.3"], db: ["postgres"] } - run-specs: name: *name matrix: - parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } + parameters: { solidus: ["current"], ruby: ["3.2"], db: ["mysql"] } - run-specs: name: *name matrix: - parameters: { solidus: ["older"], ruby: ["3.0"], db: ["sqlite"] } + parameters: { solidus: ["older"], ruby: ["3.1"], db: ["sqlite"] } - lint-code "Weekly run specs against main": @@ -66,8 +66,8 @@ workflows: - run-specs: name: *name matrix: - parameters: { solidus: ["main"], ruby: ["3.2"], db: ["postgres"] } + parameters: { solidus: ["main"], ruby: ["3.3"], db: ["postgres"] } - run-specs: name: *name matrix: - parameters: { solidus: ["current"], ruby: ["3.1"], db: ["mysql"] } \ No newline at end of file + parameters: { solidus: ["current"], ruby: ["3.2"], db: ["mysql"] } From 5244e8583dc8969e56149958505432722382f28a Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 17 Dec 2024 14:44:29 +0100 Subject: [PATCH 2/6] Move patches to app/patches This should make the patches in line with the Flickwerk conventions. --- .../admin/variants_controller_decorator.rb | 42 ------------------- .../spree/base_helper_decorator.rb | 31 -------------- .../spree/line_item_decorator.rb | 18 -------- .../spree/variant_decorator.rb | 23 ---------- .../spree_admin_variants_controller_patch.rb | 38 +++++++++++++++++ .../spree_base_helper_patch.rb | 29 +++++++++++++ .../spree_line_item_patch.rb | 16 +++++++ .../spree_variant_patch.rb | 21 ++++++++++ 8 files changed, 104 insertions(+), 114 deletions(-) delete mode 100644 app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb delete mode 100644 app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb delete mode 100644 app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb delete mode 100644 app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb create mode 100644 app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb create mode 100644 app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb create mode 100644 app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb create mode 100644 app/patches/models/solidus_volume_pricing/spree_variant_patch.rb diff --git a/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb b/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb deleted file mode 100644 index bfafc6d..0000000 --- a/app/decorators/controllers/solidus_volume_pricing/spree/admin/variants_controller_decorator.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -module SolidusVolumePricing - module Spree - module Admin - module VariantsControllerDecorator - def edit - @variant.volume_prices.build if @variant.volume_prices.empty? - super - end - - def volume_prices - @product = @variant.product - @variant.volume_prices.build if @variant.volume_prices.empty? - end - - private - - # this loads the variant for the master variant volume price editing - def load_resource_instance - parent - - if new_actions.include?(params[:action].to_sym) - build_resource - elsif params[:id] - ::Spree::Variant.find(params[:id]) - end - end - - def location_after_save - if @product.master.id == @variant.id && params[:variant].key?(:volume_prices_attributes) - return volume_prices_admin_product_variant_url(@product, @variant) - end - - super - end - - ::Spree::Admin::VariantsController.prepend self - end - end - end -end diff --git a/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb b/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb deleted file mode 100644 index 64fca5f..0000000 --- a/app/decorators/helpers/solidus_volume_pricing/spree/base_helper_decorator.rb +++ /dev/null @@ -1,31 +0,0 @@ -# frozen_string_literal: true - -module SolidusVolumePricing - module Spree - module BaseHelperDecorator - def self.prepended(base) - base.module_eval do - def display_volume_price(variant, quantity = 1, user = nil) - price_display(variant, quantity: quantity, user: user).price_string - end - - def display_volume_price_earning_percent(variant, quantity = 1, user = nil) - price_display(variant, quantity: quantity, user: user).earning_percent_string - end - - def display_volume_price_earning_amount(variant, quantity = 1, user = nil) - price_display(variant, quantity: quantity, user: user).earning_amount_string - end - - private - - def price_display(variant, quantity:, user:) - SolidusVolumePricing::PriceDisplay.new(variant, quantity: quantity, user: user) - end - end - end - - ::Spree::BaseHelper.prepend self - end - end -end diff --git a/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb b/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb deleted file mode 100644 index d0d75ab..0000000 --- a/app/decorators/models/solidus_volume_pricing/spree/line_item_decorator.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module SolidusVolumePricing - module Spree - module LineItemDecorator - def set_pricing_attributes - if quantity_changed? - options = SolidusVolumePricing::PricingOptions.from_line_item(self) - self.money_price = SolidusVolumePricing::Pricer.new(variant).price_for(options) - end - - super - end - - ::Spree::LineItem.prepend self - end - end -end diff --git a/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb b/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb deleted file mode 100644 index 75d42dd..0000000 --- a/app/decorators/models/solidus_volume_pricing/spree/variant_decorator.rb +++ /dev/null @@ -1,23 +0,0 @@ -# frozen_string_literal: true - -module SolidusVolumePricing - module Spree - module VariantDecorator - def self.prepended(base) - base.class_eval do - has_and_belongs_to_many :volume_price_models - has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy - has_many :model_volume_prices, -> { - order(position: :asc) - }, class_name: '::Spree::VolumePrice', through: :volume_price_models, source: :volume_prices - accepts_nested_attributes_for :volume_prices, allow_destroy: true, - reject_if: proc { |volume_price| - volume_price[:amount].blank? && volume_price[:range].blank? - } - end - end - - ::Spree::Variant.prepend self - end - end -end diff --git a/app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb b/app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb new file mode 100644 index 0000000..ad885e8 --- /dev/null +++ b/app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module SolidusVolumePricing + module SpreeAdminVariantsControllerPatch + def edit + @variant.volume_prices.build if @variant.volume_prices.empty? + super + end + + def volume_prices + @product = @variant.product + @variant.volume_prices.build if @variant.volume_prices.empty? + end + + private + + # this loads the variant for the master variant volume price editing + def load_resource_instance + parent + + if new_actions.include?(params[:action].to_sym) + build_resource + elsif params[:id] + ::Spree::Variant.find(params[:id]) + end + end + + def location_after_save + if @product.master.id == @variant.id && params[:variant].key?(:volume_prices_attributes) + return volume_prices_admin_product_variant_url(@product, @variant) + end + + super + end + + ::Spree::Admin::VariantsController.prepend self + end +end diff --git a/app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb b/app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb new file mode 100644 index 0000000..bd89fca --- /dev/null +++ b/app/patches/helpers/solidus_volume_pricing/spree_base_helper_patch.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +module SolidusVolumePricing + module SpreeBaseHelperPatch + def self.prepended(base) + base.module_eval do + def display_volume_price(variant, quantity = 1, user = nil) + price_display(variant, quantity: quantity, user: user).price_string + end + + def display_volume_price_earning_percent(variant, quantity = 1, user = nil) + price_display(variant, quantity: quantity, user: user).earning_percent_string + end + + def display_volume_price_earning_amount(variant, quantity = 1, user = nil) + price_display(variant, quantity: quantity, user: user).earning_amount_string + end + + private + + def price_display(variant, quantity:, user:) + SolidusVolumePricing::PriceDisplay.new(variant, quantity: quantity, user: user) + end + end + end + + ::Spree::BaseHelper.prepend self + end +end diff --git a/app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb b/app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb new file mode 100644 index 0000000..b8e2566 --- /dev/null +++ b/app/patches/models/solidus_volume_pricing/spree_line_item_patch.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module SolidusVolumePricing + module SpreeLineItemPatch + def set_pricing_attributes + if quantity_changed? + options = SolidusVolumePricing::PricingOptions.from_line_item(self) + self.money_price = SolidusVolumePricing::Pricer.new(variant).price_for(options) + end + + super + end + + ::Spree::LineItem.prepend self + end +end diff --git a/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb b/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb new file mode 100644 index 0000000..14dd1da --- /dev/null +++ b/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module SolidusVolumePricing + module SpreeVariantPatch + def self.prepended(base) + base.class_eval do + has_and_belongs_to_many :volume_price_models + has_many :volume_prices, -> { order(position: :asc) }, dependent: :destroy + has_many :model_volume_prices, -> { + order(position: :asc) + }, class_name: '::Spree::VolumePrice', through: :volume_price_models, source: :volume_prices + accepts_nested_attributes_for :volume_prices, allow_destroy: true, + reject_if: proc { |volume_price| + volume_price[:amount].blank? && volume_price[:range].blank? + } + end + end + + ::Spree::Variant.prepend self + end +end From 9035354dede707daa5a652779adb33e27fc26670 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 17 Dec 2024 16:28:50 +0100 Subject: [PATCH 3/6] Rubocop fix --- .../models/solidus_volume_pricing/spree_variant_patch.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb b/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb index 14dd1da..c812747 100644 --- a/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb +++ b/app/patches/models/solidus_volume_pricing/spree_variant_patch.rb @@ -11,8 +11,8 @@ def self.prepended(base) }, class_name: '::Spree::VolumePrice', through: :volume_price_models, source: :volume_prices accepts_nested_attributes_for :volume_prices, allow_destroy: true, reject_if: proc { |volume_price| - volume_price[:amount].blank? && volume_price[:range].blank? - } + volume_price[:amount].blank? && volume_price[:range].blank? + } end end From b830c8f16c8d267f27f3010c1ea85a313207ed20 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Mon, 13 Jan 2025 17:11:20 +0100 Subject: [PATCH 4/6] Install Flickwerk separately --- lib/solidus_volume_pricing.rb | 1 + lib/solidus_volume_pricing/engine.rb | 1 + solidus_volume_pricing.gemspec | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/solidus_volume_pricing.rb b/lib/solidus_volume_pricing.rb index 9e7cf46..9395d64 100644 --- a/lib/solidus_volume_pricing.rb +++ b/lib/solidus_volume_pricing.rb @@ -5,6 +5,7 @@ require 'deface' require 'solidus_core' require 'solidus_support' +require 'flickwerk' require 'solidus_volume_pricing/engine' require 'solidus_volume_pricing/version' require 'solidus_volume_pricing/range_from_string' diff --git a/lib/solidus_volume_pricing/engine.rb b/lib/solidus_volume_pricing/engine.rb index c0f57a2..27584fb 100644 --- a/lib/solidus_volume_pricing/engine.rb +++ b/lib/solidus_volume_pricing/engine.rb @@ -6,6 +6,7 @@ module SolidusVolumePricing class Engine < Rails::Engine include SolidusSupport::EngineExtensions + include Flickwerk isolate_namespace ::Spree diff --git a/solidus_volume_pricing.gemspec b/solidus_volume_pricing.gemspec index eee5a26..5bf0327 100644 --- a/solidus_volume_pricing.gemspec +++ b/solidus_volume_pricing.gemspec @@ -32,6 +32,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'solidus_backend', ['>= 2.4.0', '< 5'] spec.add_dependency 'coffee-rails' spec.add_dependency 'deface' + spec.add_dependency 'flickwerk', '~> 0.3.1' spec.add_dependency 'sassc-rails' spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5'] spec.add_dependency 'solidus_support', '~> 0.8' From 69917ca6dadf01d916e92254c87f2cbf5fb3e6e5 Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 14 Jan 2025 09:33:49 +0100 Subject: [PATCH 5/6] Move backend controller patch to lib/patches This stops us from loading the patch when solidus_backend is not available. --- .../spree_admin_variants_controller_patch.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {app/patches => lib/patches/backend}/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb (100%) diff --git a/app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb b/lib/patches/backend/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb similarity index 100% rename from app/patches/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb rename to lib/patches/backend/controllers/solidus_volume_pricing/spree_admin_variants_controller_patch.rb From 9c912b67f400ba7402917371a06737ec4091ac1b Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Tue, 14 Jan 2025 09:35:18 +0100 Subject: [PATCH 6/6] Temporarily depend on solidus_support with Flickwerk support --- Gemfile | 3 +++ lib/solidus_volume_pricing.rb | 1 - lib/solidus_volume_pricing/engine.rb | 1 - solidus_volume_pricing.gemspec | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 7b4f913..3cfd4a1 100644 --- a/Gemfile +++ b/Gemfile @@ -26,6 +26,9 @@ else gem 'sqlite3', '~> 1.4' end +# Temporarily use the `solidus_support` gem with Flickwerk support +gem "solidus_support", github: "mamhoff/solidus_support", branch: "re-enable-flickwerk" + # While we still support Ruby < 3 we need to workaround a limitation in # the 'async' gem that relies on the latest ruby, since RubyGems doesn't # resolve gems based on the required ruby version. diff --git a/lib/solidus_volume_pricing.rb b/lib/solidus_volume_pricing.rb index 9395d64..9e7cf46 100644 --- a/lib/solidus_volume_pricing.rb +++ b/lib/solidus_volume_pricing.rb @@ -5,7 +5,6 @@ require 'deface' require 'solidus_core' require 'solidus_support' -require 'flickwerk' require 'solidus_volume_pricing/engine' require 'solidus_volume_pricing/version' require 'solidus_volume_pricing/range_from_string' diff --git a/lib/solidus_volume_pricing/engine.rb b/lib/solidus_volume_pricing/engine.rb index 27584fb..c0f57a2 100644 --- a/lib/solidus_volume_pricing/engine.rb +++ b/lib/solidus_volume_pricing/engine.rb @@ -6,7 +6,6 @@ module SolidusVolumePricing class Engine < Rails::Engine include SolidusSupport::EngineExtensions - include Flickwerk isolate_namespace ::Spree diff --git a/solidus_volume_pricing.gemspec b/solidus_volume_pricing.gemspec index 5bf0327..eee5a26 100644 --- a/solidus_volume_pricing.gemspec +++ b/solidus_volume_pricing.gemspec @@ -32,7 +32,6 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'solidus_backend', ['>= 2.4.0', '< 5'] spec.add_dependency 'coffee-rails' spec.add_dependency 'deface' - spec.add_dependency 'flickwerk', '~> 0.3.1' spec.add_dependency 'sassc-rails' spec.add_dependency 'solidus_core', ['>= 2.0.0', '< 5'] spec.add_dependency 'solidus_support', '~> 0.8'