Jump to content
Enzo_UK

Hide Zone based rates if customer is from a certain zone.

Recommended Posts

I am using a few different shipping methods together (table rates, zone rates, and a massively modified zone rates) all in conjunction with ship in cart.

 

I use my 'zone rates' for customers outside the UK, as the rates for within the UK are a combination of 'table rates' and my 'modified zone rates'.

 

What I want to do is totally disable the 'zone rates' if the customer is from the UK, rather than having it still show up on the ship in cart and on the shipping page with an error message.

 

I kind of know how I want it to work, but just cant get my head round the coding...

// class constructor
    function zones() {
      $this->code = 'zones';
      $this->title = MODULE_SHIPPING_ZONES_TEXT_TITLE;
      $this->description = MODULE_SHIPPING_ZONES_TEXT_DESCRIPTION;
      $this->sort_order = MODULE_SHIPPING_ZONES_SORT_ORDER;
      $this->icon = '';
      $this->tax_class = MODULE_SHIPPING_ZONES_TAX_CLASS;
      $this->enabled = ((MODULE_SHIPPING_ZONES_STATUS == 'True') ? true : false);
      // CUSTOMIZE THIS SETTING FOR THE NUMBER OF ZONES NEEDED
      $this->num_zones = 4;
    }
I basically want something along the lines of...
if ($order->delivery['iso_code_2'] == UK) {$this->enabled = false;} 

I don't even know if that's going to be the right way to do it, or how to add it into the existing code without messing it all up.

 

Any help is greatly appreciated.

Edited by Enzo_UK

Share this post


Link to post
Share on other sites

Remove all of your modules and use the MZMT Addon for the whole thing. No modifications needed, just set up your zones and tables.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

I don't think MZMT will do what I need... as I have kind of made my own module that takes the customers UK postcode however its supplied, with space or without space, lowercase of capitals (e.g. ab123cd, ab12 3cd, AB123CD, AB12 3CD) and splits it and have a table that assigns the first part of the UK postcode to a zone.

Share this post


Link to post
Share on other sites

I'm not aware of any stock shipping module that will meet that last requirement, so you're back to modifying a stock module. Sorry I couldn't help.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites

Had a little think, and is there some way I can use the bit from in Flat rates to do what I want to do in my Zone rates?

 

As in Flat rates there is the option of only aplying it to only one zone... so would make sense this can be reworked to exclude one zone in Zone rates.

      $this->enabled = ((MODULE_SHIPPING_FLAT_STATUS == 'True') ? true : false);

      if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FLAT_ZONE > 0) ) {
        $check_flag = false;
        $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_SHIPPING_FLAT_ZONE . "' and zone_country_id = '" . $order->delivery['country']['id'] . "' order by zone_id");
        while ($check = tep_db_fetch_array($check_query)) {
          if ($check['zone_id'] < 1) {
            $check_flag = true;
            break;
          } elseif ($check['zone_id'] == $order->delivery['zone_id']) {
            $check_flag = true;
            break;
          }
        }

        if ($check_flag == false) {
          $this->enabled = false;
        }
      }

Share this post


Link to post
Share on other sites

The code that you posted in your initial post is close to what you need. Something like this:

if ($order->delivery['iso_code_2'] == 'UK') {
  $this->enabled = false;
} 

Add that to the end of the class constructor and it should do what you want. Assuming that the ISO code really is UK -- I didn't check.

 

Regards

Jim


See my profile for a list of my addons and ways to get support.

Share this post


Link to post
Share on other sites
    if ($this->enabled == true) {
  global $order;
  if ($order->delivery['country']['iso_code_2'] == 'GB') {
   $this->enabled = false;
  }
    }

I managed to get there in the end, thanks for telling me I was along the right lines, which made me stick with it.

 

Works as intended now, many thanks.

Edited by Enzo_UK

Share this post


Link to post
Share on other sites

Slight glitch... it worked fine when a customer is not logged in and your just switching between countries using the drop down menu in the ship in cart.

 

Once a customer was logged in you no longer have the countries drop down, and just uses the info from the customers address book, so have had to change it to using country_id instead.

    if ($this->enabled == true) {
  global $order;
  if ($order->delivery['country_id'] == '// YOUR COUNTRY ID HERE') {
   $this->enabled = false;
  }
    }
Edited by Enzo_UK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×