Possibly useful "bookmarklet" for shopping cart

Soldato
Joined
29 Aug 2010
Posts
7,850
Location
Cornwall
Hi all,

I'm not sure if many people here are like me where you build up a shopping cart of what you want, but then leave it a few days to see if you still want it (after doing some research on parts or just sleeping on it)?

What I find is that (obviously) stock level can change during this time period, especially on either popular items or items that just have a limited stock (either because of lack of demand or because stock shortage from suppliers).

So I wrote this "bookmarklet" (which I recently got working thanks to some people on this forum) for myself and thought I may as well share it in case it helps anyone else. It's purpose is simply to display the stock amount (as you see if view the product page) next to the quantity box on the "Your Basket" page.

From this:
whgyyr.jpg
To this:
2m600e8.jpg

Here is the code:
Code:
javascript:(function(){%20%20%20$('#shoppingBkt%20th:contains("Qty")').html('Qty%20/%20Stock');%20%20%20$('#shoppingBkt%20tr').each(%20%20%20%20%20function(idx,%20item)%20{%20%20%20%20%20%20%20var%20url%20=%20$(item).find('a').attr('href');%20%20%20%20%20%20%20%20if%20(url%20!=%20null)%20{%20%20%20%20%20%20%20%20%20$.ajax({%20%20%20%20%20%20%20%20%20%20%20url:%20url,%20%20%20%20%20%20%20%20%20%20%20async:%20true,%20%20%20%20%20%20%20%20%20%20}).done(function(data)%20{%20%20%20%20%20%20%20%20%20%20%20%20var%20dataRetrieved%20=%20$('span.stock',$(data)).last().text();%20%20%20%20%20%20%20%20%20%20%20if%20(dataRetrieved%20==%20'Pre-order'%20||%20dataRetrieved%20==%20'Out%20of%20Stock')%20{%20%20%20%20%20%20%20%20%20%20%20%20%20dataRetrieved%20=%20'0';%20%20%20%20%20%20%20%20%20%20%20}%20else%20if%20(dataRetrieved%20==%20null)%20{%20%20%20%20%20%20%20%20%20%20%20%20%20dataRetrieved%20=%20'-';%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20$('#shoppingBkt%20tr').eq(idx).children('td').eq(2).append('%20/%20').append(dataRetrieved);%20%20%20%20%20%20%20%20%20}).fail(function()%20{%20%20%20%20%20%20%20%20%20%20%20$('#shoppingBkt%20tr').eq(idx).children('td').eq(2).append('%20/%20-');%20%20%20%20%20%20%20%20%20});%20%20%20%20%20%20%20}%20%20%20%20%20}%20%20%20);%20%20%20$.ajax({%20%20%20%20%20url:%20'/viewcart.php',%20%20%20%20%20async:%20true,%20%20%20%20});%20})();

Now for those not familiar with bookmarklets, what you'll need to do is create a new bookmark in your browser (I've tested in Chrome and Firefox), name it whatever you like and add that above code as the URL for the bookmark. (If anyone knows of a way to create a link or something to do this automatically that'd be handy!)
Now when you're viewing your basket, click on the bookmark you've created (it won't redirect you to a new page, it'll just run the Javascript code). The page will now be slightly changed to show the stock levels of each item in your basket.
Every time the page reloads (e.g. if you update a quantity) you will need to re-run the bookmarklet.

It also works on any "Outstanding Orders" (once logged in to your account) and any orders in "Order History" (if you should want to see stock levels of those items for any reason).

If you've ordered (or are about to order) a number of pre-order items you could also use this to see when they're all in stock rather than checking each item individually.

Pre-order or Out-of-stock items appear as a quantity of 0.
Items no longer listed on the Overclockers website will display with a quantity of "-".

Hopefully this will help someone other than myself!

Mods: Not sure if there's a better location for this thread, if so feel free to move it. Thanks.
 
Back
Top Bottom