mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Update distributor details when distributor is changed
This commit is contained in:
@@ -10,6 +10,15 @@ $(document).ready(function() {
|
||||
|
||||
// Product page with master price only
|
||||
$(".add-to-cart input.title:not(#quantity):not(.max_quantity)").change(products_update_price_without_variant).change();
|
||||
|
||||
// Product page other
|
||||
$("#distributor_id").change(function() {
|
||||
var distributor_html = distributors[$(this).val()];
|
||||
if(!distributor_html) {
|
||||
distributor_html = 'When you select a distributor for your order, their address and pickup times will be displayed here.';
|
||||
}
|
||||
$("#product-distributor-details .distributor-details").html(distributor_html);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
class DistributorsController < BaseController
|
||||
def index
|
||||
@distributors = Distributor.all
|
||||
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
@distributor_details = Hash[@distributors.map { |d| [d.id, render_to_string(:partial => 'distributors/details', :locals => {:distributor => d})] }]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
options = {:distributor_id => params[:id]}
|
||||
options.merge(params.reject { |k,v| k == :id })
|
||||
|
||||
@@ -2,3 +2,8 @@ Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_before => "[data-hook='cart_form']",
|
||||
:partial => "spree/products/distributor_details",
|
||||
:name => "product_distributor_details")
|
||||
|
||||
Deface::Override.new(:virtual_path => "spree/products/show",
|
||||
:insert_after => "[data-hook='product_show']",
|
||||
:text => "<%= javascript_include_tag main_app.distributors_path(:format => :js) %>",
|
||||
:name => "product_distributor_details_js")
|
||||
|
||||
1
app/views/distributors/index.js.erb
Normal file
1
app/views/distributors/index.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
distributors = <%= @distributor_details.to_json.html_safe %>;
|
||||
@@ -1,7 +1,8 @@
|
||||
%fieldset#product-distributor-details.columns.five.omega
|
||||
%legend Distributor
|
||||
- order = current_order(false)
|
||||
- if order.andand.distributor.present?
|
||||
= render 'distributors/details', :distributor => order.distributor
|
||||
- else
|
||||
When you select a distributor for your order, their address and pickup times will be displayed here.
|
||||
.distributor-details
|
||||
- order = current_order(false)
|
||||
- if order.andand.distributor.present?
|
||||
= render 'distributors/details', :distributor => order.distributor
|
||||
- else
|
||||
When you select a distributor for your order, their address and pickup times will be displayed here.
|
||||
|
||||
@@ -61,10 +61,23 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
context "with Javascript" do
|
||||
it "changes distributor details when the distributor is changed"
|
||||
context "with Javascript", js: true do
|
||||
it "changes distributor details when the distributor is changed" do
|
||||
d1 = create(:distributor)
|
||||
d2 = create(:distributor)
|
||||
d3 = create(:distributor)
|
||||
p = create(:product, :distributors => [d1, d2, d3])
|
||||
|
||||
visit spree.product_path p
|
||||
|
||||
[d1, d2, d3].each do |d|
|
||||
select d.name, :from => 'distributor_id'
|
||||
|
||||
within '#product-distributor-details' do
|
||||
page.should have_selector 'h2', :text => d.name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user