Class: Workarea::Pricing::Discount::BuySomeGetSome::OrderItemsByProduct
- Inherits:
-
Object
- Object
- Workarea::Pricing::Discount::BuySomeGetSome::OrderItemsByProduct
- Includes:
- Enumerable
- Defined in:
- app/models/workarea/pricing/discount/buy_some_get_some/order_items_by_product.rb
Defined Under Namespace
Classes: Product
Instance Method Summary collapse
-
#initialize(order) ⇒ OrderItemsByProduct
constructor
A new instance of OrderItemsByProduct.
-
#products ⇒ Array<OrderProducts::Product>
Aggregate product that reflects all items in the order that share a product_id.
Constructor Details
#initialize(order) ⇒ OrderItemsByProduct
Returns a new instance of OrderItemsByProduct.
16 17 18 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/order_items_by_product.rb', line 16 def initialize(order) @order = order end |
Instance Method Details
#products ⇒ Array<OrderProducts::Product>
Aggregate product that reflects all items in the order that share a product_id
25 26 27 28 29 30 31 32 33 34 |
# File 'app/models/workarea/pricing/discount/buy_some_get_some/order_items_by_product.rb', line 25 def products @products ||= @order.items.group_by(&:product_id).map do |id, items| Product.new( id, items, items.sum(&:quantity), items.flat_map(&:category_ids).compact.uniq ) end end |