mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
User can add subsequent order cycles product to cart, show order cycle selection in page header along with distributor
This commit is contained in:
@@ -22,7 +22,7 @@ table {
|
||||
/* Style current distributor in main nav bar */
|
||||
nav #main-nav-bar {
|
||||
li {
|
||||
&#current-distributor {
|
||||
&#current-distribution {
|
||||
float: right;
|
||||
clear: right;
|
||||
margin: 0.5em 5px 0 0;
|
||||
|
||||
@@ -33,7 +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
|
||||
order.set_order_cycle! @order_cycle if @order_cycle
|
||||
|
||||
else
|
||||
if populate_order_cycle_required
|
||||
|
||||
@@ -71,7 +71,7 @@ Spree::Product.class_eval do
|
||||
distribution = self.product_distributions.find_by_distributor_id(distributor)
|
||||
|
||||
unless distribution
|
||||
Bugsnag.notify(Exception.new "No product distribution for product #{id} at distributor #{distributor.id}. Perhaps this product is distributed via an order cycle? This is a warning that OrderCycle fees and shipping methods are not yet implemented, and the shipping fee charged is undefined until then.")
|
||||
Bugsnag.notify(Exception.new "No product distribution for product #{id} at distributor #{distributor.andand.id}. Perhaps this product is distributed via an order cycle? This is a warning that OrderCycle fees and shipping methods are not yet implemented, and the shipping fee charged is undefined until then.")
|
||||
end
|
||||
|
||||
distribution.andand.shipping_method || Spree::ShippingMethod.where("name != 'Delivery'").last
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Deface::Override.new(:virtual_path => "spree/shared/_main_nav_bar",
|
||||
:name => "add_current_distributor_to_main_nav_bar",
|
||||
:insert_after => "li#link-to-cart",
|
||||
:partial => "spree/shared/current_distributor",
|
||||
:original => '0d843946b3a53643c5a7da90a3a21610208db866')
|
||||
:partial => "spree/shared/current_distribution",
|
||||
:original => '0d843946b3a53643c5a7da90a3a21610208db866')
|
||||
9
app/views/spree/shared/_current_distribution.html.haml
Normal file
9
app/views/spree/shared/_current_distribution.html.haml
Normal file
@@ -0,0 +1,9 @@
|
||||
- if current_distributor || current_order_cycle
|
||||
%li#current-distribution{'data-hook' => ''}
|
||||
You are shopping
|
||||
- if current_distributor
|
||||
at
|
||||
= link_to current_distributor.name, root_path
|
||||
- if current_order_cycle
|
||||
in
|
||||
= link_to current_order_cycle.name, root_path
|
||||
@@ -1,4 +0,0 @@
|
||||
- if current_distributor
|
||||
%li#current-distributor{'data-hook' => ''}
|
||||
You are shopping at
|
||||
= link_to current_distributor.name, root_path
|
||||
@@ -88,7 +88,7 @@ feature %q{
|
||||
visit spree.cart_path
|
||||
page.should have_selector 'h4 a', :text => p1.name
|
||||
page.should have_selector 'h4 a', :text => p2.name
|
||||
page.should have_selector "#current-distributor a", :text => d2.name
|
||||
page.should have_selector "#current-distribution a", :text => d2.name
|
||||
end
|
||||
|
||||
it "when the only valid distributor is the chosen one, does not allow the user to choose a distributor" do
|
||||
@@ -136,7 +136,7 @@ feature %q{
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then My distributor should have changed
|
||||
page.should have_selector "#current-distributor a", :text => d2.name
|
||||
page.should have_selector "#current-distribution a", :text => d2.name
|
||||
end
|
||||
|
||||
it "does not allow the user to add a product from a distributor that cannot supply the cart's products" do
|
||||
@@ -211,6 +211,44 @@ feature %q{
|
||||
order.order_cycle.should == oc
|
||||
end
|
||||
|
||||
context "adding a subsequent product to the cart" do
|
||||
it "when there are several valid order cycles, allows a choice from these options" do
|
||||
# Given two products, both distributed by two distributors
|
||||
d1 = create(:distributor_enterprise)
|
||||
d2 = create(:distributor_enterprise)
|
||||
p1 = create(:product)
|
||||
p2 = create(:product)
|
||||
oc1 = create(:simple_order_cycle,
|
||||
:distributors => [d1, d2], :variants => [p1.master, p2.master])
|
||||
oc2 = create(:simple_order_cycle,
|
||||
:distributors => [d1, d2], :variants => [p1.master, p2.master])
|
||||
|
||||
# When I add the first to my cart via d1/oc1
|
||||
visit spree.product_path p1
|
||||
select d1.name, :from => 'distributor_id'
|
||||
select oc1.name, :from => 'order_cycle_id'
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# And I go to add the second, I should have a choice of order cycle and distributor
|
||||
visit spree.product_path p2
|
||||
page.should have_selector '#distributor_id option', :text => d1.name
|
||||
page.should have_selector '#distributor_id option', :text => d2.name
|
||||
page.should have_selector '#order_cycle_id option', :text => oc1.name
|
||||
page.should have_selector '#order_cycle_id option', :text => oc2.name
|
||||
|
||||
# When I add the second, both should be in my cart, and my
|
||||
# distributor and order cycle should be the one chosen second
|
||||
select d2.name, :from => 'distributor_id'
|
||||
select oc2.name, :from => 'order_cycle_id'
|
||||
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
|
||||
page.should have_selector "#current-distribution a", :text => d2.name
|
||||
page.should have_selector "#current-distribution a", :text => oc2.name
|
||||
end
|
||||
end
|
||||
|
||||
it "allows us to add two products from the same distributor" do
|
||||
# Given two products, each at the same distributor
|
||||
d = create(:distributor_enterprise)
|
||||
@@ -259,8 +297,8 @@ feature %q{
|
||||
# When I add the second to my cart
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then My distributor should have changed
|
||||
page.should have_selector "#current-distributor a", :text => d2.name
|
||||
# Then my distributor should have changed
|
||||
page.should have_selector "#current-distribution a", :text => d2.name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -38,6 +38,23 @@ feature %q{
|
||||
page.should_not have_selector 'div.distributor-description'
|
||||
end
|
||||
|
||||
it "displays the distributor and order cycle name on the home page when an order cycle is selected" do
|
||||
# Given a distributor with a product
|
||||
d = create(:distributor_enterprise, :name => 'Melb Uni Co-op')
|
||||
p = create(:product)
|
||||
oc = create(:simple_order_cycle, :name => 'Bulk Foods', :distributors => [d], :variants => [p.master])
|
||||
|
||||
# When I select the distributor and order cycle
|
||||
visit spree.product_path p
|
||||
select d.name, :from => 'distributor_id'
|
||||
select oc.name, :from => 'order_cycle_id'
|
||||
click_button 'Add To Cart'
|
||||
|
||||
# Then I should see the name of the distributor and order cycle that I've selected
|
||||
page.should have_content 'You are shopping at Melb Uni Co-op in Bulk Foods'
|
||||
page.should_not have_selector 'div.distributor-description'
|
||||
end
|
||||
|
||||
it "splits the product listing by local/remote distributor" do
|
||||
# Given two distributors, with a product under each, and each product under a taxon
|
||||
taxonomy = Spree::Taxonomy.find_by_name('Products') || create(:taxonomy, :name => 'Products')
|
||||
@@ -78,7 +95,7 @@ feature %q{
|
||||
click_button 'Browse All Distributors'
|
||||
|
||||
# Then I should have left the distributor
|
||||
page.should_not have_selector '#current-distributor', :text => 'You are shopping at Melb Uni Co-op'
|
||||
page.should_not have_selector '#current-distribution', :text => 'You are shopping at Melb Uni Co-op'
|
||||
end
|
||||
|
||||
context "viewing a product, it provides a choice of distributor when adding to cart" do
|
||||
|
||||
Reference in New Issue
Block a user