Forums / General Questions / exclude shipping module from being auto selected as cheapest

exclude shipping module from being auto selected as cheapest

Views: 1,186

Results 1 to 7 of 7
2 Sep 2014, 11:08 PM
#1
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

exclude shipping module from being auto selected as cheapest

I started to use the flat rate shipping module along side UPS, FedEx, USPS and store pickup. Is there a way to exclude the flat rate module from being auto selected as cheapest. I just want UPS FedEx and USPS to be the modules zen cart looks at for auto selection. Store pickup is ignored not sure if that is by default or I did something in the past for that to work like it does.

So basically zen cart should ignore store pickup (as it already is) and the flat rate module and look at only UPS, FedEx and USPS and out of those three whomever is cheapest auto select it.

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

2 Sep 2014, 11:36 PM
#2
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: exclude shipping module from being auto selected as cheapest

I think I found where to do it just do not know how to code it:

file: includes/classes/shipping.php

      $cheapest = false;
      $size = sizeof($rates);
      for ($i=0; $i<$size; $i++) {
        if (is_array($cheapest)) {
          // never quote storepickup as lowest - needs to be configured in shipping module
          if (($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') || $size == 1) { // modified by Numinix for FEC
            $cheapest = $rates[$i];
          }
        } else {
          if ($rates[$i]['module'] != 'storepickup' || $size == 1) { // modified by Numinix for FEC
            $cheapest = $rates[$i];
          }
        }
      }
      $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
      return $cheapest;
    }
  }
}

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

3 Sep 2014, 12:00 AM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: exclude shipping module from being auto selected as cheapest

I did not test this, but you could try:

          if (($rates[$i]['cost'] < $cheapest['cost'] and ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat'))) || $size == 1) { // modified by Numinix for FEC

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

3 Sep 2014, 12:30 AM
#4
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: exclude shipping module from being auto selected as cheapest

Hello Ajeh,

Thank you I tried it but it is still selecting flat rate?

I had to change the code slightly to get it to run I think you just had a typo moved "))" those over. Here is what ran but still did not work.

if (($rates[$i]['cost'] < $cheapest['cost'] and ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat' || $size == 1))) { // modified by Numinix for FEC

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

3 Sep 2014, 12:34 AM
#5
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: exclude shipping module from being auto selected as cheapest

ok got it to work with this:

      $cheapest = false;
      $size = sizeof($rates);
      for ($i=0; $i<$size; $i++) {
        if (is_array($cheapest)) {
          // never quote storepickup as lowest - needs to be configured in shipping module
		  if (($rates[$i]['cost'] < $cheapest['cost'] and ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat' || $size == 1))) { // modified by Numinix for FEC
            $cheapest = $rates[$i];
          }
        } else {
          if ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat' || $size == 1) { // modified by Numinix for FEC
            $cheapest = $rates[$i];
          }
        }
      }
      $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
      return $cheapest;
    }
  }
}

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

3 Sep 2014, 12:41 AM
#6
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: exclude shipping module from being auto selected as cheapest

Thanks again for your help!

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14

27 Apr 2016, 6:58 PM
#7
marcopolo avatar

marcopolo

Totally Zenned

Join Date:
May 2008
Location:
United States
Posts:
522
Plugin Contributions:
2

Re: exclude shipping module from being auto selected as cheapest

 $cheapest = false; 
      $size = sizeof($rates); 
      for ($i=0; $i<$size; $i++) { 
        if (is_array($cheapest)) { 
          // never quote storepickup as lowest - needs to be configured in shipping module 
          if (($rates[$i]['cost'] < $cheapest['cost'] and ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat' || $size == 1))) { // modified by Numinix for FEC 
            $cheapest = $rates[$i]; 
          } 
        } else { 
          if ($rates[$i]['module'] != 'storepickup' && $rates[$i]['module'] != 'flat' || $size == 1) { // modified by Numinix for FEC 
            $cheapest = $rates[$i]; 
          } 
        } 
      } 
      $this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest); 
      return $cheapest; 
    } 
  } 
}  

I need to modify the above code to exclude two services OF a particular shipping module. These are SurePost and are usually always cheaper however not everyone might want to use it since the transit days can be more.

The shipping module name is upswebservices.php
Here are the two service codes: $rateReply->Service->Code == 92 || $rateReply->Service->Code == 93

Any help would be appreciated!

marcopolo
Zen Cart 2.2.2 | PHP 8.5.11 | MariaDB 10.11.14