diff --git a/app/views/spree/products/_add_to_cart.html.haml b/app/views/spree/products/_add_to_cart.html.haml index aa15449f60..309e688f54 100644 --- a/app/views/spree/products/_add_to_cart.html.haml +++ b/app/views/spree/products/_add_to_cart.html.haml @@ -17,14 +17,17 @@ - if available_distributors.length > 1 || order.andand.distributor.nil? = render 'add_to_cart_distributor_choice', distributor_collection: available_distributors - - else - distributor = available_distributors.first - 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 + - if available_order_cycles.length > 1 || order.andand.order_cycle.nil? + = render 'add_to_cart_order_cycle_choice', order_cycle_collection: available_order_cycles + - else + - order_cycle = available_order_cycles.first + - changing_order_cycle = order_cycle != order.andand.order_cycle + = render 'add_to_cart_order_cycle_fixed', order_cycle: order_cycle, changing_order_cycle: changing_order_cycle %br = button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do diff --git a/app/views/spree/products/_add_to_cart_order_cycle_fixed.html.haml b/app/views/spree/products/_add_to_cart_order_cycle_fixed.html.haml new file mode 100644 index 0000000000..377b2c8e88 --- /dev/null +++ b/app/views/spree/products/_add_to_cart_order_cycle_fixed.html.haml @@ -0,0 +1,6 @@ += hidden_field_tag "order_cycle_id", order_cycle.id + +- if changing_order_cycle + .order-cycle-fixed= "Your order cycle for this order will be changed to #{order_cycle.name} if you add this product to your cart." +- else + .order-cycle-fixed= "Your order cycle for this order is #{order_cycle.name}" diff --git a/spec/features/consumer/add_to_cart_spec.rb b/spec/features/consumer/add_to_cart_spec.rb index 15e405d235..108c7b3b67 100644 --- a/spec/features/consumer/add_to_cart_spec.rb +++ b/spec/features/consumer/add_to_cart_spec.rb @@ -247,6 +247,35 @@ feature %q{ page.should have_selector "#current-distribution a", :text => d2.name page.should have_selector "#current-distribution a", :text => oc2.name end + + it "when the only valid order cycle is the chosen one, does not allow the user to choose an order cycle" do + # Given two products, each at the same distributor + d = create(:distributor_enterprise) + p1 = create(:product) + p2 = create(:product) + oc = create(:simple_order_cycle, :distributors => [d], + :variants => [p1.master, p2.master]) + + # When I add the first to my cart + visit spree.product_path p1 + select d.name, :from => 'distributor_id' + select oc.name, :from => 'order_cycle_id' + click_button 'Add To Cart' + + # And I go to add the second, I should not have a choice of distributor or order cycle + visit spree.product_path p2 + page.should_not have_selector 'select#distributor_id' + page.should have_selector '.distributor-fixed', :text => "Your distributor for this order is #{d.name}" + page.should_not have_selector 'select#order_cycle_id' + page.should have_selector '.order-cycle-fixed', :text => "Your order cycle for this order is #{oc.name}" + + # When I add the second, both should be in my cart + click_button 'Add To Cart' + visit spree.cart_path + page.should have_selector 'h4 a', :text => p1.name + page.should have_selector 'h4 a', :text => p2.name + end + end it "allows us to add two products from the same distributor" do