Skip to content

Commit

Permalink
Merge pull request #3130 from aitbw/aitbw/fix-2998
Browse files Browse the repository at this point in the history
Allow orders with different shipping categories
  • Loading branch information
kennyadsl authored Oct 17, 2019
2 parents a9294a2 + d749a25 commit e48a6b4
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/shipping_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ShippingMethod < Spree::Base

scope :available_to_store, ->(store) do
raise ArgumentError, "You must provide a store" if store.nil?
store.shipping_methods.empty? ? all : where(id: store.shipping_method_ids)
store.shipping_methods.empty? ? all : where(id: store.shipping_methods.ids)
end

# @param shipping_category_ids [Array<Integer>] ids of desired shipping categories
Expand Down
32 changes: 32 additions & 0 deletions core/spec/models/spree/shipping_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,36 @@ def matching(categories)
it { should == 'back_end' }
end
end

describe '.available_to_store' do
let(:store) { create(:store) }
let(:first_shipping_method) { create(:shipping_method, stores: [store]) }
let(:second_shipping_method) { create(:shipping_method, stores: [store]) }

subject { [first_shipping_method, second_shipping_method] }

it 'raises an exception if no store is passed as argument' do
expect {
described_class.available_to_store(nil)
}.to raise_exception(ArgumentError, 'You must provide a store')
end

context 'when the store has no shipping methods associated' do
before { store.shipping_methods = [] }

it 'returns all shipping methods' do
expect(store.shipping_methods).to eq([])
expect(described_class.available_to_store(store)).to eq(subject)
end
end

context 'when the store has shipping methods associated' do
before { create(:shipping_method) }

it 'returns the associated records' do
expect(store.shipping_methods).to eq(subject)
expect(described_class.available_to_store(store)).to eq(subject)
end
end
end
end
51 changes: 51 additions & 0 deletions frontend/spec/features/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,57 @@
end
end

# Regression test for: https://github.com/solidusio/solidus/issues/2998
context 'when two shipping categories are available' do
let!(:first_category) { create(:shipping_category) }
let!(:second_category) { create(:shipping_category) }

let!(:first_shipping_method) do
create(:shipping_method,
shipping_categories: [first_category],
stores: [store])
end

let!(:second_shipping_method) do
create(:shipping_method,
shipping_categories: [second_category],
stores: [store])
end

context 'assigned to two different products' do
let!(:first_product) do
create(:product,
name: 'First product',
shipping_category: first_category)
end

let!(:second_product) do
create(:product,
name: 'Second product',
shipping_category: second_category)
end

before do
stock_location.stock_items.update_all(count_on_hand: 10)
end

it 'transitions successfully to the delivery step', js: true do
visit spree.product_path(first_product)
click_button 'add-to-cart-button'
visit spree.product_path(second_product)
click_button 'add-to-cart-button'

click_button 'Checkout'

fill_in_address
fill_in 'order_email', with: '[email protected]'
click_button 'Save and Continue'

expect(Spree::Order.last.state).to eq('delivery')
end
end
end

def fill_in_credit_card(number: "4111 1111 1111 1111")
fill_in "Name on card", with: 'Mary Doe'
fill_in_with_force "Card Number", with: number
Expand Down

0 comments on commit e48a6b4

Please sign in to comment.