mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding tests and views to handle changing shipping prices
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
:javascript
|
||||
angular.module('Checkout').value('order', #{render "shop/checkout/order"})
|
||||
|
||||
-#%pre
|
||||
-#{{ order | json }}
|
||||
|
||||
.large-12.columns
|
||||
%fieldset#details
|
||||
%legend Customer Details
|
||||
|
||||
@@ -15,5 +15,10 @@ end
|
||||
|
||||
# Format here is {id: require_ship_address}
|
||||
node :shipping_methods do
|
||||
Hash[current_order.distributor.shipping_methods.collect { |method| [method.id, method.require_ship_address] }]
|
||||
Hash[current_order.distributor.shipping_methods.collect {
|
||||
|method| [method.id, {
|
||||
require_ship_address: method.require_ship_address,
|
||||
price: method.compute_amount(current_order)
|
||||
}]
|
||||
}]
|
||||
end
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
%tr
|
||||
%th= adjustment.label
|
||||
%td= adjustment.display_amount.to_html
|
||||
%tr
|
||||
%th Shipping cost
|
||||
%td {{ shippingPrice() | currency }}
|
||||
%tr
|
||||
%th Cart total
|
||||
%td= current_order.display_total.to_html
|
||||
|
||||
@@ -46,3 +46,36 @@ describe 'All controllers', ->
|
||||
scope = {}
|
||||
ctrl = $controller 'OrderCycleCtrl', {$scope: scope}
|
||||
|
||||
describe "CheckoutCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
order = null
|
||||
|
||||
beforeEach ->
|
||||
module("Checkout")
|
||||
order =
|
||||
id: 3102
|
||||
shipping_method_id: "7"
|
||||
ship_address_same_as_billing: true
|
||||
payment_method_id: null
|
||||
shipping_methods:
|
||||
7:
|
||||
require_ship_address: true
|
||||
price: 0.0
|
||||
|
||||
25:
|
||||
require_ship_address: false
|
||||
price: 13
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'CheckoutCtrl', {$scope: scope, order: order}
|
||||
|
||||
|
||||
it 'Gets the ship address automatically', ->
|
||||
expect(scope.require_ship_address).toEqual true
|
||||
|
||||
it 'Gets the current shipping price', ->
|
||||
expect(scope.shippingPrice()).toEqual 0.0
|
||||
scope.order.shipping_method_id = 25
|
||||
expect(scope.shippingPrice()).toEqual 13
|
||||
|
||||
|
||||
Reference in New Issue
Block a user