Updating old shipping modules and need help adding max and min weight to ship

Open to all! Ask other shopowners for help.
Post Reply
14Steve14
Senior Contributor
Posts: 923
Joined: Fri Oct 25, 2019 7:01 pm
Phoenix Version: v1.0.9.1
Has thanked: 17 times
Been thanked: 103 times

Updating old shipping modules and need help adding max and min weight to ship

Post by 14Steve14 »

My apologies for the long post/question.

I have got to where I need to update my shipping modules. I had some coded by a certified developer who I now cannot contact so I am trying to update them myself.

I have copied, altered, and created new shipping module files using the table rate module. That all works but my old modules had a place where I had to enter the minimum and maximum shipping weighs and costs. I can get the four new boxes to show in the modules admin page. That was the easy bit.

The problem comes when I try to add the code required to enable these inputted figures in the shipping modules. The old website has a file called 'abstract_banded_shipping_module.php' in the classes folder. I have found the equivalent folder in 1.0.8.20 in system/versioned/1.0.7.8/abstract_shipping_module.php. These fields allow us to restrict the weight and order value depending on the shipping method.

What I am having trouble with is adding the code from the old website into the new websites file. I need to add
// Only ship if packet value exceeds method minimum value
if ( ($order_total / $this->shipping_num_boxes) < $this->base_constant('MIN_VALUE')) {
$this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MIN_BOX_VALUE, ($order_total / $this->shipping_num_boxes), $this->base_constant('MIN_VALUE')));
}

// Only ship if packet value does not exceed method maximum value
if ($this->base_constant('MAX_VALUE') > 0 && ($order_total / $this->shipping_num_boxes) > $this->base_constant('MAX_VALUE')) {
$this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MAX_BOX_VALUE, ($order_total / $this->shipping_num_boxes), $this->base_constant('MAX_VALUE')));
}

// Only ship if packet weight exceeds method minimum weight
if ( $this->shipping_weight < $this->base_constant('MIN_WEIGHT')) {
$this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MIN_BOX_WEIGHT, $this->shipping_weight, $this->base_constant('MIN_WEIGHT')));
}

// Only ship if packet weight does not exceed method maximum weight
if ($this->base_constant('MAX_WEIGHT') > 0 && $this->shipping_weight > $this->base_constant('MAX_WEIGHT')) {
$this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MAX_BOX_WEIGHT, $this->shipping_weight, $this->base_constant('MAX_WEIGHT')));
}
Into the new file. I cannot seem to get it to work, so am probably putting it in the wrong place. In the old file it comes into the public function update_status() { section, but when I add it in there I get errors and the shipping modules do not work. I have added the code as

Code: Select all

public function update_status() {
      if ($this->enabled && isset($GLOBALS['order']->delivery['country']['id'])) {
        $this->update_status_by($GLOBALS['order']->delivery);
      }
    
    // Only ship if packet value exceeds method minimum value
            if ( ($order_total / $this->shipping_num_boxes) < $this->base_constant('MIN_VALUE')) {
              $this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MIN_BOX_VALUE, ($order_total / $this->shipping_num_boxes), $this->base_constant('MIN_VALUE')));
            }

            // Only ship if packet value does not exceed method maximum value
            if ($this->base_constant('MAX_VALUE') > 0 && ($order_total / $this->shipping_num_boxes) > $this->base_constant('MAX_VALUE')) {
              $this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MAX_BOX_VALUE, ($order_total / $this->shipping_num_boxes), $this->base_constant('MAX_VALUE')));
            }

            // Only ship if packet weight exceeds method minimum weight
            if ( $this->shipping_weight < $this->base_constant('MIN_WEIGHT')) {
              $this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MIN_BOX_WEIGHT, $this->shipping_weight, $this->base_constant('MIN_WEIGHT')));
            }

            // Only ship if packet weight does not exceed method maximum weight
            if ($this->base_constant('MAX_WEIGHT') > 0 && $this->shipping_weight > $this->base_constant('MAX_WEIGHT')) {
              $this->disable(sprintf(COUNTRY_BANDED_SHIPPING_MAX_BOX_WEIGHT, $this->shipping_weight, $this->base_constant('MAX_WEIGHT')));
            }
            
            }
Whilst this is way above my usual coding level, can someone say what I am doing wrong, or at least help get the modules working.


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Updating old shipping modules and need help adding max and min weight to ship

Post by ecartz »

One thing that leaps out at me is that $order_total is a local variable that you never set to anything. Maybe $GLOBALS['order']->info['total'] or just $GLOBALS['order_total'] ? Perhaps the old file sets it somewhere that you're not copying over.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply