Sha256: 049bb06b07c045fa9079ab1ea3c083ba3d9999f847c805936639f794c76d5403

Contents?: true

Size: 1.14 KB

Versions: 3

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Spree
  class OrderContents < Spree::SimpleOrderContents
    # Updates the order's line items with the params passed in.
    # Also runs the PromotionHandler::Cart.
    def update_cart(params)
      if order.update(params)
        unless order.completed?
          order.line_items = order.line_items.select { |li| li.quantity > 0 }
          # Update totals, then check if the order is eligible for any cart promotions.
          # If we do not update first, then the item total will be wrong and ItemTotal
          # promotion rules would not be triggered.
          reload_totals
          order.check_shipments_and_restart_checkout
          ::Spree::PromotionHandler::Cart.new(order).activate
        end
        reload_totals
        true
      else
        false
      end
    end

    private

    def after_add_or_remove(line_item, options = {})
      reload_totals
      shipment = options[:shipment]
      shipment.present? ? shipment.update_amounts : order.check_shipments_and_restart_checkout
      ::Spree::PromotionHandler::Cart.new(order, line_item).activate
      reload_totals
      line_item
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
solidus_legacy_promotions-4.4.2 app/models/spree/order_contents.rb
solidus_legacy_promotions-4.4.1 app/models/spree/order_contents.rb
solidus_legacy_promotions-4.4.0 app/models/spree/order_contents.rb