Using true/false instead of YES/NO for address defaults and billing same as shipping

This commit is contained in:
Rob Harrington
2016-09-21 12:08:26 +10:00
committed by Bing Xie
parent 720ca17533
commit b59a1cc232
8 changed files with 23 additions and 23 deletions

View File

@@ -12,15 +12,15 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu
storage.bind $scope, "Checkout.ship_address_same_as_billing",
storeName: "#{prefix}_sameasbilling"
defaultValue: 'YES'
defaultValue: true
storage.bind $scope, "Checkout.default_bill_address",
storeName: "#{prefix}_defaultasbilladdress"
defaultValue: 'NO'
defaultValue: false
storage.bind $scope, "Checkout.default_ship_address",
storeName: "#{prefix}_defaultasshipaddress"
defaultValue: 'NO'
defaultValue: false
$scope.order = Checkout.order # Ordering is important
$scope.secrets = Checkout.secrets

View File

@@ -3,9 +3,9 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
errors: {}
secrets: {}
order: CurrentOrder.order
ship_address_same_as_billing: 'YES'
default_bill_address: 'NO'
default_ship_address: 'NO'
ship_address_same_as_billing: true
default_bill_address: false
default_ship_address: false
submit: ->
Loading.message = t 'submitting_order'

View File

@@ -62,7 +62,7 @@ class CheckoutController < Spree::CheckoutController
private
def set_default_bill_address
if params[:order][:default_bill_address] == 'YES'
if params[:order][:default_bill_address]
new_bill_address = @order.bill_address.clone.attributes
user_bill_address_id = spree_current_user.bill_address.andand.id
@@ -75,7 +75,7 @@ class CheckoutController < Spree::CheckoutController
end
def set_default_ship_address
if params[:order][:default_ship_address] == 'YES'
if params[:order][:default_ship_address]
new_ship_address = @order.ship_address.clone.attributes
user_ship_address_id = spree_current_user.ship_address.andand.id

View File

@@ -16,7 +16,7 @@
- if spree_current_user
.small-12.columns
%label
%input{type: :checkbox, "ng-model" => "Checkout.default_bill_address", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
%input{type: :checkbox, "ng-model" => "Checkout.default_bill_address"}
= t :checkout_default_bill_address
= f.fields_for :bill_address, @order.bill_address do |ba|

View File

@@ -30,12 +30,12 @@
= "{{ fieldErrors('order.shipping_method_id') }}"
%label{"ng-if" => "Checkout.requireShipAddress()"}
%input{type: :checkbox, "ng-model" => "Checkout.ship_address_same_as_billing", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
%input{type: :checkbox, "ng-model" => "Checkout.ship_address_same_as_billing"}
= t :checkout_address_same
- if spree_current_user
%label{"ng-if" => "Checkout.requireShipAddress()"}
%input{type: :checkbox, "ng-model" => "Checkout.default_ship_address", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
%input{type: :checkbox, "ng-model" => "Checkout.default_ship_address"}
= t :checkout_default_ship_address
.small-12.columns.medium-6.columns.large-6.columns

View File

@@ -1,6 +1,6 @@
.small-12.columns
#ship_address{"ng-if" => "Checkout.requireShipAddress()"}
%div.visible{"ng-if" => "Checkout.ship_address_same_as_billing === 'NO'"}
%div.visible{"ng-if" => "!Checkout.ship_address_same_as_billing"}
.row
.small-6.columns
= validated_input "First Name", "order.ship_address.firstname", "ofn-focus" => "accordion['shipping']"

View File

@@ -62,9 +62,9 @@ describe "CheckoutCtrl", ->
field = scope.fieldsToBind[0]
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", {storeName: "#{prefix}_#{field}"})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: 'YES'})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_bill_address", {storeName: "#{prefix}_defaultasbilladdress", defaultValue: 'NO'})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_ship_address", {storeName: "#{prefix}_defaultasshipaddress", defaultValue: 'NO'})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_bill_address", {storeName: "#{prefix}_defaultasbilladdress", defaultValue: false})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.default_ship_address", {storeName: "#{prefix}_defaultasshipaddress", defaultValue: false})
it "it can retrieve data from localstorage", ->

View File

@@ -126,20 +126,20 @@ describe 'Checkout service', ->
expect(Checkout.preprocess().ship_address).toBe(undefined)
it "munges the order attributes to clone ship address from bill address", ->
Checkout.ship_address_same_as_billing = 'NO'
Checkout.ship_address_same_as_billing = false
expect(Checkout.preprocess().ship_address_attributes).toEqual(orderData.ship_address)
Checkout.ship_address_same_as_billing = 'YES'
Checkout.ship_address_same_as_billing = true
expect(Checkout.preprocess().ship_address_attributes).toEqual(orderData.bill_address)
it "munges the default as billing address and shipping address", ->
expect(Checkout.preprocess().default_bill_address).toEqual('NO')
expect(Checkout.preprocess().default_ship_address).toEqual('NO')
expect(Checkout.preprocess().default_bill_address).toEqual(false)
expect(Checkout.preprocess().default_ship_address).toEqual(false)
Checkout.default_bill_address = 'YES'
Checkout.default_ship_address = 'YES'
Checkout.default_bill_address = true
Checkout.default_ship_address = true
expect(Checkout.preprocess().default_bill_address).toEqual('YES')
expect(Checkout.preprocess().default_ship_address).toEqual('YES')
expect(Checkout.preprocess().default_bill_address).toEqual(true)
expect(Checkout.preprocess().default_ship_address).toEqual(true)
it "creates attributes for card fields", ->
source_attributes = Checkout.preprocess().payments_attributes[0].source_attributes