Setting an Amazon Affiliate Link as Your Out of Stock Message in Drupal Uber Cart

As of this posting, I am pretty new to Drupal and Silly Monkey Toys is my little test site running in Uber Cart. When our items go out of stock, I wanted a way to direct people at an Amazon affiliate link – that way, I can at least make a little money off the site visitor. Being a noob with Drupal, I did not want to go hacking away at the php code or core, and I couldn’t find much documentation out there for changing the Out of Stock message in Uber Cart.

So, for those who care or need this functionality in a fairly quickand easy way, here is what I did.

First off, I made sure I was running the add-on for friendly URLs, PathAuto. There are some optional installs for things like redirects that you will really want to install for SEO purposes as well.

Side note: This addon also cleans up your URLs in Google Analytics to something that a normal human can understand. Unless you really call your products listed in Uber Cart things like /node/12, you’ll love seeing the actual name of the product.

With PathAuto installed, I used a simple JavaScript/jQuery bit of hacking to give me the rest of what I need. You’ll want to generate your own Amazon affiliate search link and mod the parts as needed.

Under your Admin->Store->Configuration Click on the linke for Out of Stock Notification At that point, you can edit the message that is displayed when your item cache is depleted. Here is  the bit of code I set to drop in our Amazon links.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<div id="doh">
<h3 style="color: red;">We're sorry, that item is currently out of stock :(</h3>
</div>
<script type="text/javascript">
jQuery(document).ready( function() {
sm_loc = document.location.toString();
sm_loc = sm_loc.substr( sm_loc.lastIndexOf('/') + 1, sm_loc.length );
if ( sm_loc != '' ) {
sm_q = sm_loc.replace(/\-/g, ' ');
jQuery('#doh').append(
'<h3>You still want it, don\'t ya. Go get your '
+ '<a target="_blank" href="http://www.amazon.com/gp/search?ie=UTF8&camp=1789&creative=9325&index=aps&keywords=' + sm_q + '&linkCode=ur2&tag=REPLACE_ME">'
+ sm_q + ' now'
+ '</a> '
+ '<img src="http://ir-na.amazon-adsystem.com/e/ir?t=REPLACE_ME&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />'
+ ' on Amazon.</h3>');
}
});
</script>
<div id="doh">
<h3 style="color: red;">We're sorry, that item is currently out of stock :(</h3>
</div>
<script type="text/javascript">
jQuery(document).ready( function() {
sm_loc = document.location.toString();
sm_loc = sm_loc.substr( sm_loc.lastIndexOf('/') + 1, sm_loc.length );
if ( sm_loc != '' ) {
sm_q = sm_loc.replace(/\-/g, ' ');
jQuery('#doh').append(
'<h3>You still want it, don\'t ya. Go get your '
+ '<a target="_blank" href="http://www.amazon.com/gp/search?ie=UTF8&camp=1789&creative=9325&index=aps&keywords=' + sm_q + '&linkCode=ur2&tag=REPLACE_ME">'
+ sm_q + ' now'
+ '</a> '
+ '<img src="http://ir-na.amazon-adsystem.com/e/ir?t=REPLACE_ME&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />'
+ ' on Amazon.</h3>');
}
});
</script>

Replacing “REPLACE_ME” with your affiliate ID, of course. Save the changes and you should be all set. When your items run out of stock, the customer will see your Amazon affiliate link.

Note: You may need to set your “Text Format” to “Full HTML”.

Have a better way, a cool idea, or just want to say hi? Leave a comment!

About 

I'm Alan Cook and I am Southside Studios. Together with my girlfriend, Laurie, we run a network of websites, including managing the sites of several clients.

When we're not working, we are making a reality out of our full time RV nomad lifestyle.

Leave a Reply

Your email address will not be published. Required fields are marked *