View Full Version : XML tag name for how much someone saves?
RockNRollPig
02-15-2004, 04:02 PM
Is there an XML tag name for the amount of money and percentage of savings people get in the AWS? Like there is "list price" and "our price"....how would I add a "You save: $10 (15%)"?
kdb003
02-15-2004, 04:07 PM
you can compute those easily
saved money = list price - our price
%saved = (saved money / list price)*100
MattM
02-15-2004, 04:09 PM
Yes - you have to compute it, it is not included in the XML feed.
RockNRollPig
02-15-2004, 04:33 PM
Okay...I'm trying to do the subtraction and it's just returning "0"...heres my code:
$save=$ListPrice-$OurPrice; echo $save;
chromate
02-15-2004, 04:46 PM
The $ListPrice and $OurPrice contain strings including the dollar sign. You need to remove this dollar sign first before you do the calculations with them and then add the dollar sign back on when you print the result.
flyingpylon
02-16-2004, 07:00 PM
The other thing to watch out for is that sometimes one or the other will be missing. I'm not sure how PHP handles an attempt to do math with a nonexistent value, but in XSLT I had to first make sure that both nodes were integers or it would return a string of "NaN" (Not a Number).
eMEraLdwPn
02-16-2004, 11:15 PM
i think if you did it php and one was missing it would just count it as 0
chrispian
02-17-2004, 08:26 AM
Not tested, but this should work
$listp = str_replace("\$", "", $listprice);
$ourp = str_replace("\$", "", $ourprice);
$savedMoney = $listp - $ourp;
$savedPercent = ($savedMoney / $listp)*100;
GCT13
02-17-2004, 08:38 AM
I wrote another AWS tutorial that addresses this issue. Should be up this week.
chrispian
02-17-2004, 07:57 PM
I just tested my code and made a small tweak for formatting.
Somewhere in your loop to display products add this code (I put it just before I display my results):
// reassign so we don't lose our original values
$listp = str_replace("\$", "", $ListPrice);
$ourp = str_replace("\$", "", $OurPrice);
// Calculate the savings in dollars
$savedMoney = $listp - $ourp;
// calculate the savings in percentages
$savedPercent = ($savedMoney / $listp)*100;
// format the saved money into $xxx.xx
$savedMoney = sprintf("%01.2f", $savedMoney);
// format the saved percen tinto $xx.xx
$savedPercent = sprintf("%01.0f", $savedPercent);
Then, do use it, I do this:
<? if ($ListPrice != $OurPrice) { ?>
<strong>You Save: <span class="prices">$<?=$savedMoney?> (<?=$savedPercent?>%)</span></strong><br />
<? } ?>
I've been making several mods to Dan's excellent code. You can see them all in action here: http://www.imaginationunbound.com/
GCT13
02-17-2004, 08:12 PM
That's a nice bookstore. Where did you get all the Books BrowseNodes?
chrispian
02-17-2004, 08:30 PM
Dan, I imported them into mysql from browsenodes.com. I added a couple of functions to your script to build 2 difference kind of trees for them too.
Let see, here is the code and the functions needed to view them.
http://www.imaginationunbound.com/source/aws-nodes.txt
http://www.imaginationunbound.com/source/browsenodes.zip
Zip file is ~ 220kb and uncompressed to 753kb.
GCT13
02-17-2004, 08:36 PM
Thanks for posting!
chrispian
02-17-2004, 08:38 PM
My pleasure. I'm happy to share every bit of code I have for it - you did! Let me know if I can help out in any way with it. I plan on putting it to use, might as well contribute ;)
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.