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
[SD-994, NUT-200] Shipping summary label issue (#10563)
Kacper Mękarski92530ca9097b
diff --git a/core/app/models/spree/adjustment.rb b/core/app/models/spree/adjustment.rbindex 37ada324a0..89731272a6 100644--- a/core/app/models/spree/adjustment.rb+++ b/core/app/models/spree/adjustment.rb@@ -27,6 +27,7 @@ module Spreebelongs_to :sourceendbelongs_to :order, class_name: 'Spree::Order', inverse_of: :all_adjustments+ belongs_to :promotion_action, class_name: 'Spree::PromotionAction', foreign_key: :source_id, optional: true # created only for has_free_shipping?validates :adjustable, :order, :label, presence: truevalidates :amount, numericality: truediff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex 56f9337fb6..53c8e4e6df 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -649,10 +649,10 @@ module Spreeenddef has_free_shipping?- promotions.- joins(:promotion_actions).- where(spree_promotion_actions: { type: 'Spree::Promotion::Actions::FreeShipping' }).- exists?+ shipment_adjustments.+ joins(:promotion_action).+ where(spree_adjustments: { eligible: true, source_type: 'Spree::PromotionAction' },+ spree_promotion_actions: { type: 'Spree::Promotion::Actions::FreeShipping' }).exists?endprivatediff --git a/core/lib/spree/testing_support/factories/promotion_factory.rb b/core/lib/spree/testing_support/factories/promotion_factory.rbindex dfb5948804..a1fdc8a3c6 100644--- a/core/lib/spree/testing_support/factories/promotion_factory.rb+++ b/core/lib/spree/testing_support/factories/promotion_factory.rb@@ -1,4 +1,21 @@FactoryBot.define do+ trait :with_item_total_rule do+ transient do+ item_total_threshold_amount { 10 }+ end++ after(:create) do |promotion, evaluator|+ rule = Spree::Promotion::Rules::ItemTotal.create!(+ preferred_operator_min: 'gte',+ preferred_operator_max: 'lte',+ preferred_amount_min: evaluator.item_total_threshold_amount,+ preferred_amount_max: evaluator.item_total_threshold_amount + 100+ )+ promotion.rules << rule+ promotion.save!+ end+ end+factory :promotion, class: Spree::Promotion doname { 'Promo' }@@ -37,24 +54,8 @@ FactoryBot.define dopromotion.save!endend- factory :promotion_with_order_adjustment, traits: [:with_order_adjustment]-- trait :with_item_total_rule do- transient do- item_total_threshold_amount { 10 }- end- after(:create) do |promotion, evaluator|- rule = Spree::Promotion::Rules::ItemTotal.create!(- preferred_operator_min: 'gte',- preferred_operator_max: 'lte',- preferred_amount_min: evaluator.item_total_threshold_amount,- preferred_amount_max: evaluator.item_total_threshold_amount + 100- )- promotion.rules << rule- promotion.save!- end- end+ factory :promotion_with_order_adjustment, traits: [:with_order_adjustment]factory :promotion_with_item_total_rule, traits: [:with_item_total_rule]end@@ -66,5 +67,7 @@ FactoryBot.define doaction.promotion = promotionaction.saveend++ factory :free_shipping_promotion_with_item_total_rule, traits: [:with_item_total_rule]endenddiff --git a/core/spec/models/spree/order_spec.rb b/core/spec/models/spree/order_spec.rbindex 5a37e4ac77..21411bbe4e 100644--- a/core/spec/models/spree/order_spec.rb+++ b/core/spec/models/spree/order_spec.rb@@ -1347,4 +1347,45 @@ describe Spree::Order, type: :model doendendend++ describe '#has_free_shipping?' do+ subject { order.has_free_shipping? }++ let(:order) { create(:order_with_line_items, line_items_count: line_items_count) }+ let(:line_items_count) { 10 }++ context 'when promotion is applied' do+ let(:free_shipping_promotion) { create(:free_shipping_promotion, code: 'freeship') }++ before do+ order.coupon_code = free_shipping_promotion.code+ Spree::PromotionHandler::Coupon.new(order).apply+ end++ it { is_expected.to be true }++ context 'when free shipping promotion has item total rule' do+ let(:free_shipping_promotion) do+ create(:free_shipping_promotion_with_item_total_rule,+ code: 'freeship',+ starts_at: 1.day.ago,+ expires_at: 1.day.from_now)+ end++ context 'when order total is in defined range' do+ it { is_expected.to be true }+ end++ context 'when order total is not in defined range' do+ let(:line_items_count) { 15 }++ it { is_expected.to be false }+ end+ end+ end++ context 'when promotion is not applied' do+ it { is_expected.to be false }+ end+ endenddiff --git a/frontend/spec/features/free_shipping_promotions_spec.rb b/frontend/spec/features/free_shipping_promotions_spec.rbindex 1a1636fd99..1e27378637 100644--- a/frontend/spec/features/free_shipping_promotions_spec.rb+++ b/frontend/spec/features/free_shipping_promotions_spec.rb@@ -3,7 +3,6 @@ require 'spec_helper'describe 'Free shipping promotions', type: :feature, js: true dolet!(:country) { create(:country, name: 'United States of America', states_required: true) }let!(:state) { create(:state, name: 'Alabama', country: country) }- let!(:mug) { create(:product, name: 'RoR Mug', price: 20) }before docreate(:zone)@@ -13,10 +12,6 @@ describe 'Free shipping promotions', type: :feature, js: true docreate(:check_payment_method)- promotion = Spree::Promotion.create!(name: 'Free Shipping',- starts_at: 1.day.ago,- expires_at: 1.day.from_now)-action = Spree::Promotion::Actions::FreeShipping.newaction.promotion = promotionaction.save@@ -25,6 +20,14 @@ describe 'Free shipping promotions', type: :feature, js: true doendcontext 'free shipping promotion automatically applied' do+ let!(:mug) { create(:product, name: 'RoR Mug', price: 20) }+ let(:promotion) do+ create(:promotion,+ name: 'Free Shipping',+ starts_at: 1.day.ago,+ expires_at: 1.day.from_now)+ end+include_context 'proceed to payment step'# Regression test for #4428@@ -35,4 +38,32 @@ describe 'Free shipping promotions', type: :feature, js: true doendendend++ context 'when free shipping promotion applies for order total in defined range' do+ let(:promotion) do+ create(:free_shipping_promotion_with_item_total_rule,+ name: 'Free Shipping',+ starts_at: 1.day.ago,+ expires_at: 1.day.from_now)+ end++ include_context 'proceed to payment step'++ context 'when order total is less than defined range' do+ let!(:mug) { create(:product, name: 'RoR Mug', price: 5) }++ it 'does not apply the free shipping promotion' do+ page.has_text? 'SHIPPING: $10.00'+ page.has_text? 'Promotion (Free Shipping): -$10.00'+ end+ end++ context 'when order total is greater than defined range' do+ let!(:mug) { create(:product, name: 'RoR Mug', price: 60) }++ it 'applies the free shipping promotion' do+ page.has_text? 'SHIPPING: FREE'+ end+ end+ endend