mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Display distributor choice on add to cart form
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
4
app/overrides/add_distributor_to_add_to_cart_form.rb
Normal file
4
app/overrides/add_distributor_to_add_to_cart_form.rb
Normal 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")
|
||||
12
app/views/spree/products/_add_to_cart.html.haml
Normal file
12
app/views/spree/products/_add_to_cart.html.haml
Normal 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))
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user