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 03-27-2013 22:50:23

netcoservices
Member
Registered: 04-17-2008
Posts: 91

Shipping Problem

I'm trying to set up a custom shipping method to the US and Canada.  I'm getting the "default shipping error".  Can someone tell me where I made a mistake in the code?

Code:

<?php 

// +--
// | All custom shipping scripts work in the same way.  A global
// | variable named 'ecom.customship' contains the following PHP
// | array.  Array keys with value info:
// |
// | weight        => Total weight of items being shipped.
// | total         => Subtotal of items being shipped.
// | quantity      => Quantity of items being shipped.
// | stateprov     => Ship to state/province.
// | country       => Ship to country.
// | postalcode    => Ship to postal code.
// | rescom        => Ship to residential/commercial status.
// | shipstateprov => Ship origin state/province.
// | shipcountry   => Ship origin country.
// | shipzip       => Ship origin postal code.
// | packages      => An array containing all packages with
// |                  each package defined in it's own array
// |                  with keys: length, width, height, weight.
// | delinfo       => Delivery information array.
// | delitems      => An array containing all items with
// |                  each item id as a key and the item quantity 
// |                  as a value.
// |
// | This script must set a global variable named 
// | 'ecom.customship_response' which is an array in the 
// | following format:
// |
// | method name => amount
// |
// | NOTE: Do not print anything within custom shipping
// | scripts.  They are designed only to return names and 
// | prices for custom shipping methods.
// |
// | This script is a Calculation On Total Item Cost script that
// | returns a prices based on total item cost.
// +--

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

if ($info['country'] == 'United States') {

$method = 'Priority Mail';

if ($info['total'] >= '0' && $info['total'] <= '27.00') {

     $custom = array($method => '4.80');

} elseif ($info['total'] > '27.01' && $info['total'] <= '53.00') {

     $custom = array($method => '7.32');

} elseif ($info['total'] > '53.01' && $info['total'] <= '90.00') {

     $custom = array($method => '10.40');

} elseif ($info['total'] > '90.01' && $info['total'] <= '120.00') {

     $custom = array($method => '14.11');

} elseif ($info['total'] > '120.01' && $info['total'] <= '140.00') {

     $custom = array($method => '15.68');

} elseif ($info['total'] > '140.01' && $info['total'] <= '180.00') {

     $custom = array($method => '18.81');



} elseif ($info['country'] == 'Canada') {

    $method         = 'Priority Mail';

if ($info['total'] >= '0' && $info['total'] <= '27.00') {

     $custom = array($method => '12.50');

} elseif ($info['total'] > '27.01' && $info['total'] <= '53.00') {

     $custom = array($method => '14.00');

} elseif ($info['total'] > '53.01' && $info['total'] <= '90.00') {

     $custom = array($method => '17.00');

} elseif ($info['total'] > '90.01' && $info['total'] <= '120.00') {

     $custom = array($method => '21.50');

} elseif ($info['total'] > '120.01' && $info['total'] <= '140.00') {

     $custom = array($method => '23.00');

} elseif ($info['total'] > '140.01' && $info['total'] <= '180.00') {

     $custom = array($method => '26.00');

} else {

     $custom = array($method => '0.00');

} // End of if statement.

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

?>

In advance, I really appreciate the help.

Offline

 

#2 03-28-2013 03:15:15

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

Re: Shipping Problem

You had a syntax error in what you posted and the logic would not have gotten you the results you wanted.  Try this:

Code:

<?php

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

if ($info['country'] == 'United States') {
    $method = 'Priority Mail';
    if ($info['total'] >= '0' && $info['total'] <= '27.00') {
        $custom = array($method => '4.80');
    } elseif ($info['total'] > '27.01' && $info['total'] <= '53.00') {
        $custom = array($method => '7.32');
    } elseif ($info['total'] > '53.01' && $info['total'] <= '90.00') {
        $custom = array($method => '10.40');
    } elseif ($info['total'] > '90.01' && $info['total'] <= '120.00') {
        $custom = array($method => '14.11');
    } elseif ($info['total'] > '120.01' && $info['total'] <= '140.00') {
        $custom = array($method => '15.68');
    } elseif ($info['total'] > '140.01' && $info['total'] <= '180.00') {
        $custom = array($method => '18.81');
    }
} elseif ($info['country'] == 'Canada') {
    $method = 'Priority Mail';
    if ($info['total'] >= '0' && $info['total'] <= '27.00') {
        $custom = array($method => '12.50');
    } elseif ($info['total'] > '27.01' && $info['total'] <= '53.00') {
        $custom = array($method => '14.00');
    } elseif ($info['total'] > '53.01' && $info['total'] <= '90.00') {
        $custom = array($method => '17.00');
    } elseif ($info['total'] > '90.01' && $info['total'] <= '120.00') {
        $custom = array($method => '21.50');
    } elseif ($info['total'] > '120.01' && $info['total'] <= '140.00') {
        $custom = array($method => '23.00');
    } elseif ($info['total'] > '140.01' && $info['total'] <= '180.00') {
        $custom = array($method => '26.00');
    }
}  // end of elseif country is Canada

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

Last edited by Dave (03-28-2013 03:15:36)

Offline

 

#3 03-28-2013 10:00:46

netcoservices
Member
Registered: 04-17-2008
Posts: 91

Re: Shipping Problem

That worked.  Thanks very much.

Offline

 

Board footer