Sha256: e1c35526fa432dddb203ffb8d5ddb791fbec34304c9f8579b9ea9380777155ca
Contents?: true
Size: 1.13 KB
Versions: 1
Compression:
Stored size: 1.13 KB
Contents
# This class is responsible for adding line items to order without going # through order contents. module SolidusSubscriptions class OrderBuilder attr_reader :order # Get a new instance of a OrderBuilder # # @param order [Spree::Order] The order to be built # # @return [SolidusSubscriptions::OrderBuilder] def initialize(order) @order = order end # Add line items for to an order. If the order already # has a line item for a given variant_id, update the quantity. Otherwise # add the line item to the order. # # @param items [Array<Spree::LineItem>] The order to add the line item to # @return [Array<Spree::LineItem] The collection that was passed in def add_line_items(items) items.map { |item| add_item_to_order(item) } end private def add_item_to_order(new_item) line_item = order.line_items.detect do |li| li.variant_id == new_item.variant_id end if line_item line_item.increment!(:quantity, new_item.quantity) else order.line_items << new_item end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
solidus_subscriptions-alpha-0.0.4 | app/models/solidus_subscriptions/order_builder.rb |