Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app/addPromotion/addPromotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function AddPromotionComponentCtrl($exceptionHandler, $rootScope, OrderCloud, to
OrderCloud.Orders.AddPromotion(orderID, promoCode)
.then(function(promo) {
$rootScope.$broadcast('OC:UpdatePromotions', orderID);
$rootScope.$broadcast('OC:UpdateOrder', orderID);
toastr.success('Promo code '+ promo.Code + ' added!', 'Success');
})
.catch(function(err) {
Expand Down
5 changes: 1 addition & 4 deletions src/app/app.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ function AppController($q, $rootScope, $state, $ocMedia, toastr, LoginService, a
$rootScope.$on('$stateChangeStart', function(e, toState) {
cleanLoadingIndicators();
var defer = $q.defer();
//defer.delay = 200;
defer.wrapperClass = 'indicator-container';
(toState.data && toState.data.loadingMessage) ? defer.message = toState.data.loadingMessage : defer.message = null;
defer.templateUrl = 'common/templates/view.loading.tpl.html';
if (toState.data) defer.message = toState.data.loadingMessage;
vm.stateLoading = defer;
});

Expand Down
7 changes: 5 additions & 2 deletions src/app/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ function BaseController($rootScope, $state, ProductSearch, CurrentUser, CurrentO
});
};

$rootScope.$on('OC:UpdateOrder', function(event, OrderID) {
OrderCloud.Orders.Get(OrderID)
$rootScope.$on('OC:UpdateOrder', function(event, OrderID, message) {
vm.orderLoading = {
message: message
};
vm.orderLoading.promise = OrderCloud.Orders.Get(OrderID)
.then(function(data) {
vm.currentOrder = data;
});
Expand Down
31 changes: 12 additions & 19 deletions src/app/cart/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,25 @@ function CartConfig($stateProvider) {
});
}

function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsList, CurrentPromotions, ocConfirm) {
function CartController($rootScope, $state, toastr, OrderCloud, LineItemsList, CurrentPromotions, ocConfirm) {
var vm = this;
vm.lineItems = LineItemsList;
vm.promotions = CurrentPromotions.Meta ? CurrentPromotions.Items : CurrentPromotions;

vm.updateQuantity = function(order, lineItem) {
ocLineItems.UpdateQuantity(order, lineItem);
};

vm.removeItem = function(order, lineItem) {
ocLineItems.RemoveItem(order, lineItem);
vm.removeItem = function(order, scope) {
vm.lineLoading = [];
vm.lineLoading[scope.$index] = OrderCloud.LineItems.Delete(order.ID, scope.lineItem.ID)
.then(function () {
$rootScope.$broadcast('OC:UpdateOrder', order.ID);
vm.lineItems.Items.splice(scope.$index, 1);
toastr.success('Line Item Removed');
});
};

//TODO: missing unit tests
vm.removePromotion = function(order, scope) {
OrderCloud.Orders.RemovePromotion(order.ID, scope.promotion.Code)
.then(function() {
$rootScope.$broadcast('OC:UpdateOrder', order.ID);
vm.promotions.splice(scope.$index, 1);
});
};
Expand All @@ -72,16 +75,7 @@ function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsLi
});
};

$rootScope.$on('OC:UpdateLineItem', function(event,Order) {
OrderCloud.LineItems.List(Order.ID)
.then(function(data) {
ocLineItems.GetProductInfo(data.Items)
.then(function() {
vm.lineItems = data;
});
});
});

//TODO: missing unit tests
$rootScope.$on('OC:UpdatePromotions', function(event, orderid) {
OrderCloud.Orders.ListPromotions(orderid)
.then(function(data) {
Expand All @@ -90,7 +84,6 @@ function CartController($rootScope, $state, OrderCloud, ocLineItems, LineItemsLi
} else {
vm.promotions = data;
}
$rootScope.$broadcast('OC:UpdateOrder', orderid);
});
});
}
8 changes: 4 additions & 4 deletions src/app/cart/templates/cart.tpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h3>
<div class="well text-center" ng-if="!cart.lineItems.Items.length">You do not have any items in your cart.</div>
<div class="row" ng-if="cart.lineItems.Items.length">
<aside class="col-md-4 col-md-push-8">
<div class="panel panel-default" hl-sticky anchor="top" offset-top="70" media-query="min-width: 992px">
<div class="panel panel-default" hl-sticky anchor="top" offset-top="70" media-query="min-width: 992px" cg-busy="base.orderLoading">
<div class="panel-heading">
<h3 class="panel-title">
Order Summary
Expand Down Expand Up @@ -58,7 +58,7 @@ <h5 ng-repeat="promotion in cart.promotions" class="text-danger">
<hr>
</div>
</div>
<div class="row c-line-item" ng-repeat="lineItem in cart.lineItems.Items track by $index">
<div class="row c-line-item" ng-repeat="lineItem in cart.lineItems.Items track by $index" cg-busy="cart.lineLoading[$index]">
<div class="col-xs-3 col-sm-2">
<div class="thumbnail c-line-item__img">
<img class="img-responsive" ng-src="{{lineItem.xp.image.URL || 'http://placehold.it/100x100?text=' + lineItem.Product.Name}}"
Expand Down Expand Up @@ -86,15 +86,15 @@ <h4 class="c-line-item__price text-right">{{lineItem.UnitPrice | currency}}</h4>
</div>
<div class="col-xs-4">
<div class="c-line-item__qty-input">
<oc-quantity-input lineitem="lineItem" order="base.currentOrder" update-fn="cart.updateQuantity"></oc-quantity-input>
<oc-quantity-input lineitem="lineItem" order="base.currentOrder"></oc-quantity-input>
</div>
</div>
<div class="col-xs-3">
<h4 class="c-line-item__total text-right">{{lineItem.LineTotal | currency}}</h4>
</div>
<div class="col-xs-2">
<div class="c-line-item__remove text-right">
<button class="btn btn-xs btn-danger" ng-click="cart.removeItem(base.currentOrder, lineItem)"><span class=""><i class="fa fa-close"></i></span></button>
<button class="btn btn-xs btn-danger" type="button" ng-click="cart.removeItem(base.currentOrder, this)"><span class=""><i class="fa fa-close"></i></span></button>
</div>
</div>
</div>
Expand Down
85 changes: 42 additions & 43 deletions src/app/cart/test/cart.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ describe('Component: Cart', function() {
q,
oc,
currentOrder,
currentPromotions,
lineItemHelpers,
rootScope,
lineItemsList,
_ocLineItems,
fakeOrder,
user
;
Expand All @@ -14,12 +14,13 @@ describe('Component: Cart', function() {
beforeEach(module(function($provide) {
$provide.value('CurrentOrder', {ID: "MockOrderID3456"});
}));
beforeEach(inject(function($rootScope, $q, OrderCloud, CurrentOrder, ocLineItems) {
beforeEach(inject(function($rootScope, $q, OrderCloud, ocLineItems, CurrentOrder) {
scope = $rootScope.$new();
q = $q;
oc = OrderCloud;
_ocLineItems = ocLineItems;
currentOrder = CurrentOrder;
lineItemHelpers = ocLineItems;
rootScope = $rootScope;
fakeOrder = {
ID: "TestOrder123456789",
Type: "Standard",
Expand All @@ -33,15 +34,15 @@ describe('Component: Cart', function() {
ShippingCost: null,
TaxCost: null
};
lineItemsList = {
"Items" : [{}, {}],
lineItemsList = {
"Items" : [{ID:"LI1"}, {ID:"LI2"}],
"Meta" : {
"Page": 1,
"PageSize": 20,
"TotalCount":29,
"TotalPages": 3,
"ItemRange" : [1,2]
}
}
};
user = {
ID: "TestUser132456789",
Expand All @@ -54,14 +55,14 @@ describe('Component: Cart', function() {
};
}));

describe('Configuration: CartConfig', function() {
describe('State: Cart', function() {
var state;
beforeEach(inject(function($state) {
state = $state.get('cart');
var defer = q.defer();
defer.resolve(lineItemsList);
spyOn(oc.LineItems,'List').and.returnValue(defer.promise);
spyOn(lineItemHelpers,'GetProductInfo').and.returnValue(defer.promise);
spyOn(_ocLineItems,'GetProductInfo').and.returnValue(defer.promise);

}));
it('should call LineItems.List',inject(function($injector){
Expand All @@ -71,7 +72,7 @@ describe('Component: Cart', function() {
it('should call LineItemHelper', inject(function($injector){
$injector.invoke(state.resolve.LineItemsList);
scope.$digest();
expect(lineItemHelpers.GetProductInfo).toHaveBeenCalled();
expect(_ocLineItems.GetProductInfo).toHaveBeenCalled();
}));
});

Expand All @@ -82,47 +83,45 @@ describe('Component: Cart', function() {
cartController = $controller('CartCtrl', {
$scope: scope,
CurrentPromotions: [],
LineItemsList: lineItemsList,
ocLineItems: lineItemHelpers
LineItemsList: lineItemsList
});
confirm = ocConfirm;
var defer = q.defer();
defer.resolve(lineItemsList);
spyOn(lineItemHelpers,'UpdateQuantity').and.returnValue(defer.promise);
spyOn(confirm,'Confirm').and.returnValue(defer.promise);
spyOn(oc.Orders, 'Delete').and.returnValue(defer.promise);
spyOn(oc.Orders,'Get').and.returnValue(defer.promise);
spyOn(oc.LineItems, 'List').and.returnValue(defer.promise);
spyOn(lineItemHelpers,'GetProductInfo').and.returnValue(defer.promise);
spyOn(rootScope, '$broadcast');
}));

describe('updateQuantity',function(){
it('should call ocLineItems UpdateQuantity Method', function(){
cartController.updateQuantity(currentOrder,lineItemsList.Items[0]);
expect(lineItemHelpers.UpdateQuantity).toHaveBeenCalledWith(currentOrder,lineItemsList.Items[0]);
}) ;
});
describe('CancelOrder',function() {
it('should call OrderCloud Confirm modal prompt', function() {
cartController.cancelOrder();
expect(confirm.Confirm).toHaveBeenCalled();
});
it('should call OC Orders Delete Method', function(){
cartController.cancelOrder(fakeOrder);
scope.$digest();
expect(oc.Orders.Delete).toHaveBeenCalledWith(fakeOrder.ID);
});
describe('removeItem()', function() {
beforeEach(function() {
var df = q.defer();
df.resolve();
spyOn(oc.LineItems, 'Delete').and.returnValue(df.promise);
});
it ('should delete the line item', function() {
cartController.removeItem(fakeOrder, {$index:0, lineItem: lineItemsList.Items[0]});
expect(oc.LineItems.Delete).toHaveBeenCalledWith(fakeOrder.ID, lineItemsList.Items[0].ID);
scope.$digest();
expect(rootScope.$broadcast).toHaveBeenCalledWith('OC:UpdateOrder', fakeOrder.ID);
expect(cartController.lineItems.Items).toEqual([{ID:"LI2"}]);
})
});
describe('OC:UpdateLineItem',function() {
it('should call LineItems List Method', inject(function($rootScope) {
$rootScope.$broadcast('OC:UpdateLineItem' ,fakeOrder);
expect(oc.LineItems.List).toHaveBeenCalledWith(fakeOrder.ID);
}));
it('should call ocLineItems GetProductInfo Method', inject(function($rootScope) {
$rootScope.$broadcast('OC:UpdateLineItem' ,fakeOrder);

describe('CancelOrder',function() {
beforeEach(function() {
var df = q.defer();
df.resolve();
spyOn(confirm,'Confirm').and.returnValue(df.promise);
spyOn(oc.Orders, 'Delete').and.returnValue(df.promise);
});
it('should call OrderCloud Confirm modal prompt', function() {
cartController.cancelOrder();
expect(confirm.Confirm).toHaveBeenCalled();
});
it('should call OC Orders Delete Method', function(){
cartController.cancelOrder(fakeOrder);
scope.$digest();
expect(oc.LineItems.List).toHaveBeenCalledWith(fakeOrder.ID);
}))
expect(oc.Orders.Delete).toHaveBeenCalledWith(fakeOrder.ID);
});
});
});
});
13 changes: 2 additions & 11 deletions src/app/checkout/payment/directives/payment.directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,7 @@ function PaymentSpendingAccountController($scope, $rootScope, toastr, OrderCloud
$scope.updatePayment = function(scope) {
var oldSelection = angular.copy($scope.payment.SpendingAccountID);
$scope.payment.SpendingAccountID = scope.spendingAccount.ID;

$scope.updatingSpendingAccountPayment = {
templateUrl: 'common/templates/view.loading.tpl.html',
message:null
};
$scope.updatingSpendingAccountPayment.promise = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment)
$scope.updatingSpendingAccountPayment = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment)
.then(function() {
$scope.showPaymentOptions = false;
toastr.success('Using ' + scope.spendingAccount.Name,'Spending Account Payment');
Expand Down Expand Up @@ -225,11 +220,7 @@ function PaymentCreditCardController($scope, $rootScope, toastr, $filter, OrderC
$scope.updatePayment = function(scope) {
var oldSelection = angular.copy($scope.payment.CreditCardID);
$scope.payment.CreditCardID = scope.creditCard.ID;
$scope.updatingCreditCardPayment = {
templateUrl: 'common/templates/view.loading.tpl.html',
message:null
};
$scope.updatingCreditCardPayment.promise = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment)
$scope.updatingCreditCardPayment = OrderCloud.Payments.Update($scope.order.ID, $scope.payment.ID, $scope.payment)
.then(function() {
$scope.showPaymentOptions = false;
toastr.success('Using ' + $filter('humanize')(scope.creditCard.CardType) + ' ending in ' + scope.creditCard.PartialAccountNumber,'Credit Card Payment');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div ng-form="OC_Checkout_Shipping" ng-init="checkoutShipping.initShippingRates(base.currentOrder)">
<div class="row">
<div class="col-md-8">
<div cg-busy="{promise:checkoutShipping.shippersLoading, templateUrl:'common/templates/view.loading.tpl.html', message:'Loading Shipping Rates'}">
<div cg-busy="{promise:checkoutShipping.shippersLoading, message:'Loading Shipping Rates'}">
<a href="" class="pull-right" ng-click="checkoutShipping.createAddress(base.currentOrder)"><i class="fa fa-plus-circle"></i> New Address</a>
<h4>Delivery Address</h4>
<div class="panel panel-default" ng-if="checkout.shippingAddress">
Expand Down
9 changes: 9 additions & 0 deletions src/app/common/config/angular-busy.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
angular.module('orderCloud')
.config(function(angularBusyDefaults) {
angular.extend(angularBusyDefaults, {
templateUrl:'common/templates/view.loading.tpl.html',
message:null,
wrapperClass: 'indicator-container'
})
})
;
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ angular.module('orderCloud')

;

function OCQuantityInput(toastr) {
function OCQuantityInput(toastr, OrderCloud, $rootScope) {
return {
scope: {
product: '=',
lineitem: '=',
label: '@',
order: '=',
updateFn: '='
order: '='
},
templateUrl: 'productDetail/quantityInput/templates/quantityInput.tpl.html',
templateUrl: 'common/templates/quantityInput.tpl.html',
replace: true,
link: function (scope) {
if (scope.product){
Expand All @@ -21,7 +20,18 @@ function OCQuantityInput(toastr) {
}
else if(scope.lineitem){
scope.item = scope.lineitem;
scope.content = "lineitem"
scope.content = "lineitem";
scope.updateQuantity = function() {
console.log('hit');
if (scope.item.Quantity > 0) {
OrderCloud.LineItems.Patch(scope.order.ID, scope.item.ID, {Quantity: scope.item.Quantity})
.then(function () {
toastr.success('Quantity Updated');
$rootScope.$broadcast('OC:UpdateOrder', scope.order.ID, 'Calculating Order Total');

});
}
}
}
else{
toastr.error('Please input either a product or lineitem attribute in the directive','Error');
Expand Down
Loading