diff options
author | Alessandro Desantis <desa.alessandro@gmail.com> | 2021-02-05 13:30:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 13:30:47 +0100 |
commit | 3a3657b79bd5d98025136da4b39751e6a43b7b9f (patch) | |
tree | b7a57b183641d64d05e5e70e281fd78cb5e37ebd /app/services/solidus_subscriptions/order_builder.rb | |
parent | 69f0ca038b66d0ca36971405e51c0d3aa916cf19 (diff) | |
parent | 4717d24c0e7203210efe8c23b55467c3e728cdc5 (diff) |
Merge pull request #172 from solidusio-contrib/aldesantis/refactoring
Processor and Checkout refactoring
Diffstat (limited to 'app/services/solidus_subscriptions/order_builder.rb')
-rw-r--r-- | app/services/solidus_subscriptions/order_builder.rb | 42 |
1 files changed, 0 insertions, 42 deletions
diff --git a/app/services/solidus_subscriptions/order_builder.rb b/app/services/solidus_subscriptions/order_builder.rb deleted file mode 100644 index a577e98..0000000 --- a/app/services/solidus_subscriptions/order_builder.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -# 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 an OrderBuilder - # - # @param order [Spree::Order] The order to be built - # - # @return [SolidusSubscriptions::OrderBuilder] - def initialize(order) - @order = order - end - - # Add line items 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 |