Class: SolidusPromotions::ProductAdvertiser
- Inherits:
-
Object
- Object
- SolidusPromotions::ProductAdvertiser
- Defined in:
- app/models/solidus_promotions/product_advertiser.rb
Instance Attribute Summary collapse
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
-
#promotions ⇒ Object
readonly
Returns the value of attribute promotions.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(product:, order:, quantity: 1) ⇒ ProductAdvertiser
constructor
A new instance of ProductAdvertiser.
Constructor Details
#initialize(product:, order:, quantity: 1) ⇒ ProductAdvertiser
Returns a new instance of ProductAdvertiser.
7 8 9 10 11 12 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 7 def initialize(product:, order:, quantity: 1) @product = product @order = order @quantity = quantity @promotions = SolidusPromotions::LoadPromotions.new(order:).call end |
Instance Attribute Details
#order ⇒ Object (readonly)
Returns the value of attribute order.
5 6 7 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 5 def order @order end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
5 6 7 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 5 def product @product end |
#promotions ⇒ Object (readonly)
Returns the value of attribute promotions.
5 6 7 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 5 def promotions @promotions end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
5 6 7 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 5 def quantity @quantity end |
Instance Method Details
#call ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/solidus_promotions/product_advertiser.rb', line 14 def call return unless product.promotionable? SolidusPromotions::Promotion.ordered_lanes.each do |lane| SolidusPromotions::PromotionLane.set(current_lane: lane) do lane_promotions = promotions.select { |promotion| promotion.lane == lane } lane_benefits = eligible_benefits_for_promotable(lane_promotions.flat_map(&:benefits), order) if product.has_variants? product.variants.each { |variant| discount_variant(variant, lane_benefits) } else discount_variant(product.master, lane_benefits) end end end end |