Add first product to cart with order cycle choice

This commit is contained in:
Rohan Mitchell
2013-05-28 14:06:52 +10:00
parent 9ef7da1339
commit 1f9f5efb79
5 changed files with 41 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ Spree::OrdersController.class_eval do
if populate_valid? @distributor
order = current_order(true)
order.set_distributor! @distributor
order.set_order_cycle! @order_cycle
else
if populate_order_cycle_required

View File

@@ -10,4 +10,9 @@ module AddToCartHelper
def available_distributors_for(order, product)
DistributionChangeValidator.new(order).available_distributors_for(product)
end
def available_order_cycles_for(order, product)
DistributionChangeValidator.new(order).available_order_cycles_for(product)
end
end

View File

@@ -13,6 +13,8 @@
%div.cleared
%br
- available_distributors = available_distributors_for(order, @product)
- available_order_cycles = available_order_cycles_for(order, @product)
- if available_distributors.length > 1 || order.andand.distributor.nil?
= render 'add_to_cart_distributor_choice', distributor_collection: available_distributors
@@ -21,6 +23,9 @@
- changing_distributor = distributor != order.andand.distributor
= render 'add_to_cart_distributor_fixed', distributor: distributor, changing_distributor: changing_distributor
= render 'add_to_cart_order_cycle_choice', order_cycle_collection: available_order_cycles
%br
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
= t(:add_to_cart)

View File

@@ -0,0 +1,2 @@
%div Order cycle for your order:
= select_tag "order_cycle_id", options_from_collection_for_select([OrderCycle.new]+order_cycle_collection, "id", "name", current_order_cycle.andand.id)

View File

@@ -182,6 +182,34 @@ feature %q{
Spree::Order.last.should be_nil
end
scenario "adding the first product to the cart" do
# Given a product and some distributors
d = create(:distributor_enterprise)
p = create(:product, :price => 12.34)
oc = create(:simple_order_cycle, :distributors => [d], :variants => [p.master])
# When I add an item to my cart
visit spree.product_path p
select d.name, :from => 'distributor_id'
select oc.name, :from => 'order_cycle_id'
click_button 'Add To Cart'
# Then the correct totals should be displayed
page.should have_selector 'span.item-total', :text => '$12.34'
# TODO: Test these when order cycle fees is implemented
# page.should have_selector 'span.shipping-total', :text => '$1.23'
# page.should have_selector 'span.grand-total', :text => '$13.57'
# And the item should be in my cart
order = Spree::Order.last
line_item = order.line_items.first
line_item.product.should == p
# And my order should have its distributor and order cycle set to the chosen ones
order.distributor.should == d
order.order_cycle.should == oc
end
it "allows us to add two products from the same distributor" do
# Given two products, each at the same distributor