Adding tests and views to handle changing shipping prices

This commit is contained in:
Will Marshall
2014-03-14 12:59:37 +11:00
parent dc95d764fe
commit fc4f108724
5 changed files with 59 additions and 9 deletions

View File

@@ -2,19 +2,25 @@ angular.module("Checkout").controller "CheckoutCtrl", ($scope, $rootScope, order
$scope.require_ship_address = false
$scope.order = order
$scope.initialize = ->
# Our shipping_methods comes through as a hash like so: {id: requires_shipping_address}
# Here we default to the first shipping method if none is selected
$scope.order.shipping_method_id ||= Object.keys(order.shipping_methods)[0]
$scope.order.ship_address_same_as_billing = true if $scope.order.ship_address_same_as_billing == null
$scope.shippingMethodChanged()
# Our shipping_methods comes through as a hash like so: {id: requires_shipping_address}
# Here we default to the first shipping method if none is selected
$scope.order.shipping_method_id ||= Object.keys(order.shipping_methods)[0]
$scope.order.ship_address_same_as_billing = true if $scope.order.ship_address_same_as_billing == null
$scope.shippingPrice = ->
$scope.shippingMethod().price
$scope.shippingMethod = ->
$scope.order.shipping_methods[$scope.order.shipping_method_id]
$scope.require_ship_address = $scope.order.shipping_methods[$scope.order.shipping_method_id]
$scope.shippingMethodChanged = ->
$scope.require_ship_address = $scope.order.shipping_methods[$scope.order.shipping_method_id]
$scope.require_ship_address = $scope.shippingMethod().require_ship_address
$scope.purchase = (event)->
event.preventDefault()
checkout.submit()
$scope.initialize()