Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Change the Qty Available from Numerical to Text

Change the Qty Available from Numerical to Text

Locked

Views: 2,304

Results 21 to 31 of 31
This thread is locked. New replies are disabled.
8 Mar 2010, 2:05 AM
#21
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Change the Qty Available from Numerical to Text

Mike_Dean:

This is what I ended up with

<?php $products_out = $products_quantity ; if ($products_out == 9999) $products_out = 'Thanks Rod, you did it'; if ($products_out == 7777) $products_out = '7-10 Days';

Sorry to tell you this, but I have just identified a possible problem. For this to work you'll need to disable the stock control, because if someone buys one of these products their counts will also be reduced and the comparisons will fail.

If you do wish to maintain stock control then the following modification will probably work:

<?php $products_out = $products_quantity ; if ($products_out >= 9000) $products_out = 'Thanks Rod, you did it'; if ($products_out >= 8000) $products_out = '7-10 Days'; You'll then need to initialise the product quantities to 9999 & 8999, etc, This will allow you to sell up to 1000 of each of these items before it starts to output the wrong information. As long as you reset the quantitys back to 9999, 8999, etc before the 1000 are sold you'll have no problem. Another solution would be to identify the code that decrements the product_quantity field and prevent it from occuring if it is one of these 'special' quantities. Cheers Rod
8 Mar 2010, 2:11 AM
#22
mike_dean avatar

mike_dean

Totally Zenned

Join Date:
Feb 2006
Location:
Central Coast, NSW, Australia
Posts:
531
Plugin Contributions:
0

Re: Change the Qty Available from Numerical to Text

Hey Rod,

I had actually thought of the stock control and the initial thought was to turn it off so as not to have the problem you identified..... Which actually defeats the purpose of displaying stock counts in the first place..

So once I get my easy populate mod working as it should, I'll come back to this and amend the code as suggested..

Cheers,
Mike

8 Mar 2010, 1:58 PM
#23
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Change the Qty Available from Numerical to Text

With a >= test, each successive test as shown will reset the output if the first one is true. You want it to stop testing if it gets a positive, so a switch may be best.```php

<?php $products_out = $products_quantity; switch (true){ case ($products_out >= 9000): $products_out = 'Thanks Rod, you did it'; break; case ($products_out >= 8000): $products_out = '7-10 Days'; break; } ```
8 Mar 2010, 2:55 PM
#24
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Change the Qty Available from Numerical to Text

gjh42:

With a >= test, each successive test as shown will reset the output if the first one is true. You want it to stop testing if it gets a positive, so a switch may be best.```php

<?php $products_out = $products_quantity; switch (true){ case ($products_out >= 9000): $products_out = 'Thanks Rod, you did it'; break; case ($products_out >= 8000): $products_out = '7-10 Days'; break; } ``` I agree, a switch/case structure is the preferred coding method in this case, but I thought it best to use the method that Mike appeared most familiar with :smile: As for "each successive test as shown will reset the output if the first one is true", this is true, but it still has the desired affect (as long as Mike remembers to test the highest numbers first and progress to the lower ones. It wasn't just luck that I opted for ">=" rather than "<=" :yes: Anyway, since we are now discussing code efficiency, This is better still: switch ($products_out) { case >= 9000: $products_out = 'Thanks Rod, you did it'; break; case >= 8000: $products_out = '7-10 Days'; break; } Cheers Rod. ps. Mike - If you are following/understanding all of this, great.. if not just use what you know best. It's all 'good'.
8 Mar 2010, 4:12 PM
#25
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Change the Qty Available from Numerical to Text

(If >= 9000 is true, then >=8000 will also be true, so the end result is the lowest tested setting for the successive if() tests as first described. These tests would need to be in low-to-high order to work correctly.)
Your statement of the switch is most efficient.

9 Mar 2010, 3:06 AM
#26
mike_dean avatar

mike_dean

Totally Zenned

Join Date:
Feb 2006
Location:
Central Coast, NSW, Australia
Posts:
531
Plugin Contributions:
0

Re: Change the Qty Available from Numerical to Text

RodG:

I agree, a switch/case structure is the preferred coding method in this case, but I thought it best to use the method that Mike appeared most familiar with :smile:

As for "each successive test as shown will reset the output if the first one is true", this is true, but it still has the desired affect (as long as Mike remembers to test the highest numbers first and progress to the lower ones.

It wasn't just luck that I opted for ">=" rather than "<=" :yes:

Anyway, since we are now discussing code efficiency, This is better still:

switch ($products_out) {
case >= 9000:
$products_out = 'Thanks Rod, you did it';
break;
case >= 8000:
$products_out = '7-10 Days';
break;
}

Cheers
Rod.

ps. Mike - If you are following/understanding all of this, great.. if not just use what you know best. It's all 'good'.

Thanks guys....

I am beginning to see that coding in php is a "little" similar to excel and formulas etc..

Its just knowing where to put the code, but you guys have been tremendous and I am actually picking alot up..

I will experiment a little more to see which is going to be a) easiest to implement and b) managed..

