Sha256: 60275b3e192b5a07dad48480096078bc7c62206bfa458444a2ec6b3fb2826402

Contents?: true

Size: 1.18 KB

Versions: 102

Compression:

Stored size: 1.18 KB

Contents

module Spree
  module Cart
    class Recalculate
      prepend Spree::ServiceModule::Base

      def call(order:, line_item:, line_item_created: false, options: {})
        order_updater = ::Spree::OrderUpdater.new(order)

        order.payments.store_credits.checkout.destroy_all
        order_updater.update

        shipment = options[:shipment]
        if shipment.present?
          # ADMIN END SHIPMENT RATE FIX
          # refresh shipments to ensure correct shipment amount is calculated when using price sack calculator
          # for calculating shipment rates.
          # Currently shipment rate is calculated on previous order total instead of current order total when updating a shipment from admin end.
          order.refresh_shipment_rates(::Spree::ShippingMethod::DISPLAY_ON_BACK_END)
          shipment.update_amounts
        else
          order.ensure_updated_shipments
        end

        ::Spree::PromotionHandler::Cart.new(order, line_item).activate
        ::Spree::Adjustable::AdjustmentsUpdater.update(line_item)
        ::Spree::TaxRate.adjust(order, [line_item.reload]) if line_item_created
        order_updater.update
        success(line_item)
      end
    end
  end
end

Version data entries

102 entries across 102 versions & 1 rubygems

Version Path
spree_core-4.10.1 app/services/spree/cart/recalculate.rb
spree_core-4.10.0 app/services/spree/cart/recalculate.rb
spree_core-4.9.0 app/services/spree/cart/recalculate.rb
spree_core-4.8.3 app/services/spree/cart/recalculate.rb
spree_core-4.8.2 app/services/spree/cart/recalculate.rb
spree_core-4.7.3 app/services/spree/cart/recalculate.rb
spree_core-4.6.6 app/services/spree/cart/recalculate.rb
spree_core-4.5.5 app/services/spree/cart/recalculate.rb
spree_core-4.0.9 app/services/spree/cart/recalculate.rb
spree_core-4.1.15 app/services/spree/cart/recalculate.rb
spree_core-4.2.7 app/services/spree/cart/recalculate.rb
spree_core-4.3.3 app/services/spree/cart/recalculate.rb
spree_core-4.4.1 app/services/spree/cart/recalculate.rb
spree_core-4.5.4 app/services/spree/cart/recalculate.rb
spree_core-4.6.5 app/services/spree/cart/recalculate.rb
spree_core-4.7.2 app/services/spree/cart/recalculate.rb
spree_core-4.7.1 app/services/spree/cart/recalculate.rb
spree_core-4.6.4 app/services/spree/cart/recalculate.rb
spree_core-4.7.0 app/services/spree/cart/recalculate.rb
spree_core-4.6.3 app/services/spree/cart/recalculate.rb