Class: Spree::VariantPropertyRule

Inherits:
Base
  • Object
show all
Defined in:
app/models/spree/variant_property_rule.rb

Instance Method Summary collapse

Methods inherited from Base

display_includes

Methods included from Core::Permalinks

#generate_permalink, #save_permalink

Instance Method Details

#applies_to_variant?(variant) ⇒ Boolean

Checks whether the rule applies to the variant by checking the rule’s conditions against the variant’s option values.

Parameters:

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'app/models/spree/variant_property_rule.rb', line 40

def applies_to_variant?(variant)
  if apply_to_all
    matches_option_value_ids?(variant.option_value_ids)
  else
    (option_value_ids & variant.option_value_ids).present?
  end
end

#matches_option_value_ids?(option_value_ids) ⇒ Boolean

Checks whether the provided ids are the same as the rule’s condition’s option value ids.

Parameters:

  • option_value_ids (Array<Integer>)

    list of option value ids

Returns:

  • (Boolean)


30
31
32
# File 'app/models/spree/variant_property_rule.rb', line 30

def matches_option_value_ids?(option_value_ids)
  self.option_value_ids.sort == option_value_ids.sort
end