From 7d0fdead7acf0b7e962d68f19f2c9f98ab94bb0b Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 5 Mar 2014 15:49:47 +1100 Subject: [PATCH] Refactoring the way we default shipping_method_id --- .../controllers/checkout_controller.js.coffee | 5 +++++ app/views/shop/checkout/_order.rabl | 10 +--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee index e9b01863d4..9d5e4802ae 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout_controller.js.coffee @@ -5,6 +5,11 @@ angular.module("Checkout").controller "CheckoutCtrl", ($scope, $rootScope, order $scope.same_as_billing = true $scope.order = order + + # 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.require_ship_address = $scope.order.shipping_methods[$scope.order.shipping_method_id] $scope.shippingMethodChanged = -> diff --git a/app/views/shop/checkout/_order.rabl b/app/views/shop/checkout/_order.rabl index 723f7ca8b2..746743db47 100644 --- a/app/views/shop/checkout/_order.rabl +++ b/app/views/shop/checkout/_order.rabl @@ -1,13 +1,5 @@ object current_order -attributes :id, :email - -# Default to the first shipping method if none selected -# We don't want to do this on the order, BUT -# We can't set checked="checked" as Angular ignores it -# So we default the value in the JSON representation of the order -node :shipping_method_id do - current_order.shipping_method_id || current_order.distributor.shipping_methods.first.andand.id -end +attributes :id, :email, :shipping_method_id child current_order.bill_address => :bill_address do attributes :phone, :firstname, :lastname, :address1, :address2, :city, :country_id, :state_id, :zipcode