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
Fixed: do not allow to create line items when there's no price in the… (#12073)
Damian Legawiece08bf59e1cf0
diff --git a/core/app/models/spree/line_item.rb b/core/app/models/spree/line_item.rbindex 1a912ed8d9..8899820d06 100644--- a/core/app/models/spree/line_item.rb+++ b/core/app/models/spree/line_item.rb@@ -70,11 +70,7 @@ module Spreedef update_pricecurrency_price = variant.price_in(order.currency)- self.price = if currency_price.amount.present?- currency_price.price_including_vat_for(tax_zone: tax_zone)- else- 0- end+ self.price = currency_price.price_including_vat_for(tax_zone: tax_zone) if currency_price.present?enddef copy_tax_categorydiff --git a/core/spec/models/spree/line_item_spec.rb b/core/spec/models/spree/line_item_spec.rbindex 7d0db99ebe..31904a5228 100644--- a/core/spec/models/spree/line_item_spec.rb+++ b/core/spec/models/spree/line_item_spec.rb@@ -159,6 +159,8 @@ describe Spree::LineItem, type: :model do# Test for #3391context '#copy_price' do+ let(:variant) { line_item.variant }+it "copies over a variant's prices" doline_item.price = nilline_item.cost_price = nil@@ -169,6 +171,38 @@ describe Spree::LineItem, type: :model doexpect(line_item.cost_price).to eq(variant.cost_price)expect(line_item.currency).to eq(variant.currency)end++ context "variant price amount is equal 0" do+ before do+ variant.prices.where(currency: order.currency).update_all(amount: 0.0)+ line_item.price = nil+ line_item.copy_price+ end++ it "copies over a variant's price" do+ expect(line_item.price).to eq(0)+ end++ it "should be valid" do+ expect(line_item).to be_valid+ end+ end++ context 'no price available in the selected currency' do+ before do+ variant.prices.where(currency: order.currency).delete_all+ line_item.price = nil+ line_item.copy_price+ end++ it "doesn't copy the price" do+ expect(line_item.price).to be_nil+ end++ it "shouldn't be valid" do+ expect(line_item).not_to be_valid+ end+ endend# test for copying prices when the vat changes