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 02-13-2009 18:08:25

Guest85
Member
Registered: 05-29-2008
Posts: 21

Custom Shipping Script Help

I'm trying to add \n\r or a <br /> but it's not working.

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 User Defined Calculation script that
// | returns a static method and amount.
// +--

// | Default code provided by CCP

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

//$custom = array('Standard Carrier' => '10.00');

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

// | End of Default

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

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

$custom['Customer Pickup - \n\rYou will be notified if an item is Out of Stock'] = '0.00';

foreach ($result as $num => $service) {$custom[$service['name']] = $service['amount'];

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

} // End of if statement.

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

?>

Offline

 

#2 02-13-2009 18:31:20

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

Re: Custom Shipping Script Help

Formatting of the service isn't supported or allowed.

Offline

 

#3 02-13-2009 18:48:33

Guest85
Member
Registered: 05-29-2008
Posts: 21

Re: Custom Shipping Script Help

1. Is there a way to add another row on that checkout page. This way I can add an asterix like Customer Pickup*. Then have another section below that states what the asterix is for.

2. Is there a way to have a specific shipping option always selected as default? For example, "UPS Ground". We have UPS and the Customer Pickup associated with ALL products but the Customer Pickup is selected at top because the shipping options are sorted in asc.

3. Is it possible to apply css to the Customer Pickup option only?

Thanks for your assistance.

Offline

 

#4 02-13-2009 18:59:45

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

Re: Custom Shipping Script Help

Guest85 wrote:

1. Is there a way to add another row on that checkout page. This way I can add an asterix like Customer Pickup*. Then have another section below that states what the asterix is for.

The "Checkout Form Footer" include in admin under Home > ClickCartPro > Displays: Skins, Menus, XHTML Includes and Messages > Manage XHTML Includes might be a good place to add something such as you describe.

Guest85 wrote:

2. Is there a way to have a specific shipping option always selected as default?

Shipping options are always ordered least expensive to most expensive.  There are no options available to specify the order they are shown or which one is selected by default.

Guest85 wrote:

3. Is it possible to apply css to the Customer Pickup option only?

Sorry no, there isn't.

Offline

 

#5 02-13-2009 19:05:54

Guest85
Member
Registered: 05-29-2008
Posts: 21

Re: Custom Shipping Script Help

Thanks for the quick reply Dave.

I can change the sort order from least expensive to most expensive and the opposite most expensive to least expensive. Is there a way to have an exception? Like least expensive to most expensive except a shipping option that equals 0.00 (Customer Pickup) place at the bottom?

I was thinking it could be done here and maybe someone has tried it. Otherwise I'll have to go with what I have for now and continue learning.

Code:

// +--
// | Work with our shipinfo array.  We want to sort the options
// | by their prices.
// +--

if (!(empty($shipinfo))) {

     $xshipinfo = array();

     foreach ($shipinfo as $group => $options) {

          $zshipinfo = array();

          foreach ($options as $key => $data) {

               $zshipinfo[$key] = $data['amount'];

          } // End of foreach statement.

          asort($zshipinfo,SORT_NUMERIC);

          foreach ($zshipinfo as $key => $amount) {

               $xshipinfo[$group][] = $options[$key];

          } // End of foreach statement.

     } // End of if statement.

     $shipinfo = $xshipinfo;

     if ($this->debug) {$this->debugger("coship: Sorted all shipping options by amount.");}

} // End of if statement.

// +--
// | Set up the first option as selected.  This may be
// | overridden in checkout later.
// +--

if (!(empty($shipinfo))) {

     foreach ($shipinfo as $group => $options) {

          $selected = 0;

          foreach ($options as $key => $data) {

               if (empty($selected)) {$shipinfo[$group][$key]['selected'] = 1; $selected++;} 
               else                  {$shipinfo[$group][$key]['selected'] = 0;}

          } // End of foreach statement.

     } // End of foreach statement.

     if ($this->debug) {$this->debugger("coship: Defaulted to first option as checked for each ship group.");}

} // End of if statement.

Offline

 

#6 02-13-2009 19:23:03

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

Re: Custom Shipping Script Help

Guest85 wrote:

I can change the sort order from least expensive to most expensive and the opposite most expensive to least expensive. Is there a way to have an exception? Like least expensive to most expensive except a shipping option that equals 0.00 (Customer Pickup) place at the bottom?

Well you're in the right place though I really wouldn't recommend modifying core code smile  If you're going mess in this area you should be able to order things any way you'd care to.

Offline

 

#7 02-17-2009 15:34:19

Guest85
Member
Registered: 05-29-2008
Posts: 21

Re: Custom Shipping Script Help

I've tried changing it to always have key 1 or value 1 always selected (this is UPS ground...customer pickup is key 0 or value 0) but can't get it to work. Anyone able to do it with the last code provided above?

Offline

 

#8 02-17-2009 15:54:45

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Custom Shipping Script Help

If your looking for a in store pickup option look at what I did . It basically lets the normal shipping display do it's thing and after it has been done pushes the in store pickup option to the front of the array, it can just as easily be placed at the end too.

John

Offline

 

#9 02-17-2009 17:18:48

Guest85
Member
Registered: 05-29-2008
Posts: 21

Re: Custom Shipping Script Help

dh783 wrote:

If your looking for a in store pickup option look at what I did . It basically lets the normal shipping display do it's thing and after it has been done pushes the in store pickup option to the front of the array, it can just as easily be placed at the end too.

John

I've tried that but can't get it to work either. I'm assuming I'm placing it in the wrong section?

Code:

// +--
// | Set up the first option as selected.  This may be
// | overridden in checkout later.
// +--

