From 6d22f56c8619ea3de0a298e4037674b84e77a914 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Mon, 17 Jun 2013 11:29:36 +1000 Subject: [PATCH] Distribution selection form is not shown when there are products in the cart. This form doesn't filter options based on which can supply the products in the cart, so don't show it in those circumstances. --- app/helpers/spree/orders_helper.rb | 5 ++ app/views/order_cycles/_selection.html.erb | 56 +++++++++++---------- spec/features/consumer/order_cycles_spec.rb | 19 +++++++ 3 files changed, 53 insertions(+), 27 deletions(-) diff --git a/app/helpers/spree/orders_helper.rb b/app/helpers/spree/orders_helper.rb index d4eaa03484..09faba61ee 100644 --- a/app/helpers/spree/orders_helper.rb +++ b/app/helpers/spree/orders_helper.rb @@ -1,5 +1,10 @@ module Spree module OrdersHelper + def cart_is_empty + order = current_order(false) + order.nil? || order.line_items.empty? + end + def order_delivery_fee_subtotal(order, options={}) options.reverse_merge! :format_as_currency => true amount = order.line_items.map { |li| li.itemwise_shipping_cost }.sum diff --git a/app/views/order_cycles/_selection.html.erb b/app/views/order_cycles/_selection.html.erb index 84a917f9c0..97c9fbd472 100644 --- a/app/views/order_cycles/_selection.html.erb +++ b/app/views/order_cycles/_selection.html.erb @@ -1,31 +1,33 @@ <%# When written in HAML, dynamic attributes (ie. (class="order-cycle-#{foo}")) were failing to parse. Regrettably rewritten in ERB. Fix me! %> -
- <%= form_for current_order(true) do |f| %> -
-

Active Hubs

- <%= f.select :distributor_id, distributor_options(@distributors, f.object.distributor_id, current_order_cycle) %> -
- <%= f.submit 'Choose Hub' %> -
+<% if cart_is_empty %> +
+ <%= form_for current_order(true) do |f| %> +
+

Active Hubs

+ <%= f.select :distributor_id, distributor_options(@distributors, f.object.distributor_id, current_order_cycle) %> +
+ <%= f.submit 'Choose Hub' %> +
-
-

Closing Soon

- - <% @order_cycles.each do |order_cycle| %> - - - - - - <% end %> -
<%= f.radio_button :order_cycle_id, order_cycle.id %> - - - -
- <%= f.submit 'Choose Order Cycle' %> -
- <% end %> -
+
+

Closing Soon

+ + <% @order_cycles.each do |order_cycle| %> + + + + + + <% end %> +
<%= f.radio_button :order_cycle_id, order_cycle.id %> + + + +
+ <%= f.submit 'Choose Order Cycle' %> +
+ <% end %> +
+<% end %> diff --git a/spec/features/consumer/order_cycles_spec.rb b/spec/features/consumer/order_cycles_spec.rb index 3d85ab4335..f38ad1f664 100644 --- a/spec/features/consumer/order_cycles_spec.rb +++ b/spec/features/consumer/order_cycles_spec.rb @@ -153,5 +153,24 @@ feature %q{ page.should have_selector "input[value='#{@oc1.id}'][checked='checked']" page.should have_selector "option[value='#{@d1.id}'][selected='selected']" end + + scenario "selection form is not shown when there are products in the cart" do + # Given a product + d = create(:distributor_enterprise) + p = create(:product, :distributors => [d]) + + # When I go to the products listing page, I should see the selection form + visit spree.products_path + page.should have_selector "#distribution-selection" + + # When I add a product to the cart + visit spree.product_path p + select d.name, :from => 'distributor_id' + click_button 'Add To Cart' + + # Then I should no longer see the selection form + visit spree.products_path + page.should_not have_selector "#distribution-selection" + end end end