EVC - Product Module
by AaronLayton
JavaScript
// Product Module
function Product( values ){
values = values || {};
// Set default values
this.productid = values.productid || 0;
this.price = values.price || 0;
this.title = values.title || "";
this.description = values.description || "";
this.colours = values.colours || []; // Empty array
this.images = values.images || []; // Empty array
return this;
}
// Can extend product with useful functions
Product.prototype = {
addColour: function( colour ){
this.colours.push(colour);
},
hasColour: function( colour ){
if (jQuery.inArray(colour, this.colours) > -1){
return true;
}
return false;
}
};
// We can then create the product using a JSON string
var myProd = new Product({
title: "Plain Poplin Shirt",
productid: 0034036, /* may need to be a string value */
price: 20,
description: "A simple smart plain shirt is all you need to complement any good suit. Our cotton poplin shirt has a well proportioned classic point collar and single cuff. Designed to work with our selection of tonal and patterned ties. Available in three colours, White, Blue and Pink.",
colours: ['white', 'black'],
images: [
'http://www.racinggreen.co.uk/upload/siteimages/xl/0034036_010_A.jpg',
'http://www.racinggreen.co.uk/upload/siteimages/xl/0034036_010_D.jpg'
]
});