Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

  • Index
  •  » ClickCartPro 6
  •  » shipping - flat rate per province but charge extra if necessary?

#1 06-29-2009 10:10:48

wyattea
Member
Registered: 01-07-2006
Posts: 1650

shipping - flat rate per province but charge extra if necessary?

I'd like to charge a flat rate per province. I have the code for that already from another shipping script I used for a particular customer. What'd I'd like to do is turn set it up for all customers but modify it so that it always charges $3 above the real-time rate (or no less than the flat rate). For example, if the real time rate is $7 but the flat rate in that province is $12, it'll charge $12. But if a different address in that province is $13, it'll charge $16 instead of $12.

Code:

<?php 

// +--
// | This script charges flat rate but verifies real-time rate is not higher - charges higher of the two
// +--

$app = $this->globals('khxc.app');
$info = $this->globals('ecom.customship');

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'FEDEX',
                 'shiptype'      => 'R');

$result = $this->include_namespace($app,'shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     if ($service['transit'] > 0) {
         $custom[$service['name'] . ' - Transit Time - ' .  $service['transit'] . ' Business Day(s) (Mon-Fri Only)'] = $service['amount'];

} else {
         $custom[$service['name']] = $service['amount'];
     }
 }

$this->globals('ecom.customship_response',$custom);

// Declare the variables for flat rate shipping per province

  $quantity = $info['quantity'];

  $ship_meth_name = 'FedEx Ground to ON-QC - $11.99';
  $ship_total = (11.99 * $quantity);
  $ship_meth_name1 = 'FedEx Ground to MB-SK - $14.99';
  $ship_total1 = (14.99 * $quantity);
  $ship_meth_name2 = 'FedEx Ground to AB-BC - $16.99';
  $ship_total2 = (16.99 * $quantity);
  $ship_meth_name3 = 'FedEx Ground to Marit. - $17.99';
  $ship_total3 = (17.99 * $quantity);

// Setup the array

if ($info['stateprov'] == 'Ontario' || $info['stateprov'] == 'Quebec') {
   $custom = array($ship_meth_name => $ship_total);
 }     

elseif ($info['stateprov'] == 'Manitoba' || $info['stateprov'] == 'Saskatchewan') {          
   $custom = array($ship_meth_name1 => $ship_total1);
 }

elseif ($info['stateprov'] == 'Alberta' || $info['stateprov'] == 'British Columbia') {          
   $custom = array($ship_meth_name2 => $ship_total2);
 }

else {

   $custom = array($ship_meth_name3 => $ship_total3);

 }  // Close if loop

$this->globals('ecom.customship_response',$custom);

?>

I'm getting a bit lost. I put two scripts together, but I'm not sure how to check the price (flat rate) against the real-time rate. Any suggestions?

James...

Offline

 

#2 06-29-2009 10:13:44

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: shipping - flat rate per province but charge extra if necessary?

I'm looking at it again, and realized it needs to only check the first real-time rate (fedex ground) and not all of the services returned (only ever two - ground and overnight).

Offline

 

#3 06-29-2009 10:29:13

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: shipping - flat rate per province but charge extra if necessary?

If you're sure it will always and forever by the first real-time rate the variable $result[0]['amount'] will contain the first real-time rate returned after the call to retrieve the real-time rates.

Offline

 

#4 07-02-2009 06:29:01

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: shipping - flat rate per province but charge extra if necessary?

Dave, I think I understand the logic, here's wha I wrote. Seems a bit convoluted though:

Code:

<?php 

// +--
// | This script charges flat rate but verifies real-time rate is not higher - charges higher of the two
// +--

$app = $this->globals('khxc.app');
$info = $this->globals('ecom.customship');


// Declare the variables for flat rate shipping per province

  $quantity = $info['quantity'];

  $ship_meth_name = 'FedEx Ground to ON-QC - $11.90';
  $ship_total = (11.90 * $quantity);
  $ship_meth_name1 = 'FedEx Ground to MB-SK - $14.90';
  $ship_total1 = (14.90 * $quantity);
  $ship_meth_name2 = 'FedEx Ground to AB-BC - $16.90';
  $ship_total2 = (16.90 * $quantity);
  $ship_meth_name3 = 'FedEx Ground to Marit. - $17.90';
  $ship_total3 = (17.90 * $quantity);

// Setup the array

if ($info['stateprov'] == 'Ontario' || $info['stateprov'] == 'Quebec') {
   $customf = array($ship_meth_name => $ship_total);
 }     

elseif ($info['stateprov'] == 'Manitoba' || $info['stateprov'] == 'Saskatchewan') {          
   $customf = array($ship_meth_name1 => $ship_total1);
 }

elseif ($info['stateprov'] == 'Alberta' || $info['stateprov'] == 'British Columbia') {          
   $customf = array($ship_meth_name2 => $ship_total2);
 }

