Skip to content
Open
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
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
Empty file modified Gruntfile.js
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified bower.json
100644 → 100755
Empty file.
312 changes: 165 additions & 147 deletions dist/ngCart.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,16 @@ angular.module('ngCart', ['ngCart.directives'])
};
};

this.addItem = function (id, name, price, quantity, data) {
this.addItem = function (id, name, price, quantity, maxqty, data) {

var inCart = this.getItemById(id);

if (typeof inCart === 'object'){
//Update quantity of an item if it's already in the cart
inCart.setQuantity(quantity, false);
inCart.setMaxQuantity(maxqty);
} else {
var newItem = new ngCartItem(id, name, price, quantity, data);
var newItem = new ngCartItem(id, name, price, quantity, maxqty, data);
this.$cart.items.push(newItem);
$rootScope.$broadcast('ngCart:itemAdded', newItem);
}
Expand Down Expand Up @@ -180,7 +181,7 @@ angular.module('ngCart', ['ngCart.directives'])
_self.$cart.tax = storedCart.tax;

angular.forEach(storedCart.items, function (item) {
_self.$cart.items.push(new ngCartItem(item._id, item._name, item._price, item._quantity, item._data));
_self.$cart.items.push(new ngCartItem(item._id, item._name, item._price, item._quantity, item._maxqty, item._data));
});
this.$save();
};
Expand All @@ -193,11 +194,12 @@ angular.module('ngCart', ['ngCart.directives'])

.factory('ngCartItem', ['$rootScope', '$log', function ($rootScope, $log) {

var item = function (id, name, price, quantity, data) {
var item = function (id, name, price, quantity, maxqty, data) {
this.setId(id);
this.setName(name);
this.setPrice(price);
this.setQuantity(quantity);
this.setMaxQuantity(maxqty);
this.setData(data);
};

Expand Down Expand Up @@ -261,10 +263,24 @@ angular.module('ngCart', ['ngCart.directives'])

};

item.prototype.setMaxQuantity = function(maxqty){
this._maxqty = maxqty;
};

item.prototype.getQuantity = function(){
return this._quantity;
};

item.prototype.getMaxQuantity = function(){
return this._maxqty;
};

item.prototype.getIsMaxQuantity = function(){
//console.log(this._maxqty+' '+this._quantity);
//console.log(this._maxqty);
return this._maxqty <= this._quantity;
};

item.prototype.setData = function(data){
if (data) this._data = data;
};
Expand Down Expand Up @@ -326,146 +342,148 @@ angular.module('ngCart', ['ngCart.directives'])
}])

.value('version', '0.0.3-rc.1');
;'use strict';


angular.module('ngCart.directives', ['ngCart.fulfilment'])

.controller('CartController',['$scope', 'ngCart', function($scope, ngCart) {
$scope.ngCart = ngCart;
}])

.directive('ngcartAddtocart', ['ngCart', function(ngCart){
return {
restrict : 'E',
controller : 'CartController',
scope: {
id:'@',
name:'@',
quantity:'@',
quantityMax:'@',
price:'@',
data:'='
},
transclude: true,
templateUrl: 'template/ngCart/addtocart.html',
link:function(scope, element, attrs){
scope.attrs = attrs;
scope.inCart = function(){
return ngCart.getItemById(attrs.id);
};

if (scope.inCart()){
scope.q = ngCart.getItemById(attrs.id).getQuantity();
} else {
scope.q = parseInt(scope.quantity);
}

scope.qtyOpt = [];
for (var i = 1; i <= scope.quantityMax; i++) {
scope.qtyOpt.push(i);
}

}

};
}])

.directive('ngcartCart', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
templateUrl: 'template/ngCart/cart.html',
link:function(scope, element, attrs){

}
};
}])

.directive('ngcartSummary', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
transclude: true,
templateUrl: 'template/ngCart/summary.html'
};
}])

.directive('ngcartCheckout', [function(){
return {
restrict : 'E',
controller : ('CartController', ['$scope', 'ngCart', 'fulfilmentProvider', function($scope, ngCart, fulfilmentProvider) {
$scope.ngCart = ngCart;

$scope.checkout = function () {
fulfilmentProvider.setService($scope.service);
fulfilmentProvider.setSettings($scope.settings);
var promise = fulfilmentProvider.checkout();
console.log(promise);
}
}]),
scope: {
service:'@',
settings:'='
},
transclude: true,
templateUrl: 'template/ngCart/checkout.html'
};
}]);;
angular.module('ngCart.fulfilment', [])
.service('fulfilmentProvider', ['$injector', function($injector){

this._obj = {
service : undefined,
settings : undefined
};

this.setService = function(service){
this._obj.service = service;
};

this.setSettings = function(settings){
this._obj.settings = settings;
};

this.checkout = function(){
var provider = $injector.get('ngCart.fulfilment.' + this._obj.service);
return provider.checkout(this._obj.settings);

}

}])


.service('ngCart.fulfilment.log', ['$q', '$log', 'ngCart', function($q, $log, ngCart){

this.checkout = function(){

var deferred = $q.defer();

$log.info(ngCart.toObject());
deferred.resolve({
cart:ngCart.toObject()
});

return deferred.promise;

}

}])

.service('ngCart.fulfilment.http', ['$http', 'ngCart', function($http, ngCart){

this.checkout = function(settings){
return $http.post(settings.url,
{data:ngCart.toObject()})
}
}])


.service('ngCart.fulfilment.paypal', ['$http', 'ngCart', function($http, ngCart){


}]);
;'use strict';


angular.module('ngCart.directives', ['ngCart.fulfilment'])

.controller('CartController',['$scope', 'ngCart', function($scope, ngCart) {
$scope.ngCart = ngCart;
}])

.directive('ngcartAddtocart', ['ngCart', function(ngCart){
return {
restrict : 'E',
controller : 'CartController',
scope: {
id:'@',
name:'@',
quantity:'@',
quantityMax:'@',
price:'@',
data:'='
},
transclude: true,
templateUrl: 'template/ngCart/addtocart.html',
link:function(scope, element, attrs){
scope.attrs = attrs;
scope.inCart = function(){
return ngCart.getItemById(attrs.id);
};

if (scope.inCart()){
// scope.q = ngCart.getItemById(attrs.id).getQuantity();
scope.q = parseInt(scope.quantity);
} else {
scope.q = parseInt(scope.quantity);
}

scope.qtyOpt = [];

for (var i = 1; i <= scope.quantityMax; i++) {
scope.qtyOpt.push(i);
}

}

};
}])

.directive('ngcartCart', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
templateUrl: 'template/ngCart/cart.html',
link:function(scope, element, attrs){

}
};
}])

.directive('ngcartSummary', [function(){
return {
restrict : 'E',
controller : 'CartController',
scope: {},
transclude: true,
templateUrl: 'template/ngCart/summary.html'
};
}])

.directive('ngcartCheckout', [function(){
return {
restrict : 'E',
controller : ('CartController', ['$scope', 'ngCart', 'fulfilmentProvider', function($scope, ngCart, fulfilmentProvider) {
$scope.ngCart = ngCart;

$scope.checkout = function () {
fulfilmentProvider.setService($scope.service);
fulfilmentProvider.setSettings($scope.settings);
var promise = fulfilmentProvider.checkout();
console.log(promise);
}
}]),
scope: {
service:'@',
settings:'='
},
transclude: true,
templateUrl: 'template/ngCart/checkout.html'
};
}]);;
angular.module('ngCart.fulfilment', [])
.service('fulfilmentProvider', ['$injector', function($injector){

this._obj = {
service : undefined,
settings : undefined
};

this.setService = function(service){
this._obj.service = service;
};

this.setSettings = function(settings){
this._obj.settings = settings;
};

this.checkout = function(){
var provider = $injector.get('ngCart.fulfilment.' + this._obj.service);
return provider.checkout(this._obj.settings);

}

}])


.service('ngCart.fulfilment.log', ['$q', '$log', 'ngCart', function($q, $log, ngCart){

this.checkout = function(){

var deferred = $q.defer();

$log.info(ngCart.toObject());
deferred.resolve({
cart:ngCart.toObject()
});

return deferred.promise;

}

}])

.service('ngCart.fulfilment.http', ['$http', 'ngCart', function($http, ngCart){

this.checkout = function(settings){
return $http.post(settings.url,
{data:ngCart.toObject()})
}
}])


.service('ngCart.fulfilment.paypal', ['$http', 'ngCart', function($http, ngCart){


}]);
Loading