View Full Version : Converting ColdFusion CFIF to PHP IF statement
grantr281040
03-13-2009, 10:10 AM
Hi there!
To stay with ecart I am switching my life from CFM to PHP. In my cart I have a coldfusion IF statement that displays a discount amount (or amount the customer has saved by buying more product) and if the client has not bought enough to qualify for a discount it displays "buy more and save" with a couple price break options.
The question is how do I convert my CFIF statement to PHP to achieve the same result.
Any help is appreciated.
Here is my current code....
<cfif WA_eCart_TotalColumn(CardCart, "TotalDiscount") GT 0>
<br />
<span class="style75 style64"><span class="style54 style76">Congratulations!!! Your Volume Discount <strong>Savings</strong> is... </span></span> <span class="style91">$<cfoutput>#LSCurrencyFormat(WA_eCart_TotalColumn(CardCart, "TotalDiscount"),'none')#</cfoutput>
</span>
<p>
<cfelse>
</p>
<p class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
Discounts apply to same card purchases only. <br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></p>
</cfif>
Ray Borduin
03-13-2009, 10:20 AM
<?php
if ($CardCart->TotalColumn("TotalDiscount") > 0) {
?>
grantr281040
03-13-2009, 11:39 AM
cool! so what do I repalce </cfoutput> with.
Thanks Ray!
Ray Borduin
03-13-2009, 11:55 AM
<?php echo($code) ?>
will output the variable $code
grantr281040
03-13-2009, 12:20 PM
Man I just can't seem to make it work so I just started over as not to confuse myself with the coldfusion elements.
So what I have is this...
Congratulations!!! Your Volume Discount <strong>Savings</strong> is... </span></span> <span class="style91">$</span><?php echo $GCcart->DisplayInfo("TotalDiscount"); ?><br />
</p>
<p><span class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
<span class="style33 style114">Discounts apply to same card purchases only. </span><br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></span>
What I want it to say is....
IF TotalDiscount is > 0
Then....
Congratulations!!! Your Volume Discount <strong>Savings</strong> is... </span></span> <span class="style91">$</span><?php echo $GCcart->DisplayInfo("TotalDiscount"); ?><br />
If TotalDiscount is == 0
Then.....
<p><span class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
<span class="style33 style114">Discounts apply to same card purchases only. </span><br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></span>
Sorry for all the rookie questions but I just haven't gotten my head around this PHP yet.
Thanks,
Grant
Ray Borduin
03-13-2009, 12:27 PM
What is the problem? Error?
grantr281040
03-13-2009, 12:35 PM
All I would bet is...
Parse error: parse error in C:\xampp\htdocs\IndustryGreetings\shopping_cart.ph p on line 542
grantr281040
03-13-2009, 12:36 PM
Sorry...I meant to say all I would GET is...
Parse error: parse error in C:\xampp\htdocs\IndustryGreetings\shopping_cart.ph p on line 542
Ray Borduin
03-13-2009, 02:35 PM
What is on line 542?
grantr281040
03-13-2009, 02:49 PM
Well I've change it now so I am not getting that error but now I do not have an IF statement. I have this...
Congratulations!!! Your Volume Discount Savings is... </span> <span class="style91">$</span><?php echo $GCcart->DisplayInfo("TotalDiscount"); ?><br />
</p>
<p><span class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
<span class="style33 style114">Discounts apply to same card purchases only. </span><br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></span>
What I want it to say is........
IF TotalDiscount is > 0
Then....
Congratulations!!! Your Volume Discount <strong>Savings</strong> is... </span></span> <span class="style91">$</span><?php echo $GCcart->DisplayInfo("TotalDiscount"); ?><br />
If TotalDiscount is == 0
Then.....
<p><span class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
<span class="style33 style114">Discounts apply to same card purchases only. </span><br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></span>
Ray Borduin
03-13-2009, 02:52 PM
<?php
if ($CardCart->TotalColumn("TotalDiscount") > 0) {
?>
your discount html
<?php
} else {
?>
your zero discount code
<?php
}
?>
grantr281040
03-16-2009, 10:26 AM
I am getting an error when I use that.
Fatal error: Call to a member function TotalColumn() on a non-object in C:\xampp\htdocs\IndustryGreetings\shopping_cart.ph p on line 560
Line 560 reads:
if ($CardCart->TotalColumn("TotalDiscount") > 0) {
Any ideas?
Thanks,
Grant
Ray Borduin
03-16-2009, 10:48 AM
From the error, it would appear that your cart isn't named CardCart, or you don't have the cart object on the page...
Drag and drop the subtotal from the bindings panel under eCart. It will give you the correct syntax, but reference the totalprice column. That syntax should allow you to get the total of any column in the cart.
grantr281040
03-16-2009, 11:03 AM
Ahhhh! That must be it....I renamed may cart....I'll try it THANKS!!!!
One more thing though. I switched all of my CFM calculations to PHP and am having an issue. I THINK it is where in Coldfusion I use the word "AND". What is the proper PHP symbol for "AND"
Thanks again!!!!
Grant
Ray Borduin
03-16-2009, 11:11 AM
in PHP: AND = &&
grantr281040
03-16-2009, 12:22 PM
I must still have some CFM language left in my formula as it is still not working.
This TotalPrice Calculation retuns the value of my [ProductCategory] rather than the value related to which quantity the client selects.
Any ideas?
Thanks,
Grant
(((((abs([ProductCategory] == 1 && [Quantity] <= 49)) * [Price]) + ((abs([ProductCategory] == 1 && [Quantity] >= 50 && [Quantity] < 100)) * 1.38) + ((abs([ProductCategory] == 1 && [Quantity] >= 100 && [Quantity] < 200)) * 1.17) + ((abs([ProductCategory] == 1 && [Quantity] >= 200 && [Quantity] < 300)) * .99) + ((abs([ProductCategory] == 1 && [Quantity] >= 300 && [Quantity] < 400)) * .92) + ((abs([ProductCategory] == 1 && [Quantity] >= 400 && [Quantity] < 500)) * .85) + ((abs([ProductCategory] == 1 && [Quantity] >= 500 && [Quantity] < 700)) * .79) + ((abs([ProductCategory] == 1 && [Quantity] >= 700 && [Quantity] < 1000)) * .71) + ((abs([ProductCategory] == 1 && [Quantity] >= 1000 && [Quantity] < 1500)) * .64) + ((abs([ProductCategory] == 1 && [Quantity] >= 1500 && [Quantity] < 2000)) * .61) + ((abs([ProductCategory] == 1 && [Quantity] >= 2000)) * .58)) * [Quantity]) + (((abs(([ProductCategory] == 1) &&([Quantity] <= 99) &&([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none')))* 5) + ((abs(([ProductCategory] == 1) && ([Quantity] > 99 && [Quantity] <= 199) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 10)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 199 && [Quantity] <= 299) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 15) + ((abs(([ProductCategory] == 1) && ([Quantity] > 299 && [Quantity] <= 399) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 20)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 399 && [Quantity] <= 499) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 25)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 499 && [Quantity] <= 699) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 30)+((abs(([ProductCategory] == 1) && ([Quantity] > 699 && [Quantity] <= 999) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 35)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 999 && [Quantity] <= 1499) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 45)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 1499 && [Quantity] <= 1999) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 55)+((abs(([ProductCategory] == 1) && ([Quantity] > 1999) && ([GH] != 'none' || [GB] != 'none' || [GS1] != 'none' || [GS2] != 'none'))) * 65)) + (((abs(([ProductCategory] == 1) &&([Quantity] <= 99) &&([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none')))* 5) + ((abs(([ProductCategory] == 1) && ([Quantity] > 99 && [Quantity] <= 199) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none')))* 10)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 199 && [Quantity] <= 299) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none')))* 15) + ((abs(([ProductCategory] == 1) && ([Quantity] > 299 && [Quantity] <= 399) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none'))) * 20)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 399 && [Quantity] <= 499) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none'))) * 25)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 499 && [Quantity] <= 699) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none'))) * 30)+((abs(([ProductCategory] == 1) && ([Quantity] > 699 && [Quantity] <= 999) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none')))* 35)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 999 && [Quantity] <= 1499) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none')))* 45)+ ((abs(([ProductCategory] == 1) && ([Quantity] > 1499 && [Quantity] <= 1999) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none'))) * 55)+((abs(([ProductCategory] == 1) && ([Quantity] > 1999) && ([ENV1] != 'none' || [ENV2] != 'none' || [ENV3] != 'none' || [ENV4] != 'none'))) * 65))) || (((abs([ProductCategory] == 11)) * [Price]) * [Quantity]) || ((((abs([ProductCategory] == 2 && [Quantity] <= 1)) * [Price]) + ((abs([ProductCategory] == 2 && [Quantity] >= 2 && [Quantity] < 5)) * 13.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 5 && [Quantity] < 10)) * 12.00) + ((abs([ProductCategory] == 2 && [Quantity] >= 10 && [Quantity] < 20)) * 10.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 20 && [Quantity] < 50)) * 9.00) + ((abs([ProductCategory] == 2 && [Quantity] >= 50 && [Quantity] < 100)) * 7.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 100)) * 6.00)) * [Quantity])
Ray Borduin
03-16-2009, 01:37 PM
There are no obvious problems I can spot.
grantr281040
03-16-2009, 01:40 PM
Thanks for taking a look Ray.
Now I'm really scared....If you can't spot any problems....I'm hosed!
LOL
grantr281040
03-16-2009, 02:08 PM
I think I found WHERE it is happening...but I don't know why???
TruePrice: (This part seems to be OK)
(((abs([ProductCategory] == 1 && [Quantity] <= 49)) * [Price]) + ((abs([ProductCategory] == 1 && [Quantity] >= 50 && [Quantity] < 100)) * 1.38) + ((abs([ProductCategory] == 1 && [Quantity] >= 100 && [Quantity] < 200)) * 1.17) + ((abs([ProductCategory] == 1 && [Quantity] >= 200 && [Quantity] < 300)) * .99) + ((abs([ProductCategory] == 1 && [Quantity] >= 300 && [Quantity] < 400)) * .92) + ((abs([ProductCategory] == 1 && [Quantity] >= 400 && [Quantity] < 500)) * .85) + ((abs([ProductCategory] == 1 && [Quantity] >= 500 && [Quantity] < 700)) * .79) + ((abs([ProductCategory] == 1 && [Quantity] >= 700 && [Quantity] < 1000)) * .71) + ((abs([ProductCategory] == 1 && [Quantity] >= 1000 && [Quantity] < 1500)) * .64) + ((abs([ProductCategory] == 1 && [Quantity] >= 1500 && [Quantity] < 2000)) * .61) + ((abs([ProductCategory] == 1 && [Quantity] >= 2000)) * .58))
BUT WHEN IT HITS THIS PART....BLAMO! Could it be the "OR" syntax???
|| ((abs([ProductCategory] == 11)) * [Price]) || ((abs([ProductCategory] == 2 && [Quantity] <= 1)) * [Price]) + ((abs([ProductCategory] == 2 && [Quantity] >= 2 && [Quantity] < 5)) * 13.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 5 && [Quantity] < 10)) * 12.00) + ((abs([ProductCategory] == 2 && [Quantity] >= 10 && [Quantity] < 20)) * 10.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 20 && [Quantity] < 50)) * 9.00) + ((abs([ProductCategory] == 2 && [Quantity] >= 50 && [Quantity] < 100)) * 7.50) + ((abs([ProductCategory] == 2 && [Quantity] >= 100)) * 6.00)
THANKS!
Ray Borduin
03-16-2009, 02:30 PM
Yes, I think it is the OR... unfortunately DW uses | to separate values in a tree like we use to display columns and calculations.
This is probably the exact problem. I would probably change it back to OR and if you have to, do a find and replace in the cart include to update it after. I think we may have even made it work with OR in anticipation of this problem but I don't remember for sure.
grantr281040
03-16-2009, 02:52 PM
I had the word OR in there to begin with and it didn't seem to work then either. I'll keep working on it and see if I can get it worked out
I really appreciate your help.
In my initial problem I placed in the code and changed the cart name and it seemed to be happy but I am still having a problem with it. As I remember I had this problem when I first made it in CFM and somehow worked it out (Likely with your help)
The TotalDiscount that it is calculating for the "Congratulations!!! Your Volume Discount Savings is..$..." is only being calculated for the first item in the cart. I need it to be the total of all items in the cart.
On my PHP page it looks like this....
<?php
if ($GCcart->TotalColumn("TotalDiscount") > 0) {
?> <span class="style1 style1 style88"><em><strong>Congratulations!!! Your Volume Discount Savings</strong></em><strong></strong><em><strong> is..<span class="style124"></strong></em></span><span class="style133"> <?php echo WA_eCart_DisplayMoney($GCcart, $GCcart->DisplayInfo("TotalDiscount")); ?></span> <span class="style124">
<?php
} else {?> </span><span class="style52 style64 style58"><strong><span class="style78"><br />
<span class="style129">BUY MORE & SAVE!</span></span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
<span class="style126"><br />
Discounts apply to same card purchases only. </span><span class="style125"><br />
<span class="style127">(Change quantity and click on the "Update Cart" button)</span></span></span>
<span class="style125">
<?php
}
?>
</span>
On my Old but working ColdFusion page it looks like this...
<cfif WA_eCart_TotalColumn(CardCart, "TotalDiscount") GT 0>
<br />
<span class="style75 style64"><span class="style54 style76">Congratulations!!! Your Volume Discount <strong>Savings</strong> is... </span></span> <span class="style91">$<cfoutput>#LSCurrencyFormat(WA_eCart_TotalColumn(CardCart, "TotalDiscount"),'none')#</cfoutput>
</span>
<p>
<cfelse>
</p>
<p class="style52 style64 style58"><strong><span class="style78">BUY MORE and SAVE</span><br />
<span class="style75"><span class="style76 style54">Increase your Quantity Now to 50 Cards and Pay Only</span> <span class="style91">$1.38 each </span><span class="style76 style54">!</span><br />
<span class="style76 style54">or get 100 Cards for Only</span> </span><span class="style91">$1.17 each </span><span class="style54 style76"><em>!</em></span></strong><br />
Discounts apply to same card purchases only. <br />
<span class="style81">(Change quantity and click on the "Update Cart" button)</span></p>
</cfif>
Ray Borduin
03-16-2009, 03:15 PM
$GCcart->DisplayInfo("TotalDiscount")
should be:
$GCcart->TotalColumn("TotalDiscount")
grantr281040
03-16-2009, 03:26 PM
Ray......YOU FRICKIN' ROCK!!!
THANKS!
grantr281040
04-02-2009, 10:02 AM
OK...I have another one that I am having a problem with.
We offer our standard envelopes for free. So...
If there is a charge in the envelope column that is greater than zero "> 0", I want it to display the charge.
If the column is equal to zero "== 0" , I want it to display the word "FREE"
So here is what I have:
<?php
if ($CardCart->TotalColumn("EnvUpgrade") > 0) {
?>
<?php echo WA_eCart_DisplayMoney($GCcart, $GCcart->DisplayInfo("EnvUpgrade")); ?>
<?php
} else {
?>
FREE
<?php
}
?>
But it gives me this error:
Fatal error: Call to a member function TotalColumn() on a non-object in C:\xampp\htdocs\IndustryGreetings\shopping_cart.ph p on line 436
line 436 reads:
if ($CardCart->TotalColumn("EnvUpgrade") > 0) {
Thanks!
Grant
Ray Borduin
04-02-2009, 11:56 AM
It should be: GCcart and not CardCart
grantr281040
04-02-2009, 12:22 PM
Dude...I feel like such an idiot when I look over something that obvious!
Thanks for your extra set of eyes. I have one more question.
In another area I want nothing to display if the column "GH" is equal to the word "none" but I can't seem to get that one to work. It just keeps displaying the word "none" It worked in CFM but the if statement was written from a different angle...
<cfif WA_eCart_DisplayInfo(CardCart, "GreetingHead") NEQ "none">#WA_eCart_DisplayInfo(CardCart, "GreetingHead")#</cfif>
So far I have for this I have...
<?php
if ($GCcart->TotalColumn("GH") == "none") {
?>
<?php
} else {
?>
<?php echo $GCcart->DisplayInfo("GH"); ?>
<?php
}
?>
Is there a command I need to put in to PHP that represents nothing or empty?
Thanks,
Grant
Ray Borduin
04-02-2009, 01:31 PM
TotalColumn will concatinate all the values of all of the columns in the cart.... you probably want to use:
if ($GCcart->DisplayInfo("GH") == "none") {
vBulletin® v3.8.1, Copyright ©2000-2012, Jelsoft Enterprises Ltd.