Posts Tagged jquery

Make the OpenCart Checkout button stand out a bit

The first time I added something to the OpenCart shopping cart I was momentarily confused as to where the Checkout link was. It’s not exactly hidden but nevertheless my brain said “Huh, wherezitat?”. So I decided to have it pop a bit when something is added to the cart (or the cart is not empty).

Here it is before:
before the OpenCart tab is changed
And here it is after:
after the OpenCart tab is changed

Now this change needs to occur if the cart has anything in it but it also needs to change as soon as something is added (assuming it was previously empty). I did this with some javascript (OpenCart uses jQuery… yay!) and one CSS style.

Here are the steps involved:

  1. First we will add the functionality to change the tab as soon as something is stuck in the cart. The file to be edited is at:
    catalog/view/theme/yourtemplatename/template/module/cart.tpl

    . Inside the document ready function around near the bottom of the file (in version 1.4.x) look for the ajax method. It has a callback named “success”. Add the following line

    $('#tab_checkout').addClass('full');

    This will apply the “full” class to the checkout tab.

  2. Now let’s create that “full” class. In
    catalog/view/theme/yourtemplatename/stylesheet/stylesheet.css

    add the following:

    #header .div4 a.full {
        color: #FFF;
        text-shadow: 1px 1px 2px #666;
        font-weight:bold;
        background: url('../image/tabGreenGlow.png') no-repeat;
    }

    Don’t forget to upload an image, in this case “tabGreenGlow.png”… just base yours on the default tab.

  3. Now we will add the functionality to display this tab site-wide (assuming something is in the cart). Open the file:
    catalog/view/theme/yourtemplatename/template/common/header.tpl

    and in the document ready function add:

    var cartStatus = $('#module_cart .middle div').text();
        if (cartStatus !== '0 items'){
            $('#tab_checkout').addClass('full');
            }

    This will check the cart contents on page load and apply the “full” style if anything is in there. That’s it!

     

,

1 Comment

Generating XML and passing it to jQuery

I am generating some XML and then POSTing it to a jQuery based plugin. Looking at the POSTed XML in Firebug, everything appears normal. However, something is not getting passed to the plugin so it is using a amount (which results in no data being properly displayed). The solution turned out to be quite simple… set the Mime-Type on the posted XML! Doh!

So by adding

header('Content-Type: text/xml');

everything passed smoothly.

     

, ,

No Comments

Magento and jQuery, Sitting in a Tree…

… k-i-s-s-i-n-g. First comes love, then comes… oh who am I kidding! They don’t really like each other that much. That said, here is how to make them at least tolerate each other:

Integrating jQuery with Magento is not complicated but there are a number of gotchas.

In a nutshell you…

  1. Create a directory named “jquery” (really you could name it “gorgonzola” but why not be consistent, eh?) in Magento’s js folder and stick the current version of jQuery inside itwherever-you-installed-it/js/jquery/jquery.js
  2. Implement jQuery’s noconflict mode by putting the following at the very end (very, very end… not inside a function or something) of the jQuery code
    jQuery.noConflict();
  3. Add a call to jquery in the page.xml file (located somewhere like wherever-you-installed-it/app/design/frontend/default/blank/layout/page.xml Note that this assumes you are using the “blank” theme in the “default” frontend)

    This bit goes with all of the other addJs bits but, and this is what took up an hour of my incredibly valuable time (an hour I could have spent playing Wii Sports, anyway), make sure you put it after all of the other javascript files. Not just after some of them… after all of them.

  4. To now make use of all of this go into wherever-you-installed-it/app/design/frontend/default/blank/template/page/html/head.phtml and put your jquery code right there at the end of the code
     

,

No Comments