From 25916caeb4e4309d048f0cbb175190ea15e3cfa4 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 13 Feb 2014 16:13:50 +1100 Subject: [PATCH] Starting on Angular models for Checkout, pretties --- .../javascripts/darkswarm/checkout.js.coffee | 2 + .../controllers/checkout_controller.js.coffee | 2 + .../stylesheets/darkswarm/forms.css.sass | 16 ++ .../stylesheets/darkswarm/variables.css.sass | 1 + app/views/shop/checkout/_form.html.haml | 151 ++++++++++-------- app/views/shop/checkout/_login.html.haml | 25 +-- app/views/shop/checkout/_signup.html.haml | 23 +-- app/views/shop/checkout/new.html.haml | 17 +- db/schema.rb | 8 +- .../consumer/shopping/checkout_spec.rb | 35 ++++ 10 files changed, 179 insertions(+), 101 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/checkout.js.coffee create mode 100644 app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee create mode 100644 app/assets/stylesheets/darkswarm/forms.css.sass diff --git a/app/assets/javascripts/darkswarm/checkout.js.coffee b/app/assets/javascripts/darkswarm/checkout.js.coffee new file mode 100644 index 0000000000..65bd062d5d --- /dev/null +++ b/app/assets/javascripts/darkswarm/checkout.js.coffee @@ -0,0 +1,2 @@ +window.Checkout = angular.module("Checkout", ["ngResource", "filters"]).config ($httpProvider) -> + $httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') diff --git a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee new file mode 100644 index 0000000000..b2df025a13 --- /dev/null +++ b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee @@ -0,0 +1,2 @@ +angular.module("Checkout").controller "CheckoutCtrl", ($scope, $rootScope) -> + $scope.require_ship_method = false diff --git a/app/assets/stylesheets/darkswarm/forms.css.sass b/app/assets/stylesheets/darkswarm/forms.css.sass new file mode 100644 index 0000000000..bada1fb68d --- /dev/null +++ b/app/assets/stylesheets/darkswarm/forms.css.sass @@ -0,0 +1,16 @@ +@import variables + +form + fieldset + padding: 0px + border: none + legend + border: 1px solid $dark-grey + border-left: 0px + border-right: 0px + padding: 16px 24px + display: block + width: 100% + margin-bottom: 1em + text-transform: uppercase + color: #999999 diff --git a/app/assets/stylesheets/darkswarm/variables.css.sass b/app/assets/stylesheets/darkswarm/variables.css.sass index a13eb9d014..c8edbc4a46 100644 --- a/app/assets/stylesheets/darkswarm/variables.css.sass +++ b/app/assets/stylesheets/darkswarm/variables.css.sass @@ -1 +1,2 @@ $fawn: #f6efe5 +$dark-grey: #c7c7c7 diff --git a/app/views/shop/checkout/_form.html.haml b/app/views/shop/checkout/_form.html.haml index f175b1c84e..e3b998d530 100644 --- a/app/views/shop/checkout/_form.html.haml +++ b/app/views/shop/checkout/_form.html.haml @@ -1,76 +1,89 @@ -= form_for @order, url: "test" do |f| - .large-8.columns - %fieldset#details - %legend Customer Details - .row - .large-6.columns - = f.label :email, "Email Address" - = f.text_field :email - = f.fields_for @order.bill_address do |ba| - .large-6.columns - = ba.label :phone - = ba.text_field :phone - = f.fields_for @order.bill_address do |ba| +%checkout{"ng-app" => "Checkout", "ng-controller" => "CheckoutCtrl"} + = form_for @order, url: "test", html: { class: "custom" } do |f| + .large-8.columns + %fieldset#details + %legend Customer Details .row .large-6.columns - = ba.label :firstname - = ba.text_field :firstname - .large-6.columns - = ba.label :lastname - = ba.text_field :lastname - - %fieldset - %legend Billing Address + = f.label :email, "Email Address" + = f.text_field :email + = f.fields_for @order.bill_address do |ba| + .large-6.columns + = ba.label :phone + = ba.text_field :phone = f.fields_for @order.bill_address do |ba| - .row - .large-12.columns - = ba.label :address1 - = ba.text_field :address1 - .row - .large-12.columns - = ba.label :address2 - = ba.text_field :address2 .row .large-6.columns - = ba.label :city - = ba.text_field :city + = ba.label :firstname + = ba.text_field :firstname .large-6.columns - = ba.label :country - = ba.text_field :country - .row - .large-6.columns.right - = ba.label :zipcode - = ba.text_field :zipcode - %fieldset#shipping - %legend Shipping - = fields_for @order.ship_address do |sa| - .row - .large-12.columns - = sa.label :address1 - = sa.text_field :address1 - .row - .large-12.columns - = sa.label :address2 - = sa.text_field :address2 + = ba.label :lastname + = ba.text_field :lastname - .row - .large-6.columns - = sa.label :city - = sa.text_field :city - .large-6.columns - = sa.label :country - = sa.text_field :country - .row - .large-6.columns.right - = sa.label :zipcode - = sa.text_field :zipcode - .row - .large-6.columns - = sa.label :firstname - = sa.text_field :firstname - .large-6.columns - = sa.label :lastname - = sa.text_field :lastname - %fieldset#payment - %legend Payment Details - This looks complicated :/ + %fieldset + %legend Billing Address + = f.fields_for @order.bill_address do |ba| + .row + .large-12.columns + = ba.label :address1 + = ba.text_field :address1 + .row + .large-12.columns + = ba.label :address2 + = ba.text_field :address2 + .row + .large-6.columns + = ba.label :city + = ba.text_field :city + .large-6.columns + = ba.label :country + = ba.text_field :country + .row + .large-6.columns.right + = ba.label :zipcode + = ba.text_field :zipcode + + %fieldset#shipping + %legend Shipping + + - for ship_method in current_distributor.shipping_methods.uniq + .row + .large-12.columns + %label + = f.radio_button :shipping_method, ship_method.id, + "data-require-ship-address" => ship_method.require_ship_address + %span.custom.radio + = ship_method.name + + = fields_for @order.ship_address do |sa| + #ship_address{"ng-show" => "require_ship_method"} + .row + .large-12.columns + = sa.label :address1 + = sa.text_field :address1 + .row + .large-12.columns + = sa.label :address2 + = sa.text_field :address2 + + .row + .large-6.columns + = sa.label :city + = sa.text_field :city + .large-6.columns + = sa.label :country + = sa.text_field :country + .row + .large-6.columns.right + = sa.label :zipcode + = sa.text_field :zipcode + .row + .large-6.columns + = sa.label :firstname + = sa.text_field :firstname + .large-6.columns + = sa.label :lastname + = sa.text_field :lastname + %fieldset#payment + %legend Payment Details + This looks complicated :/ diff --git a/app/views/shop/checkout/_login.html.haml b/app/views/shop/checkout/_login.html.haml index 4509a9dea7..33bf41fed5 100644 --- a/app/views/shop/checkout/_login.html.haml +++ b/app/views/shop/checkout/_login.html.haml @@ -1,13 +1,14 @@ -%h2 Login = form_for Spree::User.new, :html => {'data-type' => :json}, :as => :spree_user, :url => spree.spree_user_session_path do |f| - %p - = f.label :email, t(:email) - = f.email_field :email, :class => 'title', :tabindex => 1, :id => "login_spree_user_email" - %p - = f.label :password, t(:password) - = f.password_field :password, :class => 'title', :tabindex => 2, :id => "login_spree_user_password" - %p - %label - = f.check_box :remember_me - = f.label :remember_me, t(:remember_me) - %p= f.submit t(:login), :class => 'button primary', :tabindex => 3, :id => "login_spree_user_remember_me" + %fieldset + %legend I have an OFN Account + %p + = f.label :email, t(:email) + = f.email_field :email, :class => 'title', :tabindex => 1, :id => "login_spree_user_email" + %p + = f.label :password, t(:password) + = f.password_field :password, :class => 'title', :tabindex => 2, :id => "login_spree_user_password" + %p + %label + = f.check_box :remember_me + = f.label :remember_me, t(:remember_me) + %p= f.submit t(:login), :class => 'button primary', :tabindex => 3, :id => "login_spree_user_remember_me" diff --git a/app/views/shop/checkout/_signup.html.haml b/app/views/shop/checkout/_signup.html.haml index 51b8265f19..81ed7744d0 100644 --- a/app/views/shop/checkout/_signup.html.haml +++ b/app/views/shop/checkout/_signup.html.haml @@ -1,13 +1,14 @@ -%h2 Sign Up = form_for Spree::User.new, :as => :spree_user, :url => spree.spree_user_registration_path(@spree_user) do |f| - %p - = f.label :email, t(:email) - = f.email_field :email, :class => 'title', :id => "signup_spree_user_email" - %p - = f.label :password, t(:password) - = f.password_field :password, :class => 'title', :id => "signup_spree_user_password" - %p - = f.label :password_confirmation, t(:confirm_password) - = f.password_field :password_confirmation, :class => 'title', :id => "signup_spree_user_password_confirmation" + %fieldset + %legend New to OFN? + %p + = f.label :email, t(:email) + = f.email_field :email, :class => 'title', :id => "signup_spree_user_email" + %p + = f.label :password, t(:password) + = f.password_field :password, :class => 'title', :id => "signup_spree_user_password" + %p + = f.label :password_confirmation, t(:confirm_password) + = f.password_field :password_confirmation, :class => 'title', :id => "signup_spree_user_password_confirmation" - = f.submit "Sign Up", :class => 'button' + = f.submit "Sign Up", :class => 'button' diff --git a/app/views/shop/checkout/new.html.haml b/app/views/shop/checkout/new.html.haml index b3f9e0a264..97a582309d 100644 --- a/app/views/shop/checkout/new.html.haml +++ b/app/views/shop/checkout/new.html.haml @@ -1,9 +1,14 @@ - unless spree_current_user - %section#checkout_login - = render partial: "shop/checkout/login" - %section#checkout_signup - = render partial: "shop/checkout/signup" + .row + %section#checkout_login + .large-4.columns + = render partial: "shop/checkout/login" + %section#checkout_signup + .large-4.columns + = render partial: "shop/checkout/signup" + .large-2.columns + Cart bitches! -= render partial: "shop/checkout/form" - +.row + = render partial: "shop/checkout/form" diff --git a/db/schema.rb b/db/schema.rb index 313c7ddf48..b9f151fedf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140204011203) do +ActiveRecord::Schema.define(:version => 20140213003443) do create_table "adjustment_metadata", :force => true do |t| t.integer "adjustment_id" @@ -744,14 +744,16 @@ ActiveRecord::Schema.define(:version => 20140204011203) do create_table "spree_shipping_methods", :force => true do |t| t.string "name" t.integer "zone_id" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "display_on" t.integer "shipping_category_id" t.boolean "match_none" t.boolean "match_all" t.boolean "match_one" t.datetime "deleted_at" + t.boolean "require_ship_address", :default => true + t.text "description" end create_table "spree_skrill_transactions", :force => true do |t| diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index 8cf331db8e..336a35b790 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -108,6 +108,40 @@ feature "As a consumer I want to check out my cart", js: true do end end end + + describe "logged in, distributor selected, order cycle selected, product in cart" do + let(:user) { create_enterprise_user } + before do + login_to_consumer_section + select_distributor + select_order_cycle + add_product_to_cart + end + + describe "with shipping methods" do + let(:sm1) { create(:shipping_method, require_ship_address: true, name: "Frogs", description: "yellow") } + let(:sm2) { create(:shipping_method, require_ship_address: true, name: "Donkeys", description: "blue") } + before do + distributor.shipping_methods << sm1 + distributor.shipping_methods << sm2 + visit "/shop/checkout" + end + it "shows all shipping methods" do + page.should have_content "Frogs" + page.should have_content "Donkeys" + end + + it "doesn't show ship address forms by default" do + find("#ship_address").visible?.should be_false + end + + it "shows ship address forms when selected shipping method requires one" do + # Fancy Foundation Forms are weird + find("#order_shipping_method_#{sm1.id} + span").click + find("#ship_address").visible?.should be_true + end + end + end end def select_distributor @@ -122,6 +156,7 @@ def select_order_cycle end def add_product_to_cart + fill_in "variants[#{product.master.id}]", with: 5 first("form.custom > input.button.right").click end