Cheers,
Mike

9 Mar 2010, 8:19 AM
#27
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Change the Qty Available from Numerical to Text

gjh42:

(If >= 9000 is true, then >=8000 will also be true, so the end result is the lowest tested setting for the successive if() tests as first described. These tests would need to be in low-to-high order to work correctly.)

OK, so which one of you swapped my 9 & 8 keys around? :D

Ch33rs
R0d

9 Mar 2010, 8:34 AM
#28
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Change the Qty Available from Numerical to Text

Mike_Dean:

Thanks guys....

I am beginning to see that coding in php is a "little" similar to excel and formulas etc..

Most languages have the same basic control structures.

Mike_Dean:

Its just knowing where to put the code,

With any complex system this is always the most difficult part.

Mike_Dean:

but you guys have been tremendous and I am actually picking alot up..

That's always good to hear.

Mike_Dean:

I will experiment a little more to see which is going to be a) easiest to implement and b) managed..

Although there are no strict rules. if there are only 2 or 3 "if" statements required then that is probably the way to go, but anything more than this then the switch/case structure is easier to read, easier to maintain, and most likely to do exactly what you want it to do and nothing more.

In fact, when developing *new code I'll almost always start out with the "If" comparison and then change it to the switch/case structure once I've reached my 3rd or 4th 'if'.

Cheers
Rod

  • ad-hoc methology
10 Mar 2010, 9:37 AM
#29
mike_dean avatar

mike_dean

Totally Zenned

Join Date:
Feb 2006
Location:
Central Coast, NSW, Australia
Posts:
531
Plugin Contributions:
0

Re: Change the Qty Available from Numerical to Text

gjh42:

With a >= test, each successive test as shown will reset the output if the first one is true. You want it to stop testing if it gets a positive, so a switch may be best.```php

<?php $products_out = $products_quantity; switch (true){ case ($products_out >= 9000): $products_out = 'Back-to-Back Orders'; break; case ($products_out >= 8000): $products_out = 'Stock Available'; break; case ($products_out >= 7000): $products_out = '7-10 Days'; break; } ``` Hi Guys, This one seems to be the that I will probably use. (above) The latter one, *switch ($products_out) { case >= 9000: $products_out = 'Thanks Rod, you did it'; break; case >= 8000: $products_out = '7-10 Days'; break; } * broke the page, eg the info page would not display.. So I was not going to spend too long on it, as I have a few other projects that still need to be completed before I can fully implement this.. I will come back to it after though as I want to take it one step further and use the ETA that some suppliers provide. Cheers, Mike
10 Mar 2010, 10:49 AM
#30
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Change the Qty Available from Numerical to Text

Mike_Dean:

The latter one,

*switch ($products_out) {
case >= 9000:
$products_out = 'Thanks Rod, you did it';
break;
case >= 8000:
$products_out = '7-10 Days';
break;
}
*

broke the page,

I suspect you missed this line:
<?php $products_out = $products_quantity;

Cheers
Rod

10 Mar 2010, 11:21 AM
#31
mike_dean avatar

mike_dean

Totally Zenned

Join Date:
Feb 2006
Location:
Central Coast, NSW, Australia
Posts:
531
Plugin Contributions:
0

Re: Change the Qty Available from Numerical to Text

RodG:

I suspect you missed this line:
<?php $products_out = $products_quantity;

Cheers
Rod

:blush::blush::blush::blush: :oops: (next stop... Optometrist)

Cheers,