Jump to content

Groups - automatically add customers by post code


Recommended Posts

None of that makes any sense to me. The modules suggested are nothing to do with groups as far as I can see, and I have a VERY small shop, and can't afford to pay for modules anyway. I just wanted a simple way to make a new group, but there seems to be no way in the back office of regulating who is in a group.

Link to comment
Share on other sites

You should create override/controllers/front/AuthController.php to override the AuthController::processSubmitAccount() function like this:

<?php

class AuthController extends AuthControllerCore
{
    protected function processSubmitAccount()
    {

    }
}

It's probably easiest if you copy the entire function and then find this code:

                $postcode = $$addresses_type->postcode;
                /* Check zip code format */
                if ($country->zip_code_format && !$country->checkZipCode($postcode)) {
                    $this->errors[] = sprintf(Tools::displayError('The Zip/Postal code you\'ve entered is invalid. It must follow this format: %s'), str_replace('C', $country->iso_code, str_replace('N', '0', str_replace('L', 'A', $country->zip_code_format))));
                } elseif (empty($postcode) && $country->need_zip_code) {
                    $this->errors[] = Tools::displayError('A Zip / Postal code is required.');
                } elseif ($postcode && !Validate::isPostCode($postcode)) {
                    $this->errors[] = Tools::displayError('The Zip / Postal code is invalid.');
                }

After this code, you can write something like this:

                if (substr($postcode, 0, 2) == '48') {
                    $customer->addGroups(array(1));
                }

This should add the customer to group 1 if their postcode starts with 48. Change the code as necessary.

 

After you've created your override, go to Advanced Parameters > Performance and then click the "Clear cache" button (or manually delete cache/class_index.php) so PrestaShop can find the override.

 

I hope this points you in the right direction.

Link to comment
Share on other sites

Thanks but that's all double dutch to me. I don't have anything that looks remote like that. I have options of :

 

Dashboard

Catalog

Orders

Customers

Price rules

Shipping

Localisation

Modules and services

Preferences

Advanced parameters

Administration

Stats

 

Where do I go from here please?

Edited by Littlepants (see edit history)
Link to comment
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
×
×
  • Create New...