Class: Spree::ReturnItem::ExchangeVariantEligibility::SameOptionValue
- Inherits:
-
Object
- Object
- Spree::ReturnItem::ExchangeVariantEligibility::SameOptionValue
- Defined in:
- app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb
Class Method Summary collapse
-
.eligible_variants(variant) ⇒ Object
This can be configured in an initializer, e.g.: Spree::ReturnItem::ExchangeVariantEligibility::SameOptionValue.option_type_restrictions = [“size”, “color”].
Class Method Details
.eligible_variants(variant) ⇒ Object
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
22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/spree/return_item/exchange_variant_eligibility/same_option_value.rb', line 22 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 |