Google+ Followers

Wednesday, January 8, 2014

How to check all of bestbuy's inventory to find which zip code has your desired product!

As an optimizer, I 'suffer' from a sometimes debilitating yearning for the best, or most efficient, product, solution, method, etc. Thus when the Yoga 2 Pro was released, I had to acquire one. However, BestBuy was/is the only distributor with the i7 8gb ram version (at a reasonable price and on-hand), and unfortunately they only had it available for in-store pickup at a select few locations.

Maybe this has happened to you. It's frustrating, is it not, that there's no way to find out WHERE the item is in stock!?

So I spent a few minutes throwing together an ad-hoc test/solution:
My solution requires:
1. Autohotkey
2. Chrome browser with Advanced page injector extension
3. Some ingenuity and ability to google how to do certain things (for example, how to use autohotkey's spy window to determine the coordinates you should have it automatically click)

Steps I took to get the Yoga 2 Pro:

1. Create a rule in advanced page injector options:
Match:
^http://www.bestbuy.com/site/ols*
Add JavaScript:
$(document).ready(function(){$('#frmStoresSearchFormId').attr('target','_blank'); if ($('span.ca-availablenow').length > 0){alert($("[name='TxtZipCode']").attr('value'))}else {window.close()}}) 
2. Open up the store locator from the item page on BestBuy.com and try a local zipcode.
 
3. Enter the following code into the Chrome console (open with f12 or ctrl+shift+i then click console), and press enter after you change the zips to include the ones you want (I found a list of all zips online and used SublimeText to add the comma and quotes):
$('#frmStoresSearchFormId').attr('target','_blank').attr('style','target-new: tab');
$('input.buttons-blue').attr('id','attack');
window.openBB = function(){console.log(window.curNum);console.log(window.zips[window.curNum]);$("[name='TxtZipCode']").attr('value',window.zips[window.curNum]); $('#frmStoresSearchFormId').submit(); document.getElementById('attack').click(); loadNewPage('storeSearch'); setTimeout(function(openBB){window.curNum = window.curNum + 1; window.focus; if (window.curNum < window.zips.length) {window.openBB()}}, 4000)}
window.curNum = 0

window.zips = ["00501","00544","00601"]
openBB() 
NOTE: The code redundantly attempts several methods for submitting the html form element - I didn't really bother with testing to determine which to use, so I just left them all in. This is messy and hack-y code but I got a Lenovo Yoga 2 Pro out of it :)
4. Run an autohotkey if necessary to restore form submission functionality (a Chrome bug prevents this from being consistent for most people)
My code is:
^!+b::
Loop {
Click 20, 27
Click 365, 483
Sleep 3000}
After installing autohotkey, run Window Spy to determine the location coordinates of your main item lookup tab and any of the form text boxes within it - then paste the above code in with your coordinates and save anywhere as a .ahk file. Then run it and the code will be summoned when you press ctrl+shift+alt+b

Note with the barebones code above your chrome window must be the active (in focus) window for Autohotkey to click in the right place.

This is a little bit less detailed than I would like but good luck & let me know if you find what you're looking for! I was able to convince the store manager to ship it to me if I emailed him a copy of my driver's license :)

1 comment:

  1. Hello, Wonderful code!
    When I'm copy pasting the 3rd step in my chrome browser I'm getting "0" as output and there is no loop running. But when I try to typing zipcode manually, I'm able to see that new tab is getting closed automatically if the product is not available. Could you please help me?

    ReplyDelete