Skip to content
Closed
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
11 changes: 3 additions & 8 deletions core/app/models/spree/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,10 @@ def insufficient_stock?
def options=(options = {})
return unless options.present?

opts = options.dup # we will be deleting from the hash, so leave the caller's copy intact
self.price = variant.price_in(currency).amount +
variant.price_modifier_amount_in(currency, options)

currency = opts.delete(:currency) || order.currency

self.currency = currency
self.price = variant.price_in(currency).amount +
variant.price_modifier_amount_in(currency, opts)

assign_attributes opts
assign_attributes options.except(:currency)
end

private
Expand Down
12 changes: 7 additions & 5 deletions core/app/models/spree/order_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ def add_to_line_item(variant, quantity, options = {})

if line_item
line_item.quantity += quantity.to_i
line_item.currency = currency unless currency.nil?
else
opts = { currency: order.currency }.merge ActionController::Parameters.new(options).permit(PermittedAttributes.line_item_attributes).to_h
line_item = order.line_items.new(quantity: quantity,
variant: variant,
options: opts)
permitted_controller_parameters = ActionController::Parameters.new(options).permit(PermittedAttributes.line_item_attributes).to_h
line_item = order.line_items.new(
quantity: quantity,
variant: variant,
currency: order.currency,
options: permitted_controller_parameters
)
create_order_stock_locations(line_item, options[:stock_location_quantities])
end
line_item.target_shipment = options[:shipment] if options.key? :shipment
Expand Down