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.
This commit is contained in:
Rohan Mitchell
2013-06-17 11:29:36 +10:00
parent 95de78f24e
commit 6d22f56c86
3 changed files with 53 additions and 27 deletions

View File

@@ -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

View File

@@ -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! %>
<div id="distribution-selection">
<%= form_for current_order(true) do |f| %>
<div class="distributors">
<h2>Active Hubs</h2>
<%= f.select :distributor_id, distributor_options(@distributors, f.object.distributor_id, current_order_cycle) %>
<br />
<%= f.submit 'Choose Hub' %>
</div>
<% if cart_is_empty %>
<div id="distribution-selection">
<%= form_for current_order(true) do |f| %>
<div class="distributors">
<h2>Active Hubs</h2>
<%= f.select :distributor_id, distributor_options(@distributors, f.object.distributor_id, current_order_cycle) %>
<br />
<%= f.submit 'Choose Hub' %>
</div>
<div class="order-cycles">
<h2>Closing Soon</h2>
<table>
<% @order_cycles.each do |order_cycle| %>
<tr class="order-cycle-<%= order_cycle.id %><%= order_cycle_local_remote_class(current_distributor, order_cycle) %>">
<td><%= f.radio_button :order_cycle_id, order_cycle.id %></td>
<td>
<label for="order_order_cycle_id_<%= order_cycle.id %>"><%= order_cycle.name %></label>
</td>
<td>
<label for="order_order_cycle_id_<%= order_cycle.id %>"><%= distance_of_time_in_words_to_now order_cycle.orders_close_at %></label>
</td>
</tr>
<% end %>
</table>
<%= f.submit 'Choose Order Cycle' %>
</div>
<% end %>
</div>
<div class="order-cycles">
<h2>Closing Soon</h2>
<table>
<% @order_cycles.each do |order_cycle| %>
<tr class="order-cycle-<%= order_cycle.id %><%= order_cycle_local_remote_class(current_distributor, order_cycle) %>">
<td><%= f.radio_button :order_cycle_id, order_cycle.id %></td>
<td>
<label for="order_order_cycle_id_<%= order_cycle.id %>"><%= order_cycle.name %></label>
</td>
<td>
<label for="order_order_cycle_id_<%= order_cycle.id %>"><%= distance_of_time_in_words_to_now order_cycle.orders_close_at %></label>
</td>
</tr>
<% end %>
</table>
<%= f.submit 'Choose Order Cycle' %>
</div>
<% end %>
</div>
<% end %>

View File

@@ -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