Amazon Web Services Add-Ons

Calculate Savings

Amazon gives you a product's list price and the selling price, but it's up to you to determine the customer's savings, both monetarily and on a percentage basis. To make it exciting, the prices are not returned in a numeric format - dollar signs and commas are included. For example: "$1,199".

// $ListPrice = list price of the product
// $OurPrice = Amazon.com's price

// remove commas and dollar signs from $ListPrice and $OurPrice
$ListPrice2 = str_replace('$','',$ListPrice);
$ListPrice2 = str_replace(',','',$ListPrice2);
$OurPrice2 = str_replace('$','',$OurPrice);
$OurPrice2 = str_replace(',','',$OurPrice2);

// calculate savings
if($ListPrice2 > $OurPrice2){
    $saveAmount = sprintf('%.2f', ($ListPrice2 - $OurPrice2));
    $savePercentage = 100 * $saveAmount / $ListPrice2;
    $savePercentage = round($savePercentage);
    $saveAmount = number_format($saveAmount, 2, '.', ',');
}

// print the savings if savings is greater than 2%
if($ListPrice <> $OurPrice && $savePercentage > 2){
    echo 'You Save: $' .$saveAmount. ' (' .$savePercentage. '%)';
}

Show Savings Percentage on Product Images

Got the urge to put extra emphasis on how much money your visitors will save? Why not put the savings percentage right on the image? We can do this using Amazon's dynamic image format. All we need is the ASIN, the two-digit savings percentage (so 5 = 05), and your preference for the location of the percentage number on the product image (lower right or lower left).

Observe the image format. "xx" is the two-digital savings percentage, "R" or "L" determines which side the percentage is placed on the product image.

Right side: Left side:
// $Asin = the product's ASIN
// $savePercentage = the product's savings percentage

// if the saving percentage is less than 10%
if($savePercentage >= 1 && $savePercentage <= 9){$ImageUrl = 'http://images.amazon.com/images/P/' .$Asin. '.01.0' .$savePercentage. 'TLZZZZ.jpg';}
// if the saving percentage is greater than or equal to 10%
if($savePercentage >= 10){$ImageUrl = 'http://images.amazon.com/images/P/' .$Asin. '.01.' .$savePercentage. 'TLZZZZ.jpg';}

echo '<img src="' .$ImageUrl. '" border="0" />';

For More AWS Info: WebsitePublisher Forums

Looking for a hotbed of the latest and greatest AWS tips and news? Make a daily visit to the WebsitePublisher Forums! Ask a question if you're just getting your AWS site off the ground or share the knowledge if you're a seasoned veteran - we can all benefit from our collective experience.

WebSitePublisher Forums