Sha256: dffe65c8e87cd9c13164c816d7c6cd9bdcb3a78a04e74fb7cb7b66e6b446f7ed
Contents?: true
Size: 1.3 KB
Versions: 9
Compression:
Stored size: 1.3 KB
Contents
module Spree class Promotion module Rules module OptionValueWithNumerificationSupport def preferred_eligible_values values = super || {} Hash[values.keys.map(&:to_i).zip( values.values.map do |v| (v.is_a?(Array) ? v : v.split(',')).map(&:to_i) end )] end end class OptionValue < PromotionRule prepend OptionValueWithNumerificationSupport MATCH_POLICIES = %w(any) preference :match_policy, :string, default: MATCH_POLICIES.first preference :eligible_values, :hash def applicable?(promotable) promotable.is_a?(Spree::Order) end def eligible?(promotable, _options = {}) case preferred_match_policy when 'any' promotable.line_items.any? { |item| actionable?(item) } end end def actionable?(line_item) pid = line_item.product.id ovids = line_item.variant.option_values.pluck(:id) product_ids.include?(pid) && (value_ids(pid) - ovids).empty? end private def product_ids preferred_eligible_values.keys end def value_ids(product_id) preferred_eligible_values[product_id] end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems