File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/wwwroot/js/app/checkout/discountModule.ng.js
define([], function()
{
var app = angular.module('discountModule', []);
app.controller('discountBarController', ['$scope','$timeout', function($scope, $timeout){
var carrousel_discounts =[];
//only use the discounts that whre in_carrousel ==1
for(var i in $scope.product.getData().discounts){
if($scope.product.getData().discounts[i].in_carrousel ==1) carrousel_discounts[i]= $scope.product.getData().discounts[i];
};
var getNextDiscount = function(){
var nextDiscount = {};
var highestDiscount = {};
highestDiscount.quantity_min = 0
for(var i in carrousel_discounts){
var discount = carrousel_discounts[i];
var currentNextMin = nextDiscount.quantity_min ? nextDiscount.quantity_min : 9999999;
if(
(discount.quantity_min > $scope.product.getQuantity()) &&
(discount.quantity_min < currentNextMin)
)
{
nextDiscount = discount;
}
if(discount.quantity_min > highestDiscount.quantity_min){
highestDiscount = discount
}
}
if(!nextDiscount.quantity_min){
return highestDiscount
}
return nextDiscount;
};
var getCurrentDiscount = function($number){
var nextDiscount = {};
for(var i in carrousel_discounts){
var discount = carrousel_discounts[i];
var currentNextMin = nextDiscount.quantity_min ? nextDiscount.quantity_min : 9999999;
if(
(discount.quantity_min > $number-1) &&
(discount.quantity_min < currentNextMin)
)
{
nextDiscount = discount;
}
}
return nextDiscount;
};
var $this = this;
$this.discountText = '';
$this.quant = $scope.product.getQuantity();
$scope.nextDiscount = getNextDiscount();
$scope.$watch('product._quantity', function(quantity){
$this.quant = parseInt(quantity);
$scope.nextDiscount = getNextDiscount();
if(Object.keys($scope.nextDiscount).length > 0){
$this.discountText = $scope.formatDiscount($scope.nextDiscount);
}
});
$scope.glowTimer = function(){
$scope.$parent.product.shortGlow='short-glow';
$timeout(function(){$scope.$parent.product.shortGlow='';}, 1000)
}
$scope.formatCurrentDiscount = function($number){
return $scope.formatDiscount(getCurrentDiscount($number));
}
$scope.formatDiscount = function(nextDiscount){
var nextDiscountString = String(nextDiscount.next_discount_description);
if(! nextDiscount.next_discount_description)
nextDiscountString = $scope.product.getData().discounts[0].default_next_discount_description; // Tops sepecifiek
// nextDiscountString = '';
nextDiscountString = nextDiscountString.replace(':quantity', Math.ceil(($this.quant + 1) / 10) * 10);
nextDiscountString = nextDiscountString.replace(':free', Math.ceil(($this.quant + 1) / 10));
return nextDiscountString;
};
}]);
app.controller('discountBarItemController', ['$scope', 'translationsService', function($scope, translationsService){
var $this = this;
this.discount = $scope.discount;
$scope.activeDiscountItem = false;
this.displayDiscount = function(){
if(this.discount.discount_percentage) return this.discount.discount_percentage + '%';
if(this.discount.discount_fraction) return '+' + this.discount.discount_fraction + ' ' + translationsService.get('cart.free');
if(this.discount.discount_absolute) return '- €' + (this.discount.discount_absolute / 100) + '';
};
$scope.isActive = function(){
var quant = $scope.product.getQuantity();
return (quant >= ($this.discount.quantity_min ? $this.discount.quantity_min : 0));/* &&
(quant <= ($this.discount.quantity_max ? $this.discount.quantity_max : 999999));*/
// De balk moet blijven branden
};
}]);
return app;
});