Tutorials
-
Twitter
- RT @fwa: A car chase like you will have never seen before: Shaw http://t.co/obQ6elbL by @B__REEL 08:01:24 AM April 24, 2012 from web
Facebook
FRIENDS
Category Archives: Development
Foxycart : live cart contents to your site
Since originally writing this tutorial FoxyCart’s 0.7.0 release has made some of this a lot more simple. If you’re on an older version then the tutorial below should be of good use to you, but if you’ve upgraded then there’s a couple of cool new features which make the whole process a lot easier.
The foxycart.js now automatically updates some divs which you can freely place on your page. As long as you have FoxyCart up and running, it’ll work without any extra effort. Simply create the elements within your HTML you require with the following class names or IDs, taken from the FC wiki:
-
#fc_minicart,.fc_minicart: If theFC.json.product_countis greater than 0, these elements will be shown. Otherwise they’ll be hidden -
#fc_quantity,.fc_quantity: The inner HTML will be replaced by the value inFC.json.product_count. -
#fc_total_price,.fc_total_price: The inner HTML will be replaced by the value inFC.json.total_price, formatted using the_currency_formatfunction (which adds decimals but doesn’t add currency symbols).
Nice and simple.
————————————–
Original Tutorial – 10th July 2010 – For FoxyCart versions prior to 0.7.0
————————————————
I’m currently working on a redesign and rebuild of Little Plum, and the CMS of choice has been modx. The cart we’ve chosen to use is FoxyCart, due to how awesomely customisable it has turned out to be. I’ve noticed quite a lack of tutorials on using modx and foxycart together on the web, so after this experience with the Little Plum store I will try and put a few online.
In this post I’m just going to briefly explain how you can get live figures from your FoxyCart cart on your website using the FoxyCart JSON cart object. I’ll get to work on some more in depth tutorials in the future, so keep checking back.This quick tutorial assumes you’ve got your store set up and the foxycart includes already embedded on your page. Check out the foxycart documentation if any info is needed on how to do this.
When you update your cart, FC will call the fc_BuildFoxyCart() function, so whatever we put within this function will be triggered after any interaction with the cart. Create a new js file and insert this function. Include the new js file on your website.
1 2 3 | <a name="line1"></a>function fc_BuildFoxyCart() {
} |
<a name="line1"></a>function fc_BuildFoxyCart() {
}So what we want to do in this example, is display how many products we have in our cart, and what the total price is. We want to display this in a div on our website, so we’ll create a div we can write the data to.
1 | <a name="line181"></a><div id="minicart"></div> |
<a name="line181"></a><div id="minicart"></div>
In this case, our div id is “#minicart”
Getting data from the foxycart JSON is very simple, in this example we want the product_count and the total_price:
So our fc_BuildFoxyCart() function becomes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <a name="line11"></a>function fc_BuildFoxyCart() { if (fc_json.product_count > 0) { $("#minicart").html("<p>"+fc_json.product_count+" items, £" +fc_json.total_price+"</p>"); } else { $("#minicart").html("<p>0 Items</p>"); } if (fc_json.product_count == 1) { $("#minicart").html("<p>"+fc_json.product_count+" item, £" +fc_json.total_price+"</p>"); } } |
<a name="line11"></a>function fc_BuildFoxyCart() {
if (fc_json.product_count > 0) {
$("#minicart").html("<p>"+fc_json.product_count+" items, £"
+fc_json.total_price+"</p>");
}
else {
$("#minicart").html("<p>0 Items</p>");
}
if (fc_json.product_count == 1) {
$("#minicart").html("<p>"+fc_json.product_count+" item, £"
+fc_json.total_price+"</p>");
}
}Go ahead and update your cart, and watch the details written to the #minicart div. The if handles no items, and a single item., but you can customise this how you like.
This should have given you some basic knowledge on the FoxyCart JSON and how we can use it to get data from the cart onto our sites without needing to access the cart popup itself. For a full view of the JSONstructure, check out this documentation. I’ll be writing some proper tutorials very soon on FoxyCart and modx, so keep checking back!
jQuery – Browser Detection
Something I came across being very important when animating with jQuery was the way different browsers can handle the load. Internet explorer was substantially slower than the other rivals, with Chrome being fastest (although seemingly IE9 has caught up speed wise). This was especially apparant while using Cufon + animation, yeilding very jerky results while animating in IE8 and below. Another issue was IE8s lack of support for animating alpha. So what was needed was a way to handle slightly different animations depending on which Browser is being used to view the website. jQuery.browser makes this very simple: with both conditional handlers for browser type and browser version.
So for example we want to have alternative content for Internet Explorer users, we can use:
if ( $.browser.msie ) {
$(‘.mydiv’).html(‘<p>Hi There, you’re using Internet Explorer</p>’);
}
And we can take this further by checking the version of the browser:
if ( $.browser.msie ) {
if ($.browser.version <= 6)
{
$(‘.mydiv’).html(‘<p>Hi There, you’re using Internet Explorer 6 =(</p>’);
}
}
Very simple stuff! It’s best practice to try and avoid browser specific code where possible, but in certain situations it can be an essential little piece of knowledge. For more info check out the jQuery documentation.
Fix Cufón in IE9 Beta
Update
Cufon have now released the latest version with IE9 support. If you’re still having troubles then make sure you upgrade to the latest version . If for whatever reason you’d prefer not to, the below fix should help you still.
————————————————————————————-
Just a quick one, after getting the new TD site working and released, I download the Internet Explorer 9 beta and saw that cufón had started to render completely blank. The cufón guys have been quick to get a fix out, and a new release is coming soon, but if you need a quick fix then here’s some info:
<!–[if gte IE 9]>
<script type=”text/javascript”>
Cufon.set(‘engine’, ‘canvas’);
</script>
<![endif]–>
Place the above in your HTML before all the Cufon.replace() calls.
Alternatively you can force IE9 to behave like IE8 (or 7):
<meta http-equiv=”X-UA-Compatible” content=”IE=8″ />
<meta http-equiv=”X-UA-Compatible” content=”IE=7″ />
New Toasted Digital Website
Toasted Digital has been relaunched with a nice new compliant jQuery animated website.
The site itself has been a bit of an experiment so there will be some helpful info on designing and scripting with jQuery appearing soon on the blog. In the meantime, I hope you enjoy the website!
FoxyCart : Using JSON on Your Receipt Page
Following up on my previous FoxyCart/MODx Tutorial, more FoxyCart solutions have come my way. I’ve recently had to implement pixel tracking onto a client’s website. FoxyCart has some good documentation on basic affiliate tracking, however I needed slightly altered data in my tracking image. Luckily the FoxyCart JSON gives you access to more data, and with a little JavaScript you can get a lot more out.
In this small tutorial I will show you how to include custom tracking information on your receipt page, using JavaScript and the ^^receipt_only_begin^^ ^^receipt_only_end^^ placeholders.
If you’re trying to figure out how to place order data onto your receipt, you may first want to check out this documentation for the existing available placeholders to check that doesn’t already suffice.
The main issue I faced was that my order amount needed the value multiplied by 100 to remove the decimal, it also needed to be the subtotal without tax. While the ^^subtotal^^ exists, it’ll output my total as xx.xx e.g 24.99. What I’m looking for is 2499.
So in comes the FoxyCart JSON. Check out the documentation here.
With this available, we’re able to manipulate our data with JavaScript. In the <head> tag of your receipt template, we can place the following:
<script type=”text/javascript”>
window.onload = function() {
var price = fc_json.total_price;
newprice = price*100;
$(“#track”).html(“<img src=’http://yourtracking.com/&amount=”+newprice+”‘/>”);
}
</script>
Within the <body>tag of your receipt template, create the div #track
<div id=”track”></div>
This is where 0ur pixel tracking gets added.
As this is tracking, we only want the tracking image called once. FoxyCart has two useful tags to make sure this happens. ^^receipt_only_begin^^ ^^receipt_only_end^^
Place these either side of your javascript
^^receipt_only_begin^^
<script type=”text/javascript”>
window.onload = function() {
var price = fc_json.total_price;
var newprice = price*100;
$(“#track”).html(“<img src=’http://yourtracking.com/&amount=”+newprice+”‘/>”);
}
</script>
^^receipt_only_end^^
This ensures that the javascript function won’t be called on any return visits to the receipt.
There we have our tracking code with custom values inserted. Using the JSON we could potentially create a loop to support multiple tracked products, and get other values such as quantity or category.
Apparently the next release of FoxyCart will see the whole preprocess and buildfoxycart functions a little easier to work with, but even now with a little knowledge FoxyCart is awesomely flexible.
Animating divs using jquery
One of the big decisions I’ve had to make over the past few months with regards the new Toasted Digital website is Flash or no Flash. A large part of the work I do is Flash based, therefore it seems appropriate to display my portfolio in that format. However the internet is changing, and Flash while a big part of the work I do is generally not my favorite thing to use for full websites anyway. The downsides of its SEO capabilities and incompatibility with apple products can be frustrating. So I’ve decided to run a few experiments and tests using jquery to animate divs. I’ve seen a few examples around the net but can jquery alone give me the level of animation I need to make my website? I’ve not yet seen an example of sophisticated animation using jquery as an alternative to Flash, but the animation required for my website is simple and slick, therefore it may work.
Results
http://www.toasteddigital.com/ex/
Update – Check back soon for a more in depth tutorial. Follow TD on Twitter or Facebook for updates!