else {

   $customf = array($ship_meth_name3 => $ship_total3);

 }  // Close if loop

// Setup real-time rates 

$delinfo = array('stateprov'     => $info['stateprov'],
                 'country'       => $info['country'],
                 'postalcode'    => $info['postalcode'],
                 'rescom'        => $info['rescom'],
                 'shipstateprov' => $info['shipstateprov'],
                 'shipcountry'   => $info['shipcountry'],
                 'shipzip'       => $info['shipzip'],
                 'shipmethods'   => 'FEDEX',
                 'shiptype'      => 'R');

$result = $this->include_namespace($app,'shiprealtime',array('delinfo'  => $delinfo, 'packages' => $info['packages']));

foreach ($result as $num => $service) {
     if ($service['transit'] > 0) {
         $custom[$service['name'] . ' - Transit Time - ' .  $service['transit'] . ' Business Day(s) (Mon-Fri Only)'] = $service['amount'];

} else {
         $custom[$service['name']] = $service['amount'];
     }
 }

// Check and compare against that rate and province to determine which is higher


if (($info['stateprov'] == 'Ontario' || $info['stateprov'] == 'Quebec') && ($result[0]['amount'] < 9.91)) {

               $this->globals('ecom.customship_response',$customf);

} elseif (($info['stateprov'] == 'Manitoba' || $info['stateprov'] == 'Saskatchewan') && ($result[0]['amount'] < 12.91)) {

               $this->globals('ecom.customship_response',$customf);

} elseif (($info['stateprov'] == 'Alberta' || $info['stateprov'] == 'British Columbia') && ($result[0]['amount'] < 14.91)) {

               $this->globals('ecom.customship_response',$customf);

} else {

               $this->globals('ecom.customship_response',$custom);

}

?>

Basically, it creates the array of flat rates based on which province is being shipped to. Then it pulls real-time rate for that delivery addres. My if statements check the province and the if the real-time rate is less than the flat rate - if so, it assigns ecom_customship_response. I use '$customf to differentiate between $custom. 'f' means it's the flat rate.

For my flat rates, my else statement is used for all of the maritme provinces. I'll have to actually test all of the actual province names but I figured I'd check if this is making sense or whether there's an easier way than what I'm doing before I do that.

Also, the test is for basically $2 less than the flat rate because I'll setup real-time rates with a $2 handling fee.

Your thoughts?

Regards,

James...

Last edited by wyattea (07-02-2009 06:31:04)

Offline

 

#5 07-02-2009 07:37:19

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: shipping - flat rate per province but charge extra if necessary?

The logic looks OK James.  As you said though you'll want to test it thoroughly before deploying it.

Offline

 

#6 07-02-2009 19:07:14

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: shipping - flat rate per province but charge extra if necessary?

Hi Dave, I just tested it and it works! But I haven't tested it with a bunch of postal codes yet (will do).

Can you help me incorporate the transit time into the code? Here's how it looks with regular real-time shipping rates:

Code:

Delivery Method & Estimate
FedEx Ground - Transit Time - 1 Business Day(s) (Mon-Fri Only excl. Holidays) - $9.87

Here's how it looks with a product using the script to charge the higher of flat or real:

Code:

Delivery Method & Estimate
FedEx Ground to ON-QC - $11.90 - $11.90

I don't believe I can add to the line above because it's created before the real-time rate is pulled but what about appending the transit info so it is a 2nd line?

Offline

 

#7 07-03-2009 05:56:55

wyattea
Member
Registered: 01-07-2006
Posts: 1650

Re: shipping - flat rate per province but charge extra if necessary?

I tried this, but it didn't work. I'm getting lost with the variable/array names.

Code:

if (($info['stateprov'] == 'Ontario' || $info['stateprov'] == 'Quebec') && ($result[0]['amount'] < 9.91) && ($custom[$service['name']] == 'FedEx 

Ground')) {

                $customf = $customf . ' - Transit Time - ' . $service['transit'] . ' Business Day(s) (Mon-Fri Only)';            

               $this->globals('ecom.customship_response',$customf);

} elseif

Any ideas?


James...

Last edited by wyattea (07-03-2009 05:57:16)

Offline

 

#8 07-03-2009 08:12:32

Dave
Member
Registered: 07-05-2003
Posts: 11233

Re: shipping - flat rate per province but charge extra if necessary?

The transit time component is added to the textual response coming back from the real time calculation.  It isn't stored separately so it would be very difficult to extract just that value. You'd need to rework the logic that stores the time and put it in some other variable so you may use it later to build up the response string.

Offline

 
  • Index
  •  » ClickCartPro 6
  •  » shipping - flat rate per province but charge extra if necessary?

Board footer