From e0e566e6251a66349c2c6ef69ee5b2ecd71f3cd4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 26 Jun 2012 16:04:59 +1000 Subject: [PATCH] Display distributor information on checkout address page --- app/models/spree/distributor.rb | 2 +- app/models/spree/supplier.rb | 2 +- app/overrides/replace_delivery_address.rb | 3 +- .../spree/admin/distributors/show.html.haml | 2 +- .../spree/admin/suppliers/show.html.haml | 2 +- .../spree/checkout/_distributor.html.haml | 24 ++++- .../{admin => }/shared/_address.html.haml | 0 spec/factories.rb | 1 + spec/requests/consumer/checkout_spec.rb | 90 ++++++++++--------- 9 files changed, 74 insertions(+), 52 deletions(-) rename app/views/spree/{admin => }/shared/_address.html.haml (100%) diff --git a/app/models/spree/distributor.rb b/app/models/spree/distributor.rb index e9759cc542..95fc31c027 100644 --- a/app/models/spree/distributor.rb +++ b/app/models/spree/distributor.rb @@ -17,7 +17,7 @@ module Spree def initialize_country self.pickup_address ||= Address.new - self.pickup_address.country = Country.find_by_id(Spree::Config[:default_country_id]) + self.pickup_address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.pickup_address.new_record? end def set_unused_address_fields diff --git a/app/models/spree/supplier.rb b/app/models/spree/supplier.rb index 20ebcaf609..6831e2aa6b 100644 --- a/app/models/spree/supplier.rb +++ b/app/models/spree/supplier.rb @@ -14,7 +14,7 @@ module Spree def initialize_country self.address ||= Address.new - self.address.country = Country.find_by_id(Spree::Config[:default_country_id]) + self.address.country = Country.find_by_id(Spree::Config[:default_country_id]) if self.address.new_record? end def set_unused_address_fields diff --git a/app/overrides/replace_delivery_address.rb b/app/overrides/replace_delivery_address.rb index 362e217bc0..2b13785b1c 100644 --- a/app/overrides/replace_delivery_address.rb +++ b/app/overrides/replace_delivery_address.rb @@ -1,5 +1,4 @@ Deface::Override.new(:virtual_path => "spree/checkout/_address", :replace => "[data-hook='shipping_fieldset_wrapper']", :partial => "spree/checkout/distributor", - :name => "drop_off_point") - + :name => "delivery_address") diff --git a/app/views/spree/admin/distributors/show.html.haml b/app/views/spree/admin/distributors/show.html.haml index 9ba1aa4326..f5837abb15 100644 --- a/app/views/spree/admin/distributors/show.html.haml +++ b/app/views/spree/admin/distributors/show.html.haml @@ -17,7 +17,7 @@ %td= @distributor.email %tr %th Pickup address: - %td= render 'spree/admin/shared/address', :address => @distributor.pickup_address + %td= render 'spree/shared/address', :address => @distributor.pickup_address %tr %th Pickup times: %td= @distributor.pickup_times diff --git a/app/views/spree/admin/suppliers/show.html.haml b/app/views/spree/admin/suppliers/show.html.haml index 3c939ad2cd..b659dbff02 100644 --- a/app/views/spree/admin/suppliers/show.html.haml +++ b/app/views/spree/admin/suppliers/show.html.haml @@ -8,7 +8,7 @@ %td= @supplier.description %tr %th Address: - %td= render 'spree/admin/shared/address', :address => @supplier.address + %td= render 'spree/shared/address', :address => @supplier.address %tr %th Email: %td= @supplier.email diff --git a/app/views/spree/checkout/_distributor.html.haml b/app/views/spree/checkout/_distributor.html.haml index 93f0c71956..d8a87f35cc 100644 --- a/app/views/spree/checkout/_distributor.html.haml +++ b/app/views/spree/checkout/_distributor.html.haml @@ -1,5 +1,23 @@ .columns.omega.six - %fieldset{:id => 'shipping'} - %legend Collection Point - =form.collection_select("distributor_id", Spree::Distributor.all, :id, :name, {}, {:class => 'required'}) + %fieldset#shipping + %legend Distributor + %h2= @order.distributor.name + %p + %strong Address: + %br/ + = render 'spree/shared/address', :address => @order.distributor.pickup_address + %p + %strong Pickup 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 diff --git a/app/views/spree/admin/shared/_address.html.haml b/app/views/spree/shared/_address.html.haml similarity index 100% rename from app/views/spree/admin/shared/_address.html.haml rename to app/views/spree/shared/_address.html.haml diff --git a/spec/factories.rb b/spec/factories.rb index c0edc0ae6f..df9b9bdf72 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -15,6 +15,7 @@ FactoryGirl.define do phone "1000100100" description 'The creator' email 'alan@somewhere.com' + url 'http://example.com' pickup_times "Whenever you're free" pickup_address { Spree::Address.first || FactoryGirl.create(:address) } end diff --git a/spec/requests/consumer/checkout_spec.rb b/spec/requests/consumer/checkout_spec.rb index 1c588dcb2d..091dad8118 100644 --- a/spec/requests/consumer/checkout_spec.rb +++ b/spec/requests/consumer/checkout_spec.rb @@ -9,62 +9,66 @@ feature %q{ include WebHelper background do - @distributor1 = create(:distributor, :name => 'Eaterprises') - @distributor2 = create(:distributor, :name => 'Edible garden', - :pickup_address => '12 Bungee Rd', - :city => 'Carion', + @distributor = create(:distributor, :name => 'Edible garden', + :pickup_address => create(:address, :address1 => '12 Bungee Rd', :city => 'Carion'), :pickup_times => 'Tuesday, 4 PM') - @product = create(:product, :name => 'Fuji apples') + @product = create(:product, :name => 'Fuji apples', :distributors => [@distributor]) @zone = create(:zone) - create(:zone_member, zone: @zone, zoneable: Spree::Country.find_by_name('Australia')) create(:shipping_method, zone: @zone) create(:payment_method) end - context "Given I am buying a product", :js => true do - scenario "I should be able choose a distributor to pick up from", :skip => true do - login_to_consumer_section - click_link 'Fuji apples' - click_button 'Add To Cart' - click_link 'Checkout' + scenario "buying a product", :js => true do + login_to_consumer_section - fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', - 'order_bill_address_attributes_lastname' => 'Luck', - 'order_bill_address_attributes_address1' => '19 Sycamore Lane', - 'order_bill_address_attributes_city' => 'Horse Hill', - 'order_bill_address_attributes_zipcode' => '3213', - 'order_bill_address_attributes_phone' => '12999911111') + click_link 'Fuji apples' + click_button 'Add To Cart' + click_link 'Checkout' + fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', + 'order_bill_address_attributes_lastname' => 'Luck', + 'order_bill_address_attributes_address1' => '19 Sycamore Lane', + 'order_bill_address_attributes_city' => 'Horse Hill', + 'order_bill_address_attributes_zipcode' => '3213', + 'order_bill_address_attributes_phone' => '12999911111') - select('Australia', :from => 'order_bill_address_attributes_country_id') - select('Victoria', :from => 'order_bill_address_attributes_state_id') + select('Australia', :from => 'order_bill_address_attributes_country_id') + select('Victoria', :from => 'order_bill_address_attributes_state_id') - select('Edible garden', :from => 'order_distributor_id') + within('fieldset#shipping') do + [@distributor.name, + @distributor.pickup_address.address1, + @distributor.pickup_address.city, + @distributor.pickup_address.zipcode, + @distributor.pickup_address.state_text, + @distributor.pickup_address.country.name, + @distributor.pickup_times, + @distributor.contact, + @distributor.phone, + @distributor.email, + @distributor.description, + @distributor.url].each do |value| - # within('.distributor-details') do - # page.should have_content('12 Bungee Rd') - # page.should have_content('Carion') - # page.should have_content('Tuesday, 4 PM') - # end - - click_button 'Save and Continue' - #display delivery details? - - click_button 'Save and Continue' - fill_in 'card_number', :with => '4111111111111111' - select('1', :from => 'payment_source_1_month') - select("#{DateTime.now.year + 1}", :from => 'payment_source_1_year') - fill_in 'card_code', :with => '234' - - click_button 'Save and Continue' - - page.should have_content('Your order has been processed successfully') - # page.should have_content('Your order will be available on:') - # page.should have_content('On Tuesday, 4 PM') - # page.should have_content('12 Bungee Rd, Carion') + page.should have_content value + end end - end + click_button 'Save and Continue' + #display delivery details? + + click_button 'Save and Continue' + fill_in 'card_number', :with => '4111111111111111' + select('1', :from => 'payment_source_1_month') + select("#{DateTime.now.year + 1}", :from => 'payment_source_1_year') + fill_in 'card_code', :with => '234' + + click_button 'Save and Continue' + + page.should have_content('Your order has been processed successfully') + # page.should have_content('Your order will be available on:') + # page.should have_content('On Tuesday, 4 PM') + # page.should have_content('12 Bungee Rd, Carion') + end end