mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-15 04:14:24 +00:00
Adding some SUPER clever magic and fixing some regression issues
This commit is contained in:
@@ -1,32 +1,10 @@
|
||||
Darkswarm.controller "CheckoutCtrl", ($scope, $rootScope, order) ->
|
||||
Darkswarm.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()
|
||||
|
||||
$scope.shippingPrice = ->
|
||||
$scope.shippingMethod().price
|
||||
|
||||
$scope.cartTotal = ->
|
||||
$scope.shippingPrice() + $scope.order.display_total
|
||||
|
||||
$scope.shippingMethod = ->
|
||||
$scope.order.shipping_methods[$scope.order.shipping_method_id]
|
||||
|
||||
$scope.paymentMethod = ->
|
||||
$scope.order.payment_methods[$scope.order.payment_method_id]
|
||||
$scope.order = $scope.Order = Order
|
||||
|
||||
$scope.shippingMethodChanged = ->
|
||||
$scope.require_ship_address = $scope.shippingMethod().require_ship_address if $scope.shippingMethod()
|
||||
Order.shippingMethodChanged()
|
||||
|
||||
$scope.purchase = (event)->
|
||||
event.preventDefault()
|
||||
checkout.submit()
|
||||
|
||||
$scope.initialize()
|
||||
|
||||
|
||||
32
app/assets/javascripts/darkswarm/services/order.js.coffee
Normal file
32
app/assets/javascripts/darkswarm/services/order.js.coffee
Normal file
@@ -0,0 +1,32 @@
|
||||
Darkswarm.factory 'Order', ($resource, Product, order)->
|
||||
|
||||
## I am being clever here
|
||||
## order is a JSON object generated in shop/checkout/order.rabl
|
||||
## We're extending this to add methods while retaining the data!
|
||||
|
||||
new class Order
|
||||
constructor: ->
|
||||
@[name] = method for name, method of order # Clone all data from the order JSON object
|
||||
|
||||
# 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
|
||||
@shipping_method_id ||= Object.keys(@shipping_methods)[0]
|
||||
@ship_address_same_as_billing = true if @ship_address_same_as_billing == null
|
||||
@shippingMethodChanged()
|
||||
|
||||
shippingMethod: ->
|
||||
@shipping_methods[@shipping_method_id]
|
||||
|
||||
shippingMethodChanged: =>
|
||||
@require_ship_address = @shippingMethod().require_ship_address if @shippingMethod()
|
||||
|
||||
shippingPrice: ->
|
||||
@shippingMethod().price
|
||||
|
||||
paymentMethod: ->
|
||||
@payment_methods[@payment_method_id]
|
||||
|
||||
|
||||
cartTotal: ->
|
||||
@shippingPrice() + @display_total
|
||||
|
||||
Reference in New Issue
Block a user