Forums / Built-in Shipping and Payment Modules / Hide local delivery from those who are not local

Hide local delivery from those who are not local

Views: 4,450

Results 1 to 20 of 35
16 Aug 2010, 4:25 PM
#1
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Hide local delivery from those who are not local

I would like to offer local delivery to those living in my city. How can I hide this shipping option from those who do not live in my city?

17 Aug 2010, 12:08 AM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

Let's say you wanted to only allow local shipping for: Toronto

You could customize the Store Pickup storepickup shipping module with:

if (strtoupper($order->delivery['city']) == 'TORONTO') {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));
}

Be aware, however, if my customer address is: Cleveland and I set the shipping address to Toronto in the checkout, then go off the checkout_ pages and go to the shipping_estimator ... that will reset my address to Cleveland ... and I will have to reset my shipping to my Toronto address when I get to checkout_shipping ...

If, however, I change in the checkout_shipping to my Toronto address then leave the checkout_ pages but do not touch the shipping_estimator then my address will stay as Toronto and I will not have to reset this ...

So far, I tried this as a customer that needed to add the new address while in the checkout_shipping and as an existing customer with that address ...

NOTE: if someone cannot spell their City exactly right there will be no way to do the match ...

NOTE: be sure to write the city name in all CAPS as you do not know what the customer might use so their city is forced to caps for the logic of the IF ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

17 Aug 2010, 5:31 PM
#3
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Thank you for the reply.

I am a little confused, though. Am I adding this PHP code to the end of the shpping module? Also, what exactly did you mean by the rest of your post? I am sorry, but I did not really understand that part.

Thank you!

17 Aug 2010, 6:16 PM
#4
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

If you look in the code for the file:
/includes/modules/shipping/storepickup.php

around lines 92 - 96 ...

you will see that it currently reads:

    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));

The code I posted is adding an IF statement around the existing code to test the Order Delivery City name ... in this case it tests for the city TORONTO ...

If you want that to be: PEORIA then you would change TORONTO to PEORIA ...

As far as the additional information, I was just explaining that if you are testing for the city:
PEORIA

and the customer spells it:
peioria

due to a typo ... it will not work and not show for them ...

The reason the code uppercases their city for the test is you do not know how they will add it ...
Peoria
peoria
PeOria
PEORIA

so by testing it with uppercase you do not have to worry ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

17 Aug 2010, 7:41 PM
#5
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Perfect, thank you. One last question: where would I put this for the template override system? I tried /includes/modules/my_template/shipping/storepickup.php and /includes/modules/shipping/my_template/storepickup.php, but neither worked.

17 Aug 2010, 7:46 PM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

Glad to hear that you use the templates and overrides ... :smile:

Unfortunately, the Shipping Modules do not use overrides on the CODE files ...

NOTE: the Shipping Modules DO use the overrides on the LANGUAGE files ...
/includes/languages/english/modules/shipping

/includes/languages/english/modules/shipping/your_template_dir

This is the same with Payment Modules and Order Total Modules ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

17 Aug 2010, 7:50 PM
#7
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Ajeh:

Glad to hear that you use the templates and overrides ... :smile:

Yup. It is so much easier to upgrade when you use them. I wish more people did.

Sorry, I lied. I have one more question. How can I make it so it appears for multiple cities? I live in a city with several small towns near it, so I would like to offer them this option too.

Thank you!

EDIT: Can I put this edit into the shipping language file or does this have to go in the code file?

17 Aug 2010, 11:45 PM
#8
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

You are changing the file:
/includes/modules/shipping/storepickup.php

I have altered the code so you can add additional cities ...

Currently, the function quote looks like:

  function quote($method = '') {
    global $order;

    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));

    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
  /**

This is what the function quote should look like when done adding this change:

  function quote($method = '') {
    global $order;

if (in_array(strtoupper($order->delivery['city']), array('TORONTO', 'TAMPA'))) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));
}

    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
  /**

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

18 Aug 2010, 1:06 AM
#9
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Thank you so much. Can I add more than two cities?

18 Aug 2010, 1:22 AM
#10
bobdog avatar

bobdog

Totally Zenned

Join Date:
Mar 2006
Location:
Fresno, California
Posts:
590
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

From glancing at the code, yes you can. Just keep adding cities like this:

if (in_array(strtoupper($order->delivery['city']), array('TORONTO', 'TAMPA', 'SACRAMENTO', 'PHOENIX')))
18 Aug 2010, 12:49 PM
#11
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Thank you!

18 Aug 2010, 1:05 PM
#12
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Argh, I should have asked this in my first post, but is there anyway to make sure they are in my state? For example, if I use the city of Charlotte, NC, I do not want people from Charlotte, IL using this.

18 Aug 2010, 1:56 PM
#13
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

You would then need to add the state to the IF ...

if (strtoupper($order->delivery['state']) == 'FLORIDA' && in_array(strtoupper($order->delivery['city']), array('TORONTO', 'TAMPA'))) {

**** EDITED TO FIX STATE REFERENCE ****

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

18 Aug 2010, 4:08 PM
#14
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Thank you for your help. I have the following code, but after entering the IF statement for state, it does not work. I tried it with "NC" and "North Carolina".

function quote($method = '') {
    global $order;

if (strtoupper($order->delivery['delivery_state']) == 'NC' && in_array(strtoupper($order->delivery['city']), array('CHARLOTTE', 'INDIAN TRAIL', 'MATTHEWS', 'MINT HILL', 'STALLINGS'))) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));
18 Aug 2010, 6:12 PM
#15
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

It is always a good idea to follow the bouncing ball ... :cool:

Notice that I used:
FLORIDA

Two reasons for that:

1 for testing in the IF

2 the orders table stores the full name of the state ...

Moral of the story ...
Be sure to use for the IF statement the full name of the state in upper case ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

18 Aug 2010, 7:29 PM
#16
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

It still does not work. Here is my code:

function quote($method = '') {
    global $order;

if (strtoupper($order->delivery['delivery_state']) == 'NORTH CAROLINA' && in_array(strtoupper($order->delivery['city']), array('CHARLOTTE', 'INDIAN TRAIL', 'MATTHEWS', 'MINT HILL', 'STALLINGS'))) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));
}
18 Aug 2010, 11:59 PM
#17
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

Sorry ... got carried away on the reference to the delivery state of the order ...

Use on the IF:

if (strtoupper($order->delivery['state']) == 'NORTH CAROLINA' && in_array(strtoupper($order->delivery['city']), array('CHARLOTTE', 'INDIAN TRAIL', 'MATTHEWS', 'MINT HILL', 'STALLINGS'))) {

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

19 Aug 2010, 7:50 PM
#18
commdiver avatar

commdiver

Zen Follower

Join Date:
May 2010
Posts:
222
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

:clap:

Thank you so much. You have been a big help!

20 Aug 2010, 12:24 AM
#19
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide local delivery from those who are not local

No need for applause ... just throw money ... :cool:

Thanks for the update that you now have this working ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

6 Oct 2010, 2:28 AM
#20
tinman780 avatar

tinman780

New Zenner

Join Date:
Jul 2010
Location:
Welland, ON Canada
Posts:
46
Plugin Contributions:
0

Re: Hide local delivery from those who are not local

Ajeh:

You are changing the file:
/includes/modules/shipping/storepickup.php

I have altered the code so you can add additional cities ...

Currently, the function quote looks like:

function quote($method = '') {
global $order;

$this->quotes = array('id' => $this->code,
                      'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                      'methods' => array(array('id' => $this->code,
                                               'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                               'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));

if ($this->tax_class > 0) {
  $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
}

if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

return $this->quotes;

}
/**

> 
> This is what the function quote should look like when done adding this change:
> ```
  function quote($method = '') {
    global $order;

if (in_array(strtoupper($order->delivery['city']), array('TORONTO', 'TAMPA'))) {
    $this->quotes = array('id' => $this->code,
                          'module' => MODULE_SHIPPING_STOREPICKUP_TEXT_TITLE,
                          'methods' => array(array('id' => $this->code,
                                                   'title' => MODULE_SHIPPING_STOREPICKUP_TEXT_WAY,
                                                   'cost' => MODULE_SHIPPING_STOREPICKUP_COST)));
}

    if ($this->tax_class > 0) {
      $this->quotes['tax'] = zen_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
    }

    if (zen_not_null($this->icon)) $this->quotes['icon'] = zen_image($this->icon, $this->title);

    return $this->quotes;
  }
  /**

Ajeh,

I followed your code to the letter, and it works beautifully. I noticed that on the shipping page it changes 'Walk-in' to 'local delivery'. My question is, Is there a way I can give them "Both" options? A way to choose whether they want it delivered, or they would like to come pick it up.

Thanks