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 07-23-2018 10:56:56

bkc0508
Member
Registered: 04-16-2013
Posts: 6

Help with Shipping Script

I have some items we want to offer free shipping to lower 48 on but not international. We are not shipping all lower 48 for free.
The script I am currently using is below:
<?php

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

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

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

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

     $custom[$service['name']] = $service['amount'];

} // End of foreach statement.

$custom['~Local Pickup at our Shop~'] = '-1.50';

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


?>

Offline

 

#2 07-24-2018 08:03:44

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

Re: Help with Shipping Script

This should work much better for you:

Code:

<?php

// +--
// | Variable definition.
// +--

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

// +--
// | Get rates from USPS.
// +--

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

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

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

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

} // End of foreach statement.

// +--
// | Sort rates by amount (lowest to highest) and make the lowest cost option free 
// | Only if in the US and not AK or HI.
// +--

if ((!(empty($custom))) && ($info['country'] == 'United States') && ($info['stateprov'] != 'Alaska') && ($info['stateprov'] != 'Hawaii')) {

     asort($custom); foreach ($custom as $service => $rate) {$custom[$service] = 0; break 1;}

} // End of if statement.

// +--
// | Add local pickup if shipping within the same state.
// +--

if ($info['stateprov'] == $info['shipstateprov']) {$custom['Local Pickup at our Shop'] = 0;}

// +--
// | Globalize and return.
// +--

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

?>

Nick Hendler

Offline

 

#3 07-24-2018 10:01:10

bkc0508
Member
Registered: 04-16-2013
Posts: 6

Re: Help with Shipping Script

Thank you

So if I want to remove the free shipping take code out?
  asort($custom); foreach ($custom as $service => $rate) {$custom[$service] = 0; break 1;}

I assume I would need to have 2 scripts one for the products I want to offer free shipping on and another for the products we would not have free shipping promotion on. We only do free shipping on special products for limited time.

Offline

 

#4 07-25-2018 10:46:37

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

Re: Help with Shipping Script

You could disable the free shipping portion by commenting out that line like so:

Code:

//asort($custom); foreach ($custom as $service => $rate) {$custom[$service] = 0; break 1;}

Two shipping scripts is the easiest way in V8 to do what you want with your subset of products.  It's a shame you're not on K9, as that has an absolutely fantastic way of handling this.


Nick Hendler

Offline

 

#5 07-27-2018 11:20:43

bkc0508
Member
Registered: 04-16-2013
Posts: 6

Re: Help with Shipping Script

We are actually looking at going to V9.. Since we the person that originally did our site is not longer available.

Offline

 

#6 07-30-2018 07:24:57

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

Re: Help with Shipping Script

Existing clients can upgrade to K9.  Just submit this form with your requirements:

https://kryptronic.com/Form/Custom-Shop … t-Upgrades


Nick Hendler

Offline

 

#7 07-30-2018 07:45:49

bkc0508
Member
Registered: 04-16-2013
Posts: 6

Re: Help with Shipping Script

Thanks Nick
I submitted the forum on Friday.

Offline

 

#8 07-31-2018 07:30:45

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

Re: Help with Shipping Script

Great.  I replied back to your ticket on Friday with a few questions and a demo link.  I'll resend that now.


Nick Hendler

Offline

 

#9 08-01-2018 20:50:24

bkc0508
Member
Registered: 04-16-2013
Posts: 6

Re: Help with Shipping Script

webmaster wrote:

Great.  I replied back to your ticket on Friday with a few questions and a demo link.  I'll resend that now.

My email must be blocking you. I get the reply from this forum. I will put in new request tomorrow.

Offline

 

#10 08-03-2018 08:02:00

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

Re: Help with Shipping Script

bkc0508 wrote:

My email must be blocking you. I get the reply from this forum. I will put in new request tomorrow.

Looks like you figured out the mail issue, so we'll continue with the ticket.  Thanks.


Nick Hendler

Offline

 

Board footer