Fix ship_address_same_as_billing checkbox value with string

This commit is contained in:
Bing Xie
2016-08-18 15:29:16 +10:00
parent d59db1cd97
commit a6cfa061e4
6 changed files with 10 additions and 9 deletions

View File

@@ -9,9 +9,10 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu
for field in $scope.fieldsToBind
storage.bind $scope, "Checkout.order.#{field}",
storeName: "#{prefix}_#{field}"
storage.bind $scope, "Checkout.ship_address_same_as_billing",
storeName: "#{prefix}_sameasbilling"
defaultValue: true
defaultValue: 'YES'
$scope.order = Checkout.order # Ordering is important
$scope.secrets = Checkout.secrets

View File

@@ -3,7 +3,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
errors: {}
secrets: {}
order: CurrentOrder.order
ship_address_same_as_billing: true
ship_address_same_as_billing: 'YES'
submit: ->
Loading.message = t 'submitting_order'
@@ -33,7 +33,7 @@ Darkswarm.factory 'Checkout', (CurrentOrder, ShippingMethods, PaymentMethods, $h
else
# Ignore everything else
if @ship_address_same_as_billing
if @ship_address_same_as_billing == 'YES'
munged_order.ship_address_attributes = munged_order.bill_address_attributes
# If the order already has a ship and bill address (as with logged in users with
# past orders), and we don't remove id here, then this will set the wrong id for

View File

@@ -13,7 +13,7 @@
"ng-class" => "{valid: shipping.$valid, open: accordion.shipping}"}
= render 'checkout/accordion_heading'
.small-12.columns.medium-6.columns.large-6.columns
.small-12.columns
%label{"ng-repeat" => "method in ShippingMethods.shipping_methods"}
%input{type: :radio,
required: true,
@@ -30,7 +30,7 @@
= "{{ fieldErrors('order.shipping_method_id') }}"
%label{"ng-if" => "Checkout.requireShipAddress()"}
%input{type: :checkbox, "ng-model" => "Checkout.ship_address_same_as_billing"}
%input{type: :checkbox, "ng-model" => "Checkout.ship_address_same_as_billing", "ng-true-value" => "'YES'", "ng-false-value" => "'NO'"}
= t :checkout_address_same
.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"}
%div.visible{"ng-if" => "Checkout.ship_address_same_as_billing === 'NO'"}
.row
.small-6.columns
= validated_input "First Name", "order.ship_address.firstname", "ofn-focus" => "accordion['shipping']"

View File

@@ -62,7 +62,7 @@ describe "CheckoutCtrl", ->
console.log prefix
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: true})
expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: 'YES'})
it "it can retrieve data from localstorage", ->
prefix = "order_#{scope.order.id}#{CurrentUser.id or ""}#{CurrentHubMock.hub.id}"

View File

@@ -126,9 +126,9 @@ 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 = false
Checkout.ship_address_same_as_billing = 'NO'
expect(Checkout.preprocess().ship_address_attributes).toEqual(orderData.ship_address)
Checkout.ship_address_same_as_billing = true
Checkout.ship_address_same_as_billing = 'YES'
expect(Checkout.preprocess().ship_address_attributes).toEqual(orderData.bill_address)
it "creates attributes for card fields", ->