Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Always use currency price in LineItem#update_price

Damian Legawiec0bdfdb885532
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rb
index 5bc9de7682..cc4e868488 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -57,16 +57,13 @@ module Spree
end
def update_price
- if Spree::Config.show_store_currency_selector == true
- currency_price = Spree::Price.where(
- currency: order.currency,
- variant_id: variant_id
- ).first
+ currency_price = variant.price_in(order.currency)
- self.price = currency_price.price_including_vat_for(tax_zone: tax_zone)
- else
- self.price = variant.price_including_vat_for(tax_zone: tax_zone)
- end
+ self.price = if currency_price.amount.present?
+ currency_price.price_including_vat_for(tax_zone: tax_zone)
+ else
+ 0
+ end
end
def copy_tax_category
diff --git a/core/spec/models/spree/line_item_spec.rb b/core/spec/models/spree/line_item_spec.rb
index 054a14f467..cbd729ceea 100644
--- a/core/spec/models/spree/line_item_spec.rb
+++ b/core/spec/models/spree/line_item_spec.rb
@@ -171,25 +171,12 @@ describe Spree::LineItem, type: :model do
end
# test for copying prices when the vat changes
- context '#update_price' do
- let(:price) { double "price" }
- let(:order) { create :order, currency: "EUR" }
- let(:line_item) { create :line_item, order_id: order.id, currency: "EUR" }
-
- before do
- expect(line_item).to receive(:variant_id).and_return(1001)
-
- expect(Spree::Price).to receive(:where).with(
- currency: "EUR",
- variant_id: 1001
- ).and_return([price])
-
- expect(price).to receive(:price_including_vat_for).and_return(12)
-
- reset_spree_preferences do |config|
- config.show_store_currency_selector = true
- end
- end
+ describe '#update_price' do
+ let(:currency) { 'EUR' }
+ let(:order) { create(:order, currency: currency) }
+ let(:product) { create(:product_in_stock) }
+ let!(:line_item) { create(:line_item, order_id: order.id, currency: currency, product: product, variant: product.master) }
+ let!(:price) { create(:price, currency: currency, variant: product.master, amount: 12) }
it 'copies over a variants differing price for another vat zone' do
line_item.price = 10