Zen Cart Logo
Forums / General Questions / Display or not to display - compare two countries

Display or not to display - compare two countries

Views: 802

Results 1 to 9 of 9
2 Aug 2013, 2:56 PM
#1
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Display or not to display - compare two countries

Goal: To display Insurance Variable on a custom slip. Though I'd like to see if Brazil or Mexico are the delivery_country to display or not.
Basically the order has to be over $400 and not Brazil or Mexico.

This works for 1 country:

if (strtoupper($order_check->fields['delivery_country']) != 'BRAZIL' && $order_check->fields['order_total'] > 400) {
    echo $ins;	
} 
  else {
// do nothing
}
?>

This does not work with OR on 2 countries:

if (strtoupper($order_check->fields['delivery_country']) != 'BRAZIL' || strtoupper($order_check->fields['delivery_country']) != 'MEXICO' && $order_check->fields['order_total'] > 400) {
    echo $ins;	
} 
  else {
// do nothing
}
?>

How does it work for both countries to not equal the statement? I tried a couple different routes and am stuck.

3 Aug 2013, 6:51 AM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Display or not to display - compare two countries

Try this

if ( strtoupper($order_check->fields['delivery_country']) != 'BRAZIL' && strtoupper($order_check->fields['delivery_country']) != 'MEXICO' && $order_check->fields['order_total'] > 400) {
    echo $ins;    
} 
  else {
// do nothing
}
?>  
3 Aug 2013, 8:55 AM
#3
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Display or not to display - compare two countries

Hmmm ....

try this one

if ((strtoupper($order_check->fields['delivery_country']) != 'BRAZIL') || (strtoupper($order_check->fields['delivery_country']) != 'MEXICO') && $order_check->fields['order_total'] > 400) {
    echo $ins;    
} 
  else {
// do nothing
}
?> 
3 Aug 2013, 9:11 AM
#4
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Display or not to display - compare two countries

frank18:

Hmmm ....

try this one

if ((strtoupper($order_check->fields['delivery_country']) != 'BRAZIL') || (strtoupper($order_check->fields['delivery_country']) != 'MEXICO') && $order_check->fields['order_total'] > 400) {
echo $ins;
}
else {
// do nothing
}
?>

Nope, needs the && like I mentioned before.  If the delivery country is not Brazil AND it's not Mexico AND the total is more than $400 then ...
3 Aug 2013, 9:25 AM
#5
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Display or not to display - compare two countries

lat9:

Nope, needs the && like I mentioned before. If the delivery country is not Brazil AND it's not Mexico AND the total is more than $400 then ...

Criteria of the poster:

Though I'd like to see if Brazil or Mexico are the delivery_country to display or not.

me thinks: (If the delivery country is not Brazil OR it's not Mexico) AND the total is more than $400 then ...

3 Aug 2013, 9:49 AM
#6
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Display or not to display - compare two countries

frank18:

me thinks: (If the delivery country is not Brazil OR it's not Mexico) AND the total is more than $400 then ...

correction: (If (the delivery country is not Brazil OR it's not Mexico) AND the total is more than $400**)** then ...

3 Aug 2013, 1:06 PM
#7
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,100
Plugin Contributions:
56

Re: Display or not to display - compare two countries

I can see that this is turning into "logic war":blush: If parentheses were used in speech, the OP's statement would have been

Basically the order has to be over $400 and not (Brazil or Mexico).

I used De Morgan's laws (http://en.wikipedia.org/wiki/De_Morgan%27s_laws) to 'twist' this into a comparison using != and &&.

Using the following as the logical test

(If (the delivery country is not Brazil OR it's not Mexico) AND the total is more than $400)

the clause would pass WHENEVER the total is more than $400. If the delivery country is Brazil, then it's not Mexico (and vice versa).

5 Aug 2013, 1:54 PM
#8
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Re: Display or not to display - compare two countries

Thanks to the both of you! Ended up I was able to take both your helpful roads and complete the whole thing.

If not both Brazil AND Mexico and over $400, $ins
If either Brazil OR Mexico and over $300, $ins

All works perfectly! Thanks for the collaborative effort!

<?php 
  if (strtoupper($order_check->fields['delivery_country']) != 'BRAZIL' && strtoupper($order_check->fields['delivery_country']) != 'MEXICO' && $order_check->fields['order_total'] > 400) {
    echo $ins;	
} 
  else {
// do nothing  
}
?>
<?php 
  if (strtoupper($order_check->fields['delivery_country']) == 'BRAZIL' || strtoupper($order_check->fields['delivery_country']) == 'MEXICO' && $order_check->fields['order_total'] > 300) {
    echo $ins;	
} 
  else {
// do nothing  
}
?>

With this code, the shipper easily knows to include insurance instead of listing the order totals, eyeballing and making a decision.
We have a custom super_invoice. Since most of our orders are 10 items or less, we double up on one page now. The bottom half is for our internal picking/shipping and the top half is for customers. We are now saving A LOT on paper compared to printing two pages for each order.

5 Aug 2013, 9:06 PM
#9
frank18 avatar

frank18

Deceased

Join Date:
Nov 2007
Location:
Sunny Coast, Australia
Posts:
3,427
Plugin Contributions:
2

Re: Display or not to display - compare two countries

sbbemn:

Thanks to the both of you! Ended up I was able to take both your helpful roads and complete the whole thing.

If not both Brazil AND Mexico and over $400, $ins
If either Brazil OR Mexico and over $300, $ins

All works perfectly! Thanks for the collaborative effort!

Pleasure (always thought that there is something like being 'half right' :P)

Congrats also to your paper saving efforts.

Cheers / Frank