Sha256: ce7b3bafefe44cdbe60530d71cd43acd7463ad6160c918c1a54d893a29eb7325

Contents?: true

Size: 1.31 KB

Versions: 211

Compression:

Stored size: 1.31 KB

Contents

module Spree
  module ReturnItem::ExchangeVariantEligibility
    class SameOptionValue
      class_attribute :option_type_restrictions
      self.option_type_restrictions = []
      # This can be configured in an initializer, e.g.:
      # Spree::ReturnItem::ExchangeVariantEligibility::SameOptionValue.option_type_restrictions = ["size", "color"]
      #
      # This restriction causes only variants that share the same option value for the
      # specified option types to be returned. e.g.:
      #
      # option_type_restrictions = ["color", "waist"]
      # Variant: blue pants with 32 waist and 30 inseam
      #
      # can be exchanged for:
      # blue pants with 32 waist and 31 inseam
      #
      # cannot be exchanged for:
      # green pants with 32 waist and 30 inseam
      # blue pants with 34 waist and 32 inseam

      def self.eligible_variants(variant)
        product_variants = SameProduct.eligible_variants(variant).includes(option_values: :option_type)

        relevant_option_values = variant.option_values.select { |ov| option_type_restrictions.include? ov.option_type.name }
        if relevant_option_values.present?
          product_variants.select { |v| (relevant_option_values & v.option_values) == relevant_option_values }
        else
          product_variants
        end
      end
    end
  end
end

Version data entries

211 entries across 211 versions & 3 rubygems

Version Path
goca-spree-core-3.1.14.rails.5.0.1 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
goca-spree-core-3.1.14.rails.5.0 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
goca-spree-core-3.1.15.rails.5.0 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
goca-spree-core-3.1.15.pre.rails.pre.5.0 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.10.1 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.10.0 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.9.0 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.8.3 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.8.2 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.7.3 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.6.6 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.5.5 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.0.9 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.1.15 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.2.7 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.3.3 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.4.1 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.5.4 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.6.5 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
spree_core-4.7.2 app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb