From 773adca838931c945c3db35c1130bdbd1aa1e94e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Sat, 27 Oct 2012 12:49:57 +1100 Subject: [PATCH] Display distributor details on product page when distributor is selected --- .../stylesheets/store/openfoodweb.css.scss | 5 +++- .../add_distributor_details_to_product.rb | 2 +- app/views/distributors/_details.html.haml | 25 +++++++++++++++-- .../spree/checkout/_distributor.html.haml | 25 +---------------- .../products/_distributor_details.html.haml | 7 +++++ spec/requests/consumer/product_spec.rb | 28 ++++++++++++++++++- 6 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 app/views/spree/products/_distributor_details.html.haml diff --git a/app/assets/stylesheets/store/openfoodweb.css.scss b/app/assets/stylesheets/store/openfoodweb.css.scss index 06979bf3ea..fa4d16689f 100644 --- a/app/assets/stylesheets/store/openfoodweb.css.scss +++ b/app/assets/stylesheets/store/openfoodweb.css.scss @@ -145,8 +145,11 @@ ul.product-listing { /* Distributor details on product details page */ -#product-distributor-details { +fieldset#product-distributor-details { float: right; + margin-top: 0; + width: 250px; + @extend #shipping; } #product-variants { diff --git a/app/overrides/add_distributor_details_to_product.rb b/app/overrides/add_distributor_details_to_product.rb index b107869e19..6671ed40b5 100644 --- a/app/overrides/add_distributor_details_to_product.rb +++ b/app/overrides/add_distributor_details_to_product.rb @@ -1,4 +1,4 @@ Deface::Override.new(:virtual_path => "spree/products/show", :insert_before => "[data-hook='cart_form']", - :partial => "distributors/details", + :partial => "spree/products/distributor_details", :name => "product_distributor_details") diff --git a/app/views/distributors/_details.html.haml b/app/views/distributors/_details.html.haml index 6646588ef4..2a354be1db 100644 --- a/app/views/distributors/_details.html.haml +++ b/app/views/distributors/_details.html.haml @@ -1,2 +1,23 @@ -#product-distributor-details.columns.five.omega - When you select a distributor for your order, their address and pickup times will be displayed here. +%h2= distributor.name +%p + %strong Address: + %br/ + = render 'spree/shared/address', :address => distributor.pickup_address +%p + %strong Next collection time: + %br/ + = distributor.next_collection_at +%p + %strong Regular collection times: + %br/ + = distributor.pickup_times +%p + %strong Contact: + %br/ + = distributor.contact + %br/ + = "Phone: #{distributor.phone}" + %br/ + = "Email: #{distributor.email}" +%p= distributor.description +%p= link_to distributor.url, distributor.url if distributor.url diff --git a/app/views/spree/checkout/_distributor.html.haml b/app/views/spree/checkout/_distributor.html.haml index 9460e3a94b..b2eac11c71 100644 --- a/app/views/spree/checkout/_distributor.html.haml +++ b/app/views/spree/checkout/_distributor.html.haml @@ -1,27 +1,4 @@ .columns.omega.six %fieldset#shipping %legend Distributor - %h2= @order.distributor.name - %p - %strong Address: - %br/ - = render 'spree/shared/address', :address => @order.distributor.pickup_address - %p - %strong Next collection time: - %br/ - = @order.distributor.next_collection_at - %p - %strong Regular collection times: - %br/ - = @order.distributor.pickup_times - %p - %strong Contact: - %br/ - = @order.distributor.contact - %br/ - = "Phone: #{@order.distributor.phone}" - %br/ - = "Email: #{@order.distributor.email}" - %p= @order.distributor.description - %p= link_to @order.distributor.url, @order.distributor.url if @order.distributor.url - + = render 'distributors/details', :distributor => @order.distributor diff --git a/app/views/spree/products/_distributor_details.html.haml b/app/views/spree/products/_distributor_details.html.haml new file mode 100644 index 0000000000..808468f806 --- /dev/null +++ b/app/views/spree/products/_distributor_details.html.haml @@ -0,0 +1,7 @@ +%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. diff --git a/spec/requests/consumer/product_spec.rb b/spec/requests/consumer/product_spec.rb index 368452ab54..76a647d074 100644 --- a/spec/requests/consumer/product_spec.rb +++ b/spec/requests/consumer/product_spec.rb @@ -32,7 +32,33 @@ feature %q{ page.should have_selector '#product-distributor-details', :text => 'When you select a distributor for your order, their address and pickup times will be displayed here.' end - it "displays distributor details when one is selected" + it "displays distributor details when one is selected" do + d = create(:distributor) + p = create(:product, :distributors => [d]) + + visit spree.root_path + click_link d.name + visit spree.product_path p + + within '#product-distributor-details' do + [d.name, + d.pickup_address.address1, + d.pickup_address.city, + d.pickup_address.zipcode, + d.pickup_address.state_text, + d.pickup_address.country.name, + d.pickup_times, + d.next_collection_at, + d.contact, + d.phone, + d.email, + d.description, + d.url].each do |value| + + page.should have_content value + end + end + end end context "with Javascript" do