How to... > Shopping cart
This functionality hasn't been tested for Evolution 8 yet!
With this script you can show information about the contents of the shopping cart on, for example the home page of your website. It shows the number of products in the cart, the price, the percentage and the amount of VAT and the total amount of the items in the cart. It does not show the shipping costs because that can only be calculated when a customer places the order and chooses a shipping method.
It could look something like:
To use the script add a HTML-object anywhere on the page. Edit this HTML-object and copy/paste the following script in it.
<script type="text/javascript" src="res/x5cart.js"></script>
<script type="text/javascript" src="res/x5products.js"></script>
<script type="text/javascript">
// Funtion to report the status of the shoppingcart
function ReportCart() {
// Load the WX5 shoppingcartsystem
imCLoad();
// Constant values. Change to suit your language
// or pull appropriate values from Language.ini
var strProducts="products";
var strSubtotal="Subtotal";
var strVAT = "VAT";
var strTotal = imLocale["TotalVAT"];
var strEmpty = imLocale["Err_EmptyCart"];
var strGoToCart = "Go to your Shoppingcart";
// Variables which are used for the calculatins
var sBuf = ""; // outputbuffer
var iNumberOfProducts=0; // for counting the number of products
var iTotal = 0; // for calculating the total of the order
var fVAT = 0;
// Load the shopingcartfunction.
sCart = imGetCookie("imOrder");
// split the contents of the shoppingcart into an array.
if(sCart != null && sCart != "" ) {
aCart = sCart.split("|");
}
else {
aCart = new Array();
}
// If the cart is empty show 'EmptyCart'.
// This is defined in the languagedefinition.
// Otherwise count the number of ordered articles
// and calculate the total orderprice (ex shipment and VAT.
if(aCart.length == 0) {
sBuf += strEmpty;
}
else {
for ( var i = 0; i < aCart.length; i++) {
aCartProd = aCart[i].split(":");
aProd = imCGetProduct(aCartProd[0],aCartProd[1]);
iNumberOfProducts += Number(aCartProd[2]);
iTotal += aProd[4]*aCartProd[2];
}
// create a table for the output
sBuf +="<table>";
// First report the number of products and the amount ex VAT.
sBuf +="<tr><td style='text-align: left;'>" + iNumberOfProducts + " " +
strProducts + "</td>";
sBuf +="<td align='right'>" + imCFormat(iTotal,false) + "</td></tr>";
// Calculate the VAT and show a line with the amount of VAT.
fVAT = iTotal * Number( imVAT/100 );
sBuf += "<tr><td style='text-align:left;'>" + strVAT + " (" + imVAT + "%)" + "</td>";
sBuf += "<td style='text-align:right;'>" + imCFormat(fVAT,false) + "</td></tr>";
// Calulate the total amount and show this.
iTotal += fVAT;
sBuf +="<tr><td style='text-align: left;'>" + strTotal + "</td>";
sBuf +="<td align='right'><b>" + imCFormat(iTotal,false) + "</b></td></tr>";
}
sBuf += "</table>";
sBuf +=" <p> </p>";
// add a link to go to the shoppingcart...
sBuf +="<a title='' href='imcart.html'>" + strGoToCart + "</a>"
// and output the buffer...
document.write(sBuf);
}
ReportCart();
</script>
Change the language labels (the ones in green) in the texts which are appropriate for your language and click on OK (ignore the error. The script works fine!)
You can then format the block using the WX5 format painter or add extra markup-codes in the text.
There's also a link to quickly go to the shopping cart...
Sub-Menu: