HEX
Server: Apache
System: Linux v38079.2is.nl 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64
User: democfellows (10015)
PHP: 8.1.34
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/creativefellows.nl/test.creativefellows.nl/mysteryrun/public/js/app.js
$(document).foundation().ready(function(){
		
	// open external links in new window
	$(document.links).filter(function() {
	  return this.hostname != window.location.hostname;
	}).attr('target', '_blank');
	
	$(".shopping-cart").shoppingCart();	
		
});


$.fn.shoppingCart = function(){
	
	return this.each(function(){

		var cart		= $(this);
		var removeItem  = cart.find("a.delete");
		var amounts		= cart.find("select.change-amount");
		
		cart.init = function()
		{	
			
			removeItem.on("click",cart.removeFromBasket);
			amounts.on("change",cart.updateAmount);
			
		}
		
		
		cart.updateAmount = function()
		{
			var row 	= $(this).closest(".item");
			var uid		= cart.getUid( $(this) );
			var price	= cart.getPrice( $(this) );
			var amount 	= $(this).val();
			
			$.ajax({
			    dataType: "json",
				type: 'PATCH',
			    url: "winkelwagen",
			    data: {
			    	uid: uid,
					amount: amount
			    },
			    success: function(json)
				{				
					cart.updateTotals(json);
					cart.updateRow(row,amount,price);
			    }
			});
		
		}
		
		cart.updateRow = function(row,amount,price)
		{
			row.find(".product-total").html( cart.formatPrice((amount * price)) );
		}
		
		
		cart.formatPrice = function(number,sign)
		{
			return (sign === true ? "€ " : "" ) + number.toFixed(2).replace(".",",");
		}
		
		cart.getUid = function(element)
		{
			return element.closest(".item").attr("data-uid");
		}
		
		
		cart.getPrice = function(element)
		{
			return element.closest(".item").attr("data-price");
			
		}
		
		
		cart.removeFromBasket = function()
		{
			var product = $(this)
			var uid 	= product.attr("data-id");
			
			$.ajax({
			    dataType: "json",
				type: 'DELETE',
			    url: "winkelwagen",
			    data: {
			    	uid: uid
			    },
			    success: function(json)
				{				
					cart.deleteRow(product);
					cart.updateTotals(json);
			    }
			});
			
		}
		
		
		cart.updateTotals = function(total)
		{
						
			$("#cart-subtotal").text(total.subtotal);
			$("#cart-delivery").text(total.delivery);
			$("#cart-total").html("€ " + total.total);
			$("#cart-tax").html("€ " + total.tax);
			
		}
		
		
		cart.deleteRow = function(product)
		{
			product.closest(".item").slideUp();
		}
		
				
		// init the plugin
	    cart.init();
		
		
	});
}