function daProduct(element){ var self = this; self.element = element; //self.errorblock = ''; self.serialiseObject = function(element){ responseobject = {}; data = $(element).serializeArray(); $(data).each(function(i , field){ if(typeof(field) === 'object'){ responseobject[field.name] = field.value; } }); return responseobject; } self.getPrice = function(){ var data = self.serialiseObject($(self.element)); $.ajax('/ajaxgetprice' , { 'data': data , 'dataType': 'json' , 'success': function(response){ if(typeof(response.price) != 'undefined' && response.price) { $(self.element).find('.productprice').text(response.price_formatted_inc); $(self.element).find('.productprice-ex').text(response.price_formatted); $(self.element).find('.productprice-original').text(response.price_no_discount_formatted_inc); $(self.element).find('.addtocartbtn').css('display' , ''); $(self.element).find('.getpricebtn').css('display' , 'none'); $(self.element).find('.productprice').css('display' , ''); $(self.element).find('.producterrors').css('display' , 'none'); // ajax returns both quantity discounted price and non quantity discounted price // display the quantity discount price - use non quantity discount price to calculate unit prices // non-quantity discounted price should not have vouchers applied either // update volume discounts table var $unitPrice, currency, multiplier; $(self.element).find('.volume-discounts tbody tr').each(function() { $unitPrice = $(this).find('.unit-price'); // remove everything except the currency currency = $unitPrice.text().replace(/[0-9.]/g, ''); // get this row's multiplier value multiplier = $(this).attr('data-multiplier'); // update this row's html $unitPrice.html(currency += parseFloat(response.price_no_discount_inc * multiplier).toFixed(2)); }); } else if(typeof(response.errors) == 'object'){ $(self.element).find('.addtocartbtn').css('display' , 'none'); $(self.element).find('.productprice').css('display' , 'none'); self.displayErrors(response.errors); } } , 'error': function() { } }); } self.displayErrors = function(errors){ $(self.element).find('.producterrorcontent').html(''); $(self.element).find('.producterrors').css('display' , ''); $(errors).each(function(index , item){ $(self.element).find('.producterrorcontent').append('