Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Remove deprecated filter and variant options presenters (#14009)

Damian Legawiece515e3674765
diff --git a/spree/core/app/presenters/spree/filters/price_presenter.rb b/spree/core/app/presenters/spree/filters/price_presenter.rb
deleted file mode 100644
index 0fed98cccf..0000000000
--- a/spree/core/app/presenters/spree/filters/price_presenter.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-module Spree
- module Filters
- class PricePresenter
- def initialize(amount:, currency:)
- Spree::Deprecation.warn('Spree::Filters::PricePresenter is deprecated and will be removed in Spree 5.5.')
- @amount = amount.to_i
- @currency = currency
- end
-
- def to_i
- amount
- end
-
- def to_s
- Spree::Money.new(amount, currency: currency, no_cents_if_whole: true).to_s
- end
-
- private
-
- attr_reader :amount, :currency
- end
- end
-end
diff --git a/spree/core/app/presenters/spree/filters/price_range_presenter.rb b/spree/core/app/presenters/spree/filters/price_range_presenter.rb
deleted file mode 100644
index 41d7b667ce..0000000000
--- a/spree/core/app/presenters/spree/filters/price_range_presenter.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-module Spree
- module Filters
- class PriceRangePresenter
- def self.from_param(param, currency:)
- prices = param.split('-')
-
- new(
- min_price: PricePresenter.new(amount: prices.first, currency: currency),
- max_price: PricePresenter.new(amount: prices.last, currency: currency)
- )
- end
-
- def initialize(min_price:, max_price:)
- Spree::Deprecation.warn('Spree::Filters::PriceRangePresenter is deprecated and will be removed in Spree 5.5.')
- @min_price = min_price
- @max_price = max_price
- end
-
- attr_reader :min_price, :max_price
-
- def to_param
- "#{min_price.to_i}-#{max_price.to_i}"
- end
-
- def to_s
- "#{min_price} - #{max_price}"
- end
- end
- end
-end
diff --git a/spree/core/app/presenters/spree/filters/quantified_price_range_presenter.rb b/spree/core/app/presenters/spree/filters/quantified_price_range_presenter.rb
deleted file mode 100644
index f44aa1088f..0000000000
--- a/spree/core/app/presenters/spree/filters/quantified_price_range_presenter.rb
+++ /dev/null
@@ -1,45 +0,0 @@
-module Spree
- module Filters
- class QuantifiedPriceRangePresenter
- ALLOWED_QUANTIFIERS = [
- :less_than,
- :more_than
- ].freeze
-
- def initialize(price:, quantifier:)
- Spree::Deprecation.warn('Spree::Filters::QuantifiedPriceRangePresenter is deprecated and will be removed in Spree 5.5.')
- if ALLOWED_QUANTIFIERS.exclude?(quantifier.to_sym)
- raise ArgumentError, "quantifier must be one of: #{ALLOWED_QUANTIFIERS.join(', ')}"
- end
-
- @price = price
- @quantifier = quantifier.to_sym
- end
-
- def to_param
- case quantifier
- when :less_than
- less_than_param
- when :more_than
- more_than_param
- end
- end
-
- def to_s
- "#{I18n.t("activerecord.attributes.spree/product.#{quantifier}")} #{price}"
- end
-
- private
-
- attr_reader :price, :quantifier
-
- def less_than_param
- "0-#{price.to_i}"
- end
-
- def more_than_param
- "#{price.to_i}-Infinity"
- end
- end
- end
-end
diff --git a/spree/core/app/presenters/spree/variants/options_presenter.rb b/spree/core/app/presenters/spree/variants/options_presenter.rb
deleted file mode 100644
index beede2f5da..0000000000
--- a/spree/core/app/presenters/spree/variants/options_presenter.rb
+++ /dev/null
@@ -1,82 +0,0 @@
-module Spree
- module Variants
- class OptionsPresenter
- WORDS_CONNECTOR = ', '.freeze
-
- attr_reader :variant
-
- delegate :option_values, to: :variant
-
- def initialize(variant)
- Spree::Deprecation.warn('Spree::Variants::OptionsPresenter is deprecated and will be removed in Spree 5.5. Please use Spree::Variant#options_text instead.')
- @variant = variant
- end
-
- def to_sentence
- options = option_values
- options = sort_options(options)
- options = present_options(options)
-
- join_options(options)
- end
-
- def to_hash
- options = option_values
- options = sort_options(options)
- options = present_options_as_hash(options)
-
- join_hash_options(options)
- end
-
- private
-
- def sort_options(options)
- if options.first&.association(:option_type)&.loaded?
- options.sort_by { |o| o.option_type.position }
- else
- options.includes(:option_type).sort_by { |o| o.option_type.position }
- end
- end
-
- def present_options(options)
- options.map do |ov|
- method = "present_#{ov.option_type.name}_option"
-
- respond_to?(method, true) ? send(method, ov) : present_option(ov)
- end
- end
-
- def present_color_option(option)
- "#{option.option_type.presentation}: #{option.presentation}"
- end
-
- def present_option(option)
- "#{option.option_type.presentation}: #{option.presentation}"
- end
-
- def join_options(options)
- options.to_sentence(words_connector: WORDS_CONNECTOR, two_words_connector: WORDS_CONNECTOR)
- end
-
- def present_options_as_hash(options)
- options.map do |ov|
- method = "present_#{ov.option_type.name}_option_as_hash"
-
- respond_to?(method, true) ? send(method, ov) : present_option_as_hash(ov)
- end
- end
-
- def present_option_as_hash(option)
- {}.tap do |hash|
- hash.store(option.option_type.presentation.downcase, option.presentation)
- end
- end
-
- def join_hash_options(options)
- return {} if options.empty?
-
- options.inject(:merge).symbolize_keys
- end
- end
- end
-end
diff --git a/spree/core/spec/presenters/spree/variants/options_presenter_spec.rb b/spree/core/spec/presenters/spree/variants/options_presenter_spec.rb
deleted file mode 100644
index 396ade05e2..0000000000
--- a/spree/core/spec/presenters/spree/variants/options_presenter_spec.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-require 'spec_helper'
-
-describe Spree::Variants::OptionsPresenter do
- describe '#to_sentence' do
- let(:option_type_1) { create :option_type, position: 2, name: 'Foo Type', presentation: 'Foo Type' }
- let(:option_type_2) { create :option_type, position: 1, name: 'Bar Type', presentation: 'Bar Type' }
-
- let(:option_value_1) { create :option_value, name: 'Foo', presentation: 'Foo', option_type: option_type_1 }
- let(:option_value_2) { create :option_value, name: 'Bar', presentation: 'Bar', option_type: option_type_2 }
-
- let(:variant) { build :variant, option_values: [option_value_1, option_value_2] }
-
- subject(:to_sentence) { described_class.new(variant).to_sentence }
-
- # Regression test for #2432
- it 'orders by bar than foo' do
- expect(to_sentence).to eq 'Bar Type: Bar, Foo Type: Foo'
- end
- end
-
- describe '#to_hash' do
- subject { described_class.new(variant).to_hash }
-
- let(:option_type_1) { create :option_type, name: 'color', presentation: 'Color' }
- let(:option_value_1) { create :option_value, option_type: option_type_1, name: 'white', presentation: 'White' }
- let(:option_type_2) { create :option_type, name: 'size', presentation: 'Size' }
- let(:option_value_2) { create :option_value, option_type: option_type_2, name: 'Medium', presentation: 'Medium' }
-
- context 'when variant has option values' do
- let(:variant) { create :variant, option_values: [option_value_1, option_value_2] }
-
- it 'returns valid hash' do
- expect(subject).to eq({ color: 'White', size: 'Medium' })
- end
- end
-
- context 'when variant has no option values' do
- let(:product) { create(:product) }
- let(:variant) { product.master }
-
- it 'returns empty hash' do
- expect(subject).to eq({})
- end
- end
- end
-end