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.

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.rb
index 1a912ed8d9..8899820d06 100644
--- a/core/app/models/spree/line_item.rb
+++ b/core/app/models/spree/line_item.rb
@@ -70,11 +70,7 @@ module Spree
def update_price
currency_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?
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 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 #3391
context '#copy_price' do
+ let(:variant) { line_item.variant }
+
it "copies over a variant's prices" do
line_item.price = nil
line_item.cost_price = nil
@@ -169,6 +171,38 @@ describe Spree::LineItem, type: :model do
expect(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
+ end
end
# test for copying prices when the vat changes