Sha256: 5c7a322df6124ebeebc93f396450ab6ae720d3d0aa8578cb0f757ba1f0bdfd1b
Contents?: true
Size: 1.26 KB
Versions: 57
Compression:
Stored size: 1.26 KB
Contents
module Spree module Cart class Update prepend Spree::ServiceModule::Base def call(order:, params:) return failure(order) unless order.update(filter_order_items(order, params)) 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. ActiveRecord::Base.transaction do order.update_with_updater! ::Spree::PromotionHandler::Cart.new(order).activate order.ensure_updated_shipments order.payments.store_credits.checkout.destroy_all order.update_with_updater! end success(order) end private def filter_order_items(order, params) return params if params[:line_items_attributes].nil? || params[:line_items_attributes][:id] line_item_ids = order.line_items.pluck(:id) params[:line_items_attributes].each_pair do |id, value| params[:line_items_attributes].delete(id) unless line_item_ids.include?(value[:id].to_i) || value[:variant_id].present? end params end end end end
Version data entries
57 entries across 57 versions & 1 rubygems