function Product(id){ this.products_id = id; this.products_ids = new Array(); this.products_quantity = 0; this.products_quantitys = new Array(); this.products_model = ""; this.products_image = ""; this.products_price = 0; this.products_date_added = 0; this.products_last_modified = 0; this.products_date_available = 0; this.products_weight = 0; this.products_status = 0; this.products_statuss = new Array(); this.products_tax_class_id = 0; this.products_tax_class_ids = new Array(); this.manufacturers_id = 0; this.products_ordered = 0; this.products_attributes = new Array(); this.products_ordereds = new Array(); //vaste elementen this.classUrl = '/scripts/classes/Shop/Product.php'; this.orderBy = ''; this.productResults = new Array(); this.getProductsId = function(){ return this.products_id; } this.getId = function(){ return this.products_id; } this.setProductsId = function(val){ this.products_id = val; } //searcher this.setProductsIds = function(val){ this.products_ids.push(val); } this.resetProductsIds = function(){ this.products_ids = new Array(); } this.getProductsQuantity = function(){ return this.products_quantity; } this.setProductsQuantity = function(val){ this.products_quantity = val; } //searcher this.setProductsQuantitys = function(val){ this.products_quantitys.push(val); } this.resetProductsQuantitys = function(){ this.products_quantitys = new Array(); } this.getProductsModel = function(){ return this.products_model; } this.setProductsModel = function(val){ this.products_model = val; } this.getProductsImage = function(){ return this.products_image; } this.setProductsImage = function(val){ this.products_image = val; } this.getProductsPrice = function(){ return this.products_price; } this.setProductsPrice = function(val){ this.products_price = val; } this.getProductsDate_added = function(){ return this.products_date_added; } this.setProductsDate_added = function(val){ this.products_date_added = val; } this.getProductsLast_modified = function(){ return this.products_last_modified; } this.setProductsLast_modified = function(val){ this.products_last_modified = val; } this.getProductsDate_available = function(){ return this.products_date_available; } this.setProductsDate_available = function(val){ this.products_date_available = val; } this.getProductsWeight = function(){ return this.products_weight; } this.setProductsWeight = function(val){ this.products_weight = val; } this.getProductsStatus = function(){ return this.products_status; } this.setProductsStatus = function(val){ this.products_status = val; } this.setProductsAttributes = function(val){ this.products_attributes = val; } //searcher this.setProductsStatuss = function(val){ this.products_statuss.push(val); } this.resetProductsStatuss = function(){ this.products_statuss = new Array(); } this.getProductsTax_class_id = function(){ return this.products_tax_class_id; } this.setProductsTax_class_id = function(val){ this.products_tax_class_id = val; } //searcher this.setProductsTax_class_ids = function(val){ this.products_tax_class_ids.push(val); } this.resetProductsTax_class_ids = function(){ this.products_tax_class_ids = new Array(); } this.getManufacturersId = function(){ return this.manufacturers_id; } this.setManufacturersId = function(val){ this.manufacturers_id = val; } this.getProductsOrdered = function(){ return this.products_ordered; } this.setProductsOrdered = function(val){ this.products_ordered = val; } //extra this.pictureThumb1 = ""; this.getPictureThumb1 = function(){ var n = this.products_image.lastIndexOf("."); return "/images/"+this.products_image.substring(0,n)+".thumb"+this.products_image.substring(n); } this.setPictureThumb1 = function(val){ this.products_image = val; } this.load = function(func){ var t = this; var req = new XMLHttpRequest(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4 && (req.status == 200 || req.status == 304)) { var xml = req.responseXML; if (xml.documentElement) { t.loadXML(xml,0); if (typeof(func)=="function") func(); else if (typeof(func)=="string"){setTimeout(func,0);}; } } } } req.open('GET', this.classUrl+'?ac=load&products_id='+this.products_id+'&noCache='+new Date().getTime()); //asynchroon req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15'); req.send(null); } this.loadXML = function(xml,index){ var root = xml.getElementsByTagName('product')[index]; this.setProductsId(this.getNodeValue(root,'products_id')); this.setProductsQuantity(this.getNodeValue(root,'products_quantity')); this.setProductsModel(this.getNodeValue(root,'products_model')); this.setProductsImage(this.getNodeValue(root,'products_image')); this.setProductsPrice(this.getNodeValue(root,'products_price')); this.setProductsDate_added(this.getNodeValue(root,'products_date_added')); this.setProductsLast_modified(this.getNodeValue(root,'products_last_modified')); this.setProductsDate_available(this.getNodeValue(root,'products_date_available')); this.setProductsWeight(this.getNodeValue(root,'products_weight')); this.setProductsStatus(this.getNodeValue(root,'products_status')); this.setProductsTax_class_id(this.getNodeValue(root,'products_tax_class_id')); this.setManufacturersId(this.getNodeValue(root,'manufacturers_id')); this.setProductsOrdered(this.getNodeValue(root,'products_ordered')); } this.updateQuantity = function(quantity){ var t = this, req = new XMLHttpRequest(), params = "&id="+this.products_id+"&quantity="+quantity, attr_ids = 0; if (typeof this.products_attributes != 'undefined' && this.products_attributes != null) this.products_attributes.forEach(function(a){ attr_ids += ","+a.attr_id; }); params+="&attr_ids="+attr_ids; req.open('GET', this.classUrl+'?ac=updateQuantity'+params+'&noCache='+new Date().getTime()); //asynchroon req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15'); req.send(null); }; this.verkoopToPrice = function(vk,func){ var t = this; var req = new XMLHttpRequest(); if (req) { req.onreadystatechange = function() { if (req.readyState == 4 && (req.status == 200 || req.status == 304)) { var xml = req.responseXML; if (xml.documentElement) { var root = xml.getElementsByTagName('product')[0]; t.setVerkoopprijs(t.getNodeValue(root,'verkoopprijs')); if (typeof(func)=="function") func(); } } } } req.open('GET', this.classUrl+'?ac=verkoopToPrice&vk='+vk+'&noCache='+new Date().getTime()); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-15'); req.send(null); }; this.escape = function(str){ return escape(str).replace(/\+/gi,'%2B');} this.getNodeValue = function (el,name){ if (el.getElementsByTagName(name)[0].firstChild == null) return ''; else return el.getElementsByTagName(name)[0].firstChild.nodeValue; } }