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.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
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.rbindex 5bc9de7682..cc4e868488 100644--- a/core/app/models/spree/line_item.rb+++ b/core/app/models/spree/line_item.rb@@ -57,16 +57,13 @@ module Spreeenddef 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+ endenddef copy_tax_categorydiff --git a/core/spec/models/spree/line_item_spec.rb b/core/spec/models/spree/line_item_spec.rbindex 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 doend# 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' doline_item.price = 10