mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding the 'same as billing address' JS
This commit is contained in:
@@ -2,6 +2,7 @@ angular.module("Checkout").controller "CheckoutCtrl", ($scope, $rootScope) ->
|
||||
$scope.require_ship_address = false
|
||||
$scope.shipping_method = -1
|
||||
$scope.payment_method = -1
|
||||
$scope.same_as_billing = true
|
||||
|
||||
$scope.shippingMethodChanged = ->
|
||||
$scope.require_ship_address = $("#order_shipping_method_id_" + $scope.shipping_method).attr("data-require-ship-address")
|
||||
|
||||
@@ -21,20 +21,27 @@
|
||||
= f.fields_for :bill_address do |ba|
|
||||
.row
|
||||
.large-12.columns
|
||||
= ba.text_field :address1, label: "Billing Address"
|
||||
= ba.text_field :address1, label: "Billing Address",
|
||||
"ng-model" => "billing_address1"
|
||||
.row
|
||||
.large-12.columns
|
||||
= ba.text_field :address2
|
||||
= ba.text_field :address2,
|
||||
"ng-model" => "billing_address2"
|
||||
.row
|
||||
.large-6.columns
|
||||
= ba.text_field :city
|
||||
= ba.text_field :city,
|
||||
"ng-model" => "billing_city"
|
||||
|
||||
.large-6.columns
|
||||
= ba.select :country_id, Spree::Country.order(:name).select([:id, :name]).map{|c| [c.name, c.id]}
|
||||
= ba.select :country_id, Spree::Country.order(:name).select([:id, :name]).map{|c| [c.name, c.id]},
|
||||
"ng-model" => "billing_country_id"
|
||||
.row
|
||||
.large-6.columns
|
||||
= ba.select :state_id, Spree::State.order(:name).select([:id, :name]).map{|c| [c.name, c.id]}
|
||||
= ba.select :state_id, Spree::State.order(:name).select([:id, :name]).map{|c| [c.name, c.id]},
|
||||
"ng-model" => "billing_state_id"
|
||||
.large-6.columns.right
|
||||
= ba.text_field :zipcode
|
||||
= ba.text_field :zipcode,
|
||||
"ng-model" => "billing_zipcode"
|
||||
|
||||
%fieldset#shipping
|
||||
|
||||
@@ -52,26 +59,42 @@
|
||||
|
||||
= f.fields_for :ship_address do |sa|
|
||||
#ship_address{"ng-show" => "require_ship_address"}
|
||||
.row
|
||||
.large-12.columns
|
||||
= sa.text_field :address1
|
||||
.row
|
||||
.large-12.columns
|
||||
= sa.text_field :address2
|
||||
%label
|
||||
= check_box_tag :same_as_billing, true, true,
|
||||
"ng-model" => "same_as_billing"
|
||||
Shipping address same as billing address?
|
||||
|
||||
%div.visible{"ng-show" => "!same_as_billing"}
|
||||
.row
|
||||
.large-12.columns
|
||||
= sa.text_field :address1
|
||||
.row
|
||||
.large-12.columns
|
||||
= sa.text_field :address2
|
||||
|
||||
.row
|
||||
.large-6.columns
|
||||
= sa.text_field :city
|
||||
.large-6.columns
|
||||
= sa.select :country_id, Spree::Country.order(:name).select([:id, :name]).map{|c| [c.name, c.id]}
|
||||
.row
|
||||
.large-6.columns.right
|
||||
= sa.text_field :zipcode
|
||||
.row
|
||||
.large-6.columns
|
||||
= sa.text_field :firstname
|
||||
.large-6.columns
|
||||
= sa.text_field :lastname
|
||||
|
||||
#ship_address_hidden{"ng-show" => "same_as_billing"}
|
||||
= sa.hidden_field :address1, "ng-value" => "billing_address1"
|
||||
= sa.hidden_field :address2, "ng-value" => "billing_address2"
|
||||
= sa.hidden_field :city, "ng-value" => "billing_city"
|
||||
= sa.hidden_field :country_id, "ng-value" => "billing_country_id"
|
||||
= sa.hidden_field :zipcode, "ng-value" => "billing_zipcode"
|
||||
= sa.hidden_field :firstname, "ng-value" => "billing_firstname"
|
||||
= sa.hidden_field :lastname, "ng-value" => "billing_lastname"
|
||||
|
||||
.row
|
||||
.large-6.columns
|
||||
= sa.text_field :city
|
||||
.large-6.columns
|
||||
= sa.select :country_id, Spree::Country.order(:name).select([:id, :name]).map{|c| [c.name, c.id]}
|
||||
.row
|
||||
.large-6.columns.right
|
||||
= sa.text_field :zipcode
|
||||
.row
|
||||
.large-6.columns
|
||||
= sa.text_field :firstname
|
||||
.large-6.columns
|
||||
= sa.text_field :lastname
|
||||
%fieldset#payment
|
||||
%legend Payment Details
|
||||
- current_order.available_payment_methods.each do |method|
|
||||
|
||||
@@ -133,15 +133,35 @@ feature "As a consumer I want to check out my cart", js: true do
|
||||
page.should have_content "Donkeys"
|
||||
end
|
||||
|
||||
it "doesn't show ship address forms " do
|
||||
it "doesn't show ship address forms when a shipping method wants no address" do
|
||||
choose(sm2.name)
|
||||
find("#ship_address").visible?.should be_false
|
||||
end
|
||||
|
||||
it "shows ship address forms when selected shipping method requires one" do
|
||||
context "When shipping method requires an address" do
|
||||
before do
|
||||
choose(sm1.name)
|
||||
end
|
||||
it "shows the hidden ship address fields by default" do
|
||||
check "Shipping address same as billing address?"
|
||||
find("#ship_address_hidden").visible?.should be_true
|
||||
find("#ship_address > div.visible").visible?.should be_false
|
||||
end
|
||||
|
||||
it "shows ship address forms when 'same as billing address' is unchecked" do
|
||||
uncheck "Shipping address same as billing address?"
|
||||
find("#ship_address_hidden").visible?.should be_false
|
||||
find("#ship_address > div.visible").visible?.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
it "copies billing address to hidden shipping address fields" do
|
||||
choose(sm1.name)
|
||||
save_and_open_page
|
||||
find("#ship_address").visible?.should be_true
|
||||
check "Shipping address same as billing address?"
|
||||
fill_in "Billing Address", with: "testy"
|
||||
within "#ship_address_hidden" do
|
||||
find("#order_ship_address_attributes_address1").value.should == "testy"
|
||||
end
|
||||
end
|
||||
|
||||
describe "with payment methods" do
|
||||
|
||||
Reference in New Issue
Block a user