if (!(empty($shipinfo))) {

     foreach ($shipinfo as $group => $options) {

          $selected = 0;

          foreach ($options as $key => $data) {

               if (empty($selected)) {$shipinfo[$group][$key]['selected'] = 1; $selected++;} 
               else                  {$shipinfo[$group][$key]['selected'] = 0;}

          } // End of foreach statement.

     } // End of foreach statement.

     if ($this->debug) {$this->debugger("coship: Defaulted to first option as checked for each ship group.");}

} // End of if statement.

// +--
// | Work with our shipinfo array some more.  We want to handle free
// | shipping and handling charges here.
// +--

$freeship = $this->globals('khxc_settings.' . $this->app . '.freeshipamt');
$handling = $this->globals('khxc_settings.' . $this->app . '.shiphandlecharge');
$handzero = $this->globals('khxc_settings.' . $this->app . '.shiphandzero');

// ##################################
// # Added 2-17-09
// ##################################

$instore = array('name' => 'In Store Pickup', 'amount' => '', 'mark' => '', 'selected' => '0');
array_unshift($options,$instore);

// ##################################
// # End
// ##################################

if ((($freeship > 0) || ($handling > 0)) && (!(empty($shipinfo)))) {

     $xshipinfo = array();

     foreach ($shipinfo as $group => $options) {

          // +--
          // | Add in handling charges.
          // +--

          if ($handling > 0) {

               foreach ($options as $key => $data) {

                    if (($data['amount'] > 0) || (!(empty($handzero)))) {

                         $options[$key]['amount'] = $data['amount'] + $handling;

                    } // End of if statement.

               } // End of foreach statement.

               if ($this->debug) {$this->debugger("coship: Applied handling charge of '{$handling}'.");}

               // +--
               // | Update all of our realtime shipper info arrays to
               // | include the handling disclaimer.
               // +--

               $zshipinfo = $this->globals('ecom.ship_shipinfo');

               if (!(empty($zshipinfo))) {

                    foreach ($zshipinfo as $zshipper => $zinfo) {

                         $zshipinfo[$zshipper]['shipper_info']['show_handledisc'] = 1;

                    } // End of foreach statement.

                    $this->globals('ecom.ship_shipinfo',$zshipinfo);

               } // End of if statement.

          } // End of if statement.

          // +--
          // | Handle free shipping.
          // +--

          if (($freeship > 0) && ($subtotal >= $freeship)) {

               // +--
               // | Get the amount for the first item in the array.
               // +--

               foreach ($options as $key => $data) {

                    $xamount = $data['amount']; break 1;

               } // End of foreach statement.

               // +--
               // | Subtract that amount from all of the shipping
               // | options.
               // +--

               foreach ($options as $key => $data) {

                    $amount = $data['amount'] - $xamount;

                    if ($amount <= 0) {$amount = 0;}

                    $options[$key]['amount'] = $amount;

               } // End of foreach statement.

// ##################################
// # Added 2-17-09
// # When placed here as I have it on my site, it will not affect the normal free shipping and the rest of the 
// # shipping amounts offered and still make the lowest shipping amount the default, but it will push the in store  
// # pickup to the top of the list so that it can be select.
// ##################################

            $instore = array('name' => 'In Store Pickup', 'amount' => '', 'mark' => '', 'selected' => '0');

             array_unshift($options,$instore);

// ##################################
// # End
// ##################################
                  
                  if ($this->debug) {$this->debugger("coship: Applied free shipping discount of '{$xamount}'.");}

          } // End of if statement.

          $xshipinfo[$group] = $options;

     } // End of foreach statement.

     // +--
     // | Copy $xshipinfo over to our $shipinfo var.
     // +--

     $shipinfo = $xshipinfo;

     if ($this->debug) {$this->debugger("coship: Completed modifying shipping options for handling fees and free shipping.");}

} // End of if statement.

Offline

 

#10 02-17-2009 19:51:47

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Custom Shipping Script Help

First you only need one instance of the mod in the shipping code. Second the first place you have it will not work as it needs to be nested in the foreach statement that go:

Code:

 foreach ($shipinfo as $group => $options) {

Third the second place you have it is inside the free ship amount clause, which is ok but will only work when the items is equal to or is over the free ship threshold, if it's not set to zero. If you want it not to be tied to free shipping then you need to move it just above where the xshipinfo array is built here:

Code:

          } // End of if statement.

// Mod

            $instore = array('name' => 'In Store Pickup', 'amount' => '', 'mark' => '', 'selected' => '0');

             array_unshift($options,$instore);

// --------

          $xshipinfo[$group] = $options;

John

Last edited by dh783 (02-17-2009 19:53:14)

Offline

 

#11 02-17-2009 20:01:59

Guest85
Member
Registered: 05-29-2008
Posts: 21

Re: Custom Shipping Script Help

Thanks for the help John. I commented out the first instance of it (for now) and placed the second one in the correct place thanks to your help. The product that I'm adding to the cart should still be Realtime Carrier correct? If yes, then the "In Store Pickup" is not being displayed and yes I did make sure that I removed the item and re-added it to the cart.

Offline

 

#12 02-17-2009 22:23:19

dh783
Member
From: Avondale, Arizona
Registered: 04-06-2005
Posts: 6233
Website

Re: Custom Shipping Script Help

It shouldn't matter if the item in the test is real time shipping or custom as they should both run this section of the script, at least in my site I get in store pick in the custom shipping test I have done, but I have more mods in my code to only allow this to be for local customers. I am unable to get to my code at the moment so I will not be untile tomarrow befor I can look again.

John

Offline

 

Board footer