Business Catalyst: Catching the Add Item to Shopping Cart Event

Programmers

shoppingCartLet’s say you’ve customized the shopping cart Quantity module to make it fit your website’s design. But when someone adds a product to the cart, it doesn’t update the number anymore!

Here’s a quick fix, inspired by  on the blog post here, and his original coding here.

First, I hacked the actual shopping cart module to display how I wanted it to in the first function (don’t forget to put this within the document ready tag):

//DEALING WITH SHOPPING CART # IN HEADER
function ShoppingCartUpdate(){
     var itemsInCart = $('#catCartSummary .cartSummaryItem').html();
     var itemsSplit = itemsInCart.split(' ');
     if (itemsSplit[0] == 'Shopping'){
          $('#circleSC').html('0');
     } else {
          $('#circleSC').html(itemsSplit[0]);
     }
}
ShoppingCartUpdate();

I called the function so that it runs when the page is loaded. That’s the easy stuff.

Now we check for a Window Alert and run our function again inside of it.

window.alert = function(msg){
     ShoppingCartUpdate();
     if ((msg.indexOf('ERROR:') >= 0) || (msg.indexOf('- ') >= 0)){
           //add anything here if the item doesn't get added to the cart because of an error.
     }
}

That’s it! I left the error section just in case you want to use it.

Thanks again to !

Comments