correct minicart code

General ShopSite user discussion

correct minicart code

Postby lordofdirt » Wed Apr 08, 2009 9:35 am

The minicart displays on my pages correctly when the shopping cart is empty but then disappears when I add things to the cart. I read in another post that the end of the code is written so that it throws an extra </div> out whenever the number of items is zero and all I had to do was move

document.write("</div>\n");

higher up into a set of else brackets and/or add another bracket. Not being that familiar with javascript, I'm a bit confused. Does anyone have an example of how that last bit of script is supposed to look?
lordofdirt
 
Posts: 40
Joined: Fri May 16, 2008 8:19 am

Postby RedSyntax » Thu Apr 09, 2009 8:09 am

Here is the complete code for the mini cart view:


#### Mini Cart Detail Display ####

#### YOU CAN CHANGE THESE VALUES IF NEEDED ####
[-- IF PAGE.LinkColor --]
[-- VAR.MiniCartTextColor PAGE.LinkColor --]
# [-- VAR.MiniCartBackgroundColor PAGE.BackgroundColor --]
[-- VAR.MiniCartBackgroundColor "transparent" --]
[-- ELSE --]
[-- VAR.MiniCartTextColor MORE_INFO.LinkColor --]
# [-- VAR.MiniCartBackgroundColor MORE_INFO.BackgroundColor --]
[-- VAR.MiniCartBackgroundColor "transparent" --]
[-- END_IF --]
[-- VAR.ShowCart "no" --]
[-- VAR.MiniCartColor "black" --]
[-- VAR.TextAlign "left" --]

#### DON'T CHANGE ANYTHING BELOW HERE ####

<script language="javascript">
var cookies=document.cookie; //read in all cookies
var start = cookies.indexOf("ss_cart_[-- STORE_Serial_Number --]=");
var cartvalues = "";
var linecount = 0;
var start1;
var end1;
var tmp;

// Start Output
document.write("<div style=\"color: [-- VAR.MiniCartTextColor --];");
document.write("background-color: [-- VAR.MiniCartBackgroundColor --];");
document.write("text-align: [-- VAR.TextAlign --];");
document.write("font-family: Verdana, Arial, Helvetica, sans-serif;");
document.write("font-size: 8pt;");
document.write("\">\n");

document.write("<table>\n");
document.write("<tr>\n");
document.write("<th colspan=\"3\" align=\"center\">");

[-- IF VAR.ShowCart "yes" --]
document.write("<a href=\"[-- SHOPPING_CART_URL --]\"");
document.write("style=\"text-decoration: underline;");
document.write("color: [-- VAR.MiniCartTextColor --];");
document.write("\">");
document.write("<img src=\"[-- OUTPUT_DIRECTORY_URL --]/media/themesmedia/cart-[-- VAR.MiniCartColor --].gif\" border=\"0\" name=\"cart\" align=\"top\">");
document.write("</a> ");
[-- END_IF --]

document.write("<a href=\"[-- SHOPPING_CART_URL --]\"");
document.write("style=\"text-decoration: underline;");
document.write("color: [-- VAR.MiniCartTextColor --];");
document.write("\">");
document.write("[-- STORE.SC_YourShoppingCart --]");
document.write("</a>");

document.write("</th></tr>");

if (start == -1) //No cart cookie
{
document.write("</table>\n");
}
else //cart cookie is present
{
start = cookies.indexOf("=", start) +1;
var end = cookies.indexOf(";", start);

if (end == -1)
{
end = cookies.length;
}

cartvalues = unescape(cookies.substring(start,end)); //read in just the cookie data

start = 0;
while ((start = cartvalues.indexOf("|", start)) != -1)
{
start++;
end = cartvalues.indexOf("|", start);
if (end != -1)
{
linecount++;

if (linecount == 3) // Product Subtotal
{
start1 = start;
end1 = end;
document.write("<tr><td>Qty</td>");
document.write("<td align=\"center\">Product</td>");
document.write("<td align=\"center\">Price</td></tr>\n");
}

if (linecount > 3) // individual products
{
tmp = cartvalues.substring(start,end);
colon = tmp.indexOf(":", 0);
document.write("<tr>");
document.write("<td>");
document.write(tmp.substring(0,colon));
document.write("</td><td>");
colon2 = tmp.indexOf(":", colon+1);
document.write(tmp.substring(colon2+1,end - start));
document.write("</td><td align=\"right\">");
document.write(tmp.substring(colon+1,colon2));
document.write("</td></tr>\n");
}

start = end;
}
else
{
break;
}
} // end while loop

//close minicart HTML
document.write("<tr>");
document.write("<td colspan=\"2\" align=\"right\">Subtotal</td>");
document.write("<td align=\"right\">");
tmp = cartvalues.substring(start1,end1);
colon = tmp.indexOf(":", 0);
document.write(tmp.substring(colon+1,end1 - start1));
document.write("</td>");
document.write("</tr>");
document.write("</table>\n");
}
document.write("</div>\n");
</script>
RedSyntax
 
Posts: 51
Joined: Mon Nov 17, 2008 7:29 am


Return to User Forum

Who is online

Users browsing this forum: No registered users and 146 guests