Display distributor choice on add to cart form

This commit is contained in:
Rohan Mitchell
2012-06-24 11:28:06 +10:00
parent 9be5dc41b9
commit a91722a593
5 changed files with 41 additions and 22 deletions

View File

@@ -4,7 +4,15 @@ Spree::ProductsController.class_eval do
include Spree::DistributorsHelper
include OpenFoodWeb::SplitProductsByDistributor
before_filter :load_distributors, :only => :show
respond_override :index => { :html => { :success => lambda {
@products, @products_local, @products_remote = split_products_by_distributor @products, current_distributor
} } }
def load_distributors
@distributors = Spree::Distributor.by_name
end
end

View File

@@ -8,6 +8,8 @@ module Spree
validates :name, :pickup_address, :country_id, :state_id, :city, :post_code, :presence => true
scope :by_name, order('name')
after_initialize :initialize_country
def initialize_country

View File

@@ -0,0 +1,4 @@
Deface::Override.new(:virtual_path => "spree/products/_cart_form",
:replace => "[data-hook='product_price'] .add-to-cart",
:partial => "spree/products/add_to_cart",
:name => "product_add_to_cart")

View File

@@ -0,0 +1,12 @@
.add-to-cart
- if @product.has_stock? || Spree::Config[:allow_backorders]
%p Quantity
= number_field_tag (@product.has_variants? ? :quantity : "variants[#{@product.master.id}]"), 1, :class => 'title', :in => 1..@product.on_hand
%p Distributor
= select_tag "distributor_id", options_from_collection_for_select(@distributors, "id", "name", current_distributor.andand.id)
%br/
= button_tag :class => 'large primary', :id => 'add-to-cart-button', :type => :submit do
= t(:add_to_cart)
- else
= content_tag('strong', t(:out_of_stock))

View File

@@ -78,28 +78,21 @@ feature %q{
end
context "viewing a product, it provides a choice of distributor when adding to cart" do
it "displays the local distributor as the default choice when available for the current product"
it "functions with remote distributors"
it "displays the local distributor as the default choice when available for the current product" do
# Given a distributor and a product under it
distributor = create(:distributor)
product = create(:product, :distributors => [distributor])
# When we select the distributor and view the product
visit spree.root_path
click_link distributor.name
visit spree.product_path(product)
# Then we should see our distributor as the default option when adding the item to our cart
page.should have_selector "select#distributor_id option[value='#{distributor.id}'][selected='selected']"
end
it "functions with remote distributors also"
end
end
# scenario "browsing products by distributor" do
# # Given a product at each of two distributors
# d1 = create(:distributor)
# d2 = create(:distributor)
# p1 = create(:product, :distributors => [d1])
# p2 = create(:product, :distributors => [d2])
# # When I go to the home page, I should see both products
# visit spree.root_path
# page.should have_content p1.name
# page.should have_content p2.name
# # When I filter by one distributor, I should see only the product from that distributor
# click_link d1.name
# page.should have_content p1.name
# page.should_not have_content p2.name
# end
end