Split products by local/remote distributor: apply to products, search results and taxon pages

This commit is contained in:
Rohan Mitchell
2012-06-24 09:21:44 +10:00
parent ebb624bdc3
commit 34f95ffb4a
5 changed files with 56 additions and 12 deletions

View File

@@ -0,0 +1,10 @@
require 'open_food_web/split_products_by_distributor'
Spree::ProductsController.class_eval do
include Spree::DistributorsHelper
include OpenFoodWeb::SplitProductsByDistributor
respond_override :index => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distributor @products, current_distributor
} } }
end

View File

@@ -0,0 +1,10 @@
require 'open_food_web/split_products_by_distributor'
Spree::TaxonsController.class_eval do
include Spree::DistributorsHelper
include OpenFoodWeb::SplitProductsByDistributor
respond_override :show => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distributor @products, current_distributor
} } }
end

View File

@@ -1,4 +1,19 @@
Deface::Override.new(:virtual_path => "spree/home/index",
:replace => "[data-hook='homepage_products']",
:partial => "spree/shared/products_by_distributor",
:name => "products")
:name => "products_home")
Deface::Override.new(:virtual_path => "spree/products/index",
:replace => "[data-hook='homepage_products']",
:partial => "spree/shared/products_by_distributor",
:name => "products_products")
Deface::Override.new(:virtual_path => "spree/products/index",
:replace => "[data-hook='search_results']",
:partial => "spree/shared/products_by_distributor",
:name => "products_search")
Deface::Override.new(:virtual_path => "spree/taxons/show",
:replace => "[data-hook='taxon_products']",
:partial => "spree/shared/products_by_distributor",
:name => "products_taxon")

View File

@@ -1,5 +1,5 @@
- if @products
#products= render 'spree/shared/products', :products => @products
#products= render 'spree/shared/products', :products => @products, :taxon => @taxon
- else
#products-local= render 'spree/shared/products', :products => @products_local
#products-remote= render 'spree/shared/products', :products => @products_remote
#products-local= render 'spree/shared/products', :products => @products_local, :taxon => @taxon
#products-remote= render 'spree/shared/products', :products => @products_remote, :taxon => @taxon

View File

@@ -36,23 +36,32 @@ feature %q{
end
it "splits the product listing by local/remote distributor" do
# Given two distributors, with a product under each
# 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')
taxonomy_root = taxonomy.root
taxon = create(:taxon, :name => 'Taxon one', :parent_id => taxonomy_root.id)
d1 = create(:distributor)
d2 = create(:distributor)
p1 = create(:product, :distributors => [d1])
p2 = create(:product, :distributors => [d2])
p1 = create(:product, :distributors => [d1], :taxons => [taxon])
p2 = create(:product, :distributors => [d2], :taxons => [taxon])
# When I select the first distributor
visit spree.root_path
click_link d1.name
# Then I should see products split by local/remote distributor
page.should_not have_selector '#products'
page.should have_selector '#products-local', :text => p1.name
page.should have_selector '#products-remote', :text => p2.name
# TODO: Also see on products page and taxon page
# on the home page, the products page, the search results page and the taxon page
[spree.root_path,
spree.products_path,
spree.products_path(:keywords => 'Product'),
spree.nested_taxons_path(taxon.permalink)
].each do |path|
visit path
page.should_not have_selector '#products'
page.should have_selector '#products-local', :text => p1.name
page.should have_selector '#products-remote', :text => p2.name
end
end
it "allows the user to leave the distributor" do