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.

#1 10-04-2017 14:35:22

polarize
Member
Registered: 11-15-2004
Posts: 293

Custom Shipping Script - Discounting Selected States

Hello,

We are using a custom shipping script for USPS and UPS and would like to figure out what is needed for return shipping cost results that reside in certain states that we can program a shipping discount by percentage to help the customer out on far away extensive shipping costs.  we figured this might be easiest determined by state rather than zip code if this is possible. Please advise...

Code:

<?php 

$info               = $this->globals('ecom.customship');
$custom             = array();
$usps_weight_cutoff = 51;

$shipmethod         = 'USPS, UPSTOOLS';

if ($info['weight'] >= $usps_weight_cutoff) {$shipmethod = 'UPSTOOLS';}

//
// Static Ship Price Lookup
// 

$DB =& $this->quick_object('CORE_DB','core','CORE_DB_1');

if (!(empty($info['delitems']))) {

     $sql = 'SELECT id, shiponename, shiponeprice, shiptwoname, shiptwoprice, shipthreename, shipthreeprice FROM ecom_prod WHERE ';

     foreach ($info['delitems'] as $diid => $diquan) {$sql .= 'id=' . $DB->quote($diid) . ' OR ';}

     $sql = preg_replace('/ OR $/','',$sql);

     $res = $DB->sql_do(array('table' => 'ecom_prod', 'sql' => $sql, 'order' => array('id' => 'ASC')));

     if ((!($this->isError($res))) && (!(empty($res)))) {

          foreach ($res as $num => $data) {

               // ShipOnePrice

               if ((!(empty($data['shiponename']))) && ($data['shiponeprice'] > 0) && (!(empty($info['delitems'][$data['id']])))) {

                    if (!(isset($custom[$data['shiponename']]))) {$custom[$data['shiponename']] = 0;} 

                    $custom[$data['shiponename']] += ($data['shiponeprice'] * $info['delitems'][$data['id']]);

               } // End of if statement.

               // ShipTwoPrice

               if ((!(empty($data['shiptwoname']))) && ($data['shiptwoprice'] > 0) && (!(empty($info['delitems'][$data['id']])))) {

                    if (!(isset($custom[$data['shiptwoname']]))) {$custom[$data['shiptwoname']] = 0;} 

                    $custom[$data['shiptwoname']] += ($data['shiptwoprice'] * $info['delitems'][$data['id']]);

               } // End of if statement.

               // ShipThreePrice

               if ((!(empty($data['shipthreename']))) && ($data['shipthreeprice'] > 0) && (!(empty($info['delitems'][$data['id']])))) {

                    if (!(isset($custom[$data['shipthreename']]))) {$custom[$data['shipthreename']] = 0;} 

                    $custom[$data['shipthreename']] += ($data['shipthreeprice'] * $info['delitems'][$data['id']]);

               } // End of if statement.

          } // End of foreach statement.

     } // End of fif statement.

} // End of if statement.

//
// Realtime 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'   => $shipmethod,
                 'shiptype'      => 'R');

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

foreach ($result as $num => $service) {

     if (preg_match('/UPS/',$service['name'])) {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.00);

     } else {

          $custom[$service['name']] = $service['amount'] + ($service['amount'] * 0.00);

     } // End of if statement.

} // End of if statement.

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

?>

Using Kryptronic K9! smile
Previous Versions:
ClickCartPro 8
ClickCartPro 7
ClickCartPro 6
ClickCartPro 5.1

Offline

 

#2 10-05-2017 08:05:58

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19798
Website

Re: Custom Shipping Script - Discounting Selected States

Sure, you can do that.  Looks like you're doing a product table lookup and adding all the positive shipone/shiptwo/shipthree methods as well as doing a realtime call to either UPS and USPS or UPS only.


Nick Hendler

Offline

 

Board footer