Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,7 @@ def update_item_total
end

def persist_totals
order.update_columns(
payment_state: order.payment_state,
shipment_state: order.shipment_state,
item_total: order.item_total,
item_count: order.item_count,
adjustment_total: order.adjustment_total,
included_tax_total: order.included_tax_total,
additional_tax_total: order.additional_tax_total,
payment_total: order.payment_total,
shipment_total: order.shipment_total,
promo_total: order.promo_total,
total: order.total,
updated_at: Time.current,
)
order.save!(validate: false)
end

# Updates the +shipment_state+ attribute according to the following logic:
Expand Down
24 changes: 11 additions & 13 deletions core/lib/spree/core/importer/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Importer
class Order

def self.import(user, params)
begin
ActiveRecord::Base.transaction do
ensure_country_id_from_params params[:ship_address_attributes]
ensure_state_id_from_params params[:ship_address_attributes]
ensure_country_id_from_params params[:bill_address_attributes]
Expand Down Expand Up @@ -45,9 +45,6 @@ def self.import(user, params)
end
end
order.reload
rescue
order.destroy if order && order.persisted?
raise
end
end

Expand All @@ -56,27 +53,27 @@ def self.create_shipments_from_params(shipments_hash, order)

line_items = order.line_items
shipments_hash.each do |s|
shipment = order.shipments.build
shipment = Shipment.new
shipment.tracking = s[:tracking]
shipment.stock_location = Spree::StockLocation.find_by_admin_name(s[:stock_location]) || Spree::StockLocation.find_by_name!(s[:stock_location])

inventory_units = s[:inventory_units] || []
inventory_units.each do |iu|
ensure_variant_id_from_params(iu)

unit = shipment.inventory_units.build
unit.order = order
unless line_item = order.line_items.find_by(variant_id: iu[:variant_id])
line_item = order.contents.add(Spree::Variant.find(iu[:variant_id]), 1)
end

# Spree expects a Inventory Unit to always reference a line
# item and variant otherwise users might get exceptions when
# trying to view these units. Note the Importer might not be
# able to find the line item if line_item.variant_id |= iu.variant_id
unit.variant_id = iu[:variant_id]
if line_item = order.line_items.find_by(variant_id: iu[:variant_id])
unit.line_item = line_item
else
unit.line_item = order.contents.add(Spree::Variant.find(iu[:variant_id]), 1)
end
shipment.inventory_units.new(
order: order,
variant_id: iu[:variant_id],
line_item: line_item
)
end

# Mark shipped if it should be.
Expand All @@ -88,6 +85,7 @@ def self.create_shipments_from_params(shipments_hash, order)
end
end

order.shipments << shipment
shipment.save!

shipping_method = Spree::ShippingMethod.find_by_name(s[:shipping_method]) || Spree::ShippingMethod.find_by_admin_name!(s[:shipping_method])
Expand Down