Zen Cart Logo
Forums / Discounts/Coupons, Gift Certificates, Newsletters, Ads / New customers automatically join defined pricing group

New customers automatically join defined pricing group

Views: 11,175

Results 1 to 20 of 24
1 Jul 2007, 5:32 PM
#1
gaekwad avatar

gaekwad

New Zenner

Join Date:
May 2007
Posts:
33
Plugin Contributions:
0

New customers automatically join defined pricing group

Hi there.
Is it possible to have new customers be added to a pre-defined pricing group by default? I can add them manually, but I'm using the Invoice payment mod and it requires a customer to be in a pricing group.

Thanks in advance.
P

1 Jul 2007, 7:50 PM
#2
ajeh avatar

ajeh

Oba-san

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

Re: New customers automatically join defined pricing group

You can alter the create account so that when the record is created it sets the customers_group_pricing field in the customers table to the value that you are wanting to use as an existing discount group by default ...

1 Jul 2007, 8:27 PM
#3
gaekwad avatar

gaekwad

New Zenner

Join Date:
May 2007
Posts:
33
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Sweet - that makes perfect sense :) Could I ask which file needs to be edited in order to make that happen? Happy to scootch around a bit, but any pointer would be appreciated.

Thanks, Ajeh - appreciate it :)

1 Jul 2007, 11:19 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,699
Plugin Contributions:
56

Re: New customers automatically join defined pricing group

Rather than modifying the code, I would suggest you just modify the default value for customers.customers_group_pricing using phpMyAdmin.

Good luck,
Software Guy

2 Jul 2007, 12:44 AM
#5
gaekwad avatar

gaekwad

New Zenner

Join Date:
May 2007
Posts:
33
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

swguy, you're a genius - thanks. Works a treat! And thanks for making the Invoice mod, very useful.

15 Apr 2009, 2:26 AM
#6
jenpen avatar

jenpen

Zen Follower

Join Date:
Sep 2007
Location:
Far South Coast, NSW, Australia
Posts:
427
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

modify the default value for customers.customers_group_pricing using phpMyAdmin

Can anyone give just a little more detail on this? I'm pretty comfortable in phpMyAdmin, just give me a push in the right direction ... jenpen

20 Apr 2009, 4:08 AM
#7
jenpen avatar

jenpen

Zen Follower

Join Date:
Sep 2007
Location:
Far South Coast, NSW, Australia
Posts:
427
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Me again - does anyone know exactly how to "modify the default value for customers.customers_group_pricing using phpMyAdmin"??
Thanks, Jen

20 Apr 2009, 9:36 AM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: New customers automatically join defined pricing group

Open phpMyAdmin
Access the customers table structure
Edit the "default" value for the customers_group_pricing table to the value you desire.

21 Apr 2009, 5:38 AM
#9
jenpen avatar

jenpen

Zen Follower

Join Date:
Sep 2007
Location:
Far South Coast, NSW, Australia
Posts:
427
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

So now I'm nearly there ... found exactly how to change the default value but ... what to? Sorry to be a dodo. I tried "invoice" but got an error. Jen

21 Apr 2009, 5:51 AM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: New customers automatically join defined pricing group

When you created your discount groups in your admin, they were assigned a number. Use that number.

21 Apr 2009, 6:04 AM
#11
jenpen avatar

jenpen

Zen Follower

Join Date:
Sep 2007
Location:
Far South Coast, NSW, Australia
Posts:
427
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

:blush:
Thanks doc.

27 Apr 2009, 10:05 AM
#12
colinr avatar

colinr

New Zenner

Join Date:
Jul 2006
Posts:
35
Plugin Contributions:
1

Re: New customers automatically join defined pricing group

I would also like to add customers to discount group automatically when they sign up. However I would like this to only be selected trade customers.

I see this working by providing a special sign-up link to the customer inviting them to open a trade account. This alternative sign-up form would need to define the alternative group to which they should added - perhaps as a hidden field.

Is this possible?

ColinR

2 Sep 2010, 1:31 AM
#13
jenpen avatar

jenpen

Zen Follower

Join Date:
Sep 2007
Location:
Far South Coast, NSW, Australia
Posts:
427
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

A bit over a year and I have completely forgotten how I managed this last time. There's a "customers" table and a "Group pricing" table but not a customers group pricing" table. Or is it different now?

15 Nov 2010, 2:46 AM
#14
bluedotted avatar

bluedotted

New Zenner

Join Date:
Oct 2008
Posts:
64
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Got it where the customer is added to the group to offer 10% off but is there an option to opt the customer out of the new signup group once the coupon sent has been used?

22 Aug 2011, 8:37 AM
#15
scientific_anomaly avatar

scientific_anomaly

New Zenner

Join Date:
Nov 2010
Posts:
44
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

it can be annoying to have to reinvent the wheel so here it is on a plate as I would like it served every time if I could.

in includes/modules/create_account.php after around line 252

Add a line like this 'customers_group_pricing' => 3,

Where 3 is the ID number of the group price you want as a default (yours could be any number, in my case 3 refers to group c price)

code:

$sql_data_array = array('customers_firstname' => $firstname,
'customers_lastname' => $lastname,
'customers_email_address' => $email_address,
'customers_nick' => $nick,
'customers_telephone' => $telephone,
'customers_fax' => $fax,
'customers_newsletter' => (int)$newsletter,
'customers_email_format' => $email_format,
'customers_default_address_id' => 0,
'customers_group_pricing' => 3,
'customers_password' => zen_encrypt_password($password),
'customers_authorization' => (int)CUSTOMERS_APPROVAL_AUTHORIZATION

3 Apr 2012, 3:30 PM
#16
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

This works perfectly, thank you! Does anyone know of a way to apply this to COWOA users?

3 Apr 2012, 3:59 PM
#17
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,513
Plugin Contributions:
176

Re: New customers automatically join defined pricing group

Simple. Do the same thing in the corresponding file that your custom addon uses.

3 Apr 2012, 4:04 PM
#18
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Thanks, I tried adding it to this array, but didn't have any luck:

    $sql_data_array = array('customers_firstname' => $firstname,
                            'customers_lastname' => $lastname,
                            'customers_email_address' => $email_address,
                            'customers_nick' => $nick,
                            'customers_telephone' => $telephone,
                            'customers_fax' => $fax,
                            'customers_newsletter' => (int)$newsletter,
                            'customers_email_format' => $email_format,
                            'customers_default_address_id' => 0,
                            'customers_password' => zen_encrypt_password($password),
                            'COWOA_account' => 1,
                            'customers_authorization' => (int)CUSTOMERS_APPROVAL_AUTHORIZATION
    );

FULL no_account.php file:

<?php
/**
 * no_account.php
 *
 * @package modules
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2007 Joseph Schilz
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: J_Schilz for Integrated COWOA - 14 April 2007
 */
// This should be first line of the script:
$zco_notifier->notify('NOTIFY_MODULE_START_NO_ACCOUNT');

if (!defined('IS_ADMIN_FLAG')) {
  die('Illegal Access');
}
/**
 * Set some defaults
 */
  $process = false;
  $zone_name = '';
  $entry_state_has_zones = '';
  $error_state_input = false;
  $state = '';
  $zone_id = 0;
  $error = false;
  $email_format = (ACCOUNT_EMAIL_PREFERENCE == '1' ? 'HTML' : 'TEXT');
  $newsletter = (ACCOUNT_NEWSLETTER_STATUS == '1' || ACCOUNT_NEWSLETTER_STATUS == '0' ? false : true);
/**
 * Process form contents
 */
if (isset($_POST['action']) && ($_POST['action'] == 'process')) {
  $process = true;
  
  /** COWOA - If CART Total is 0, skip all but E-Mail Checks */
  
 if ($_SESSION['cart']->show_total() != 0 || COWOA_EMAIL_ONLY == 'false') {
  
     if (ACCOUNT_GENDER == 'true') {
    if (isset($_POST['gender'])) {
      $gender = zen_db_prepare_input($_POST['gender']);
    } else {
      $gender = false;
    }
  }

  if (ACCOUNT_COMPANY == 'true') $company = zen_db_prepare_input($_POST['company']);
  $firstname = zen_db_prepare_input($_POST['firstname']);
  $lastname = zen_db_prepare_input($_POST['lastname']);
  $nick = zen_db_prepare_input($_POST['nick']);
  if (ACCOUNT_DOB == 'true') $dob = (empty($_POST['dob']) ? zen_db_prepare_input('0001-01-01 00:00:00') : zen_db_prepare_input($_POST['dob']));
  $street_address = zen_db_prepare_input($_POST['street_address']);
  if (ACCOUNT_SUBURB == 'true') $suburb = zen_db_prepare_input($_POST['suburb']);
  $postcode = zen_db_prepare_input($_POST['postcode']);
  $city = zen_db_prepare_input($_POST['city']);
  if (ACCOUNT_STATE == 'true') {
    $state = zen_db_prepare_input($_POST['state']);
    if (isset($_POST['zone_id'])) {
      $zone_id = zen_db_prepare_input($_POST['zone_id']);
    } else {
      $zone_id = false;
    }
  }
  $country = zen_db_prepare_input($_POST['zone_country_id']);
  $telephone = zen_db_prepare_input($_POST['telephone']);
  $fax = zen_db_prepare_input($_POST['fax']);
  $email_format = zen_db_prepare_input($_POST['email_format']);
  $customers_authorization = CUSTOMERS_APPROVAL_AUTHORIZATION;
  $customers_referral = zen_db_prepare_input($_POST['customers_referral']);

  if (ACCOUNT_NEWSLETTER_STATUS == '1' || ACCOUNT_NEWSLETTER_STATUS == '2') {
    $newsletter = 0;
  if (isset($_POST['newsletter'])) {
    $newsletter = zen_db_prepare_input($_POST['newsletter']);
    }
  }

  $password = zen_db_prepare_input($_POST['password']);
  $confirmation = zen_db_prepare_input($_POST['confirmation']);


  if (DISPLAY_PRIVACY_CONDITIONS == 'true') {
    if (!isset($_POST['privacy_conditions']) || ($_POST['privacy_conditions'] != '1')) {
      $error = true;
      $messageStack->add('no_account', ERROR_PRIVACY_STATEMENT_NOT_ACCEPTED, 'error');
    }
  }

  if (ACCOUNT_GENDER == 'true') {
    if ( ($gender != 'm') && ($gender != 'f') ) {
      $error = true;
      $messageStack->add('no_account', ENTRY_GENDER_ERROR);
    }
  }

  if (strlen($firstname) < ENTRY_FIRST_NAME_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_FIRST_NAME_ERROR);
  }

  if (strlen($lastname) < ENTRY_LAST_NAME_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_LAST_NAME_ERROR);
  }


  if (ACCOUNT_COMPANY == 'true') {
    if ((int)ENTRY_COMPANY_MIN_LENGTH > 0 && strlen($company) < ENTRY_COMPANY_MIN_LENGTH) {
      $error = true;
      $messageStack->add('no_account', ENTRY_COMPANY_ERROR);
    }
  }

  if (strlen($street_address) < ENTRY_STREET_ADDRESS_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_STREET_ADDRESS_ERROR);
  }

  if (strlen($city) < ENTRY_CITY_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_CITY_ERROR);
  }

  if (ACCOUNT_STATE == 'true') {
    $check_query = "SELECT count(*) AS total
                    FROM " . TABLE_ZONES . "
                    WHERE zone_country_id = :zoneCountryID";
    $check_query = $db->bindVars($check_query, ':zoneCountryID', $country, 'integer');
    $check = $db->Execute($check_query);
    $entry_state_has_zones = ($check->fields['total'] > 0);
    if ($entry_state_has_zones == true) {
      $zone_query = "SELECT distinct zone_id, zone_name, zone_code
                     FROM " . TABLE_ZONES . "
                     WHERE zone_country_id = :zoneCountryID
                     AND " . 
                     ((trim($state) != '' && $zone_id == 0) ? "(upper(zone_name) like ':zoneState%' OR upper(zone_code) like '%:zoneState%') OR " : "") .
                    "zone_id = :zoneID
                     ORDER BY zone_code ASC, zone_name";

      $zone_query = $db->bindVars($zone_query, ':zoneCountryID', $country, 'integer');
      $zone_query = $db->bindVars($zone_query, ':zoneState', strtoupper($state), 'noquotestring');
      $zone_query = $db->bindVars($zone_query, ':zoneID', $zone_id, 'integer');
      $zone = $db->Execute($zone_query);

      //look for an exact match on zone ISO code
      $found_exact_iso_match = ($zone->RecordCount() == 1);
      if ($zone->RecordCount() > 1) {
        while (!$zone->EOF && !$found_exact_iso_match) {
          if (strtoupper($zone->fields['zone_code']) == strtoupper($state) ) {
            $found_exact_iso_match = true;
            continue;
          }
          $zone->MoveNext();
        }
      }

      if ($found_exact_iso_match) {
        $zone_id = $zone->fields['zone_id'];
        $zone_name = $zone->fields['zone_name'];
      } else {
        $error = true;
        $error_state_input = true;
        $messageStack->add('no_account', ENTRY_STATE_ERROR_SELECT);
      }
    } else {
      if (strlen($state) < ENTRY_STATE_MIN_LENGTH) {
        $error = true;
        $error_state_input = true;
        $messageStack->add('no_account', ENTRY_STATE_ERROR);
      }
    }
  }

  if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_POST_CODE_ERROR);
  }

  if ( (is_numeric($country) == false) || ($country < 1) ) {
    $error = true;
    $messageStack->add('no_account', ENTRY_COUNTRY_ERROR);
  }

  if (strlen($telephone) < ENTRY_TELEPHONE_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_TELEPHONE_NUMBER_ERROR);
  }
/* COWOA - End of CART Totals = 0 */ 
 }
 
  $email_address = zen_db_prepare_input($_POST['email_address']);
  
  if (strlen($email_address) < ENTRY_EMAIL_ADDRESS_MIN_LENGTH) {
    $error = true;
    $messageStack->add('no_account', ENTRY_EMAIL_ADDRESS_ERROR);
  } elseif (zen_validate_email($email_address) == false) {
    $error = true;
    $messageStack->add('no_account', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
  } else {
    $check_email_query = "select count(*) as total
                            from " . TABLE_CUSTOMERS . "
                            where customers_email_address = '" . zen_db_input($email_address) . "'
                            and COWOA_account != 1";
    $check_email = $db->Execute($check_email_query);

    if ($check_email->fields['total'] > 0) {
      $error = true;
      $messageStack->add('no_account', ENTRY_EMAIL_ADDRESS_ERROR_EXISTS);
    }
  }
  
/* COWOA - Set all fields to No_Account for free products */
if ($_SESSION['cart']->show_total() == 0 and COWOA_EMAIL_ONLY == 'true') {
    
$company = No_Account;
$firstname = No_Account;
$lastname = No_Account;
$nick = No_Account;
$street_address = No_Account;
$suburb = No_Account;
$city = No_Account;
$postcode = 33333;
$dob = '0001-01-01 00:00:00';
$state = Florida;
$country = 223;
$telephone = 5555551212;
$fax = 5555551212;
$customers_referrals = No_Account;
$gender = m;
} 
 
  $password=zen_create_random_value(15, 'mixed');

  if ($error == true) {
    // hook notifier class
    $zco_notifier->notify('NOTIFY_FAILURE_DURING_NO_ACCOUNT');
  } else {

    $_SESSION['COWOA'] = true;

    $sql_data_array = array('customers_firstname' => $firstname,
                            'customers_lastname' => $lastname,
                            'customers_email_address' => $email_address,
                            'customers_nick' => $nick,
                            'customers_telephone' => $telephone,
                            'customers_fax' => $fax,
                            'customers_newsletter' => (int)$newsletter,
                            'customers_email_format' => $email_format,
                            'customers_default_address_id' => 0,
                            'customers_password' => zen_encrypt_password($password),
                            'COWOA_account' => 1,
                            'customers_authorization' => (int)CUSTOMERS_APPROVAL_AUTHORIZATION
    );

    if ((CUSTOMERS_REFERRAL_STATUS == '2' and $customers_referral != '')) $sql_data_array['customers_referral'] = $customers_referral;
    if (ACCOUNT_GENDER == 'true') $sql_data_array['customers_gender'] = $gender;
    if (ACCOUNT_DOB == 'true') $sql_data_array['customers_dob'] = (empty($_POST['dob']) || $dob_entered == '0001-01-01 00:00:00' ? zen_db_prepare_input('0001-01-01 00:00:00') : zen_date_raw($_POST['dob']));

    zen_db_perform(TABLE_CUSTOMERS, $sql_data_array);

    $_SESSION['customer_id'] = $db->Insert_ID();

    $zco_notifier->notify('NOTIFY_MODULE_NO_ACCOUNT_ADDED_CUSTOMER_RECORD', array_merge(array('customer_id' => $_SESSION['customer_id']), $sql_data_array));
    $sql_data_array = array('customers_id' => $_SESSION['customer_id'],
                            'entry_firstname' => $firstname,
                            'entry_lastname' => $lastname,
                            'entry_street_address' => $street_address,
                            'entry_postcode' => $postcode,
                            'entry_city' => $city,
                            'entry_country_id' => $country);

    if (ACCOUNT_GENDER == 'true') $sql_data_array['entry_gender'] = $gender;
    if (ACCOUNT_COMPANY == 'true') $sql_data_array['entry_company'] = $company;
    if (ACCOUNT_SUBURB == 'true') $sql_data_array['entry_suburb'] = $suburb;
    if (ACCOUNT_STATE == 'true') {
      if ($zone_id > 0) {
        $sql_data_array['entry_zone_id'] = $zone_id;
        $sql_data_array['entry_state'] = '';
      } else {
        $sql_data_array['entry_zone_id'] = '0';
        $sql_data_array['entry_state'] = $state;
      }
    }

    zen_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);

    $address_id = $db->Insert_ID();
    $zco_notifier->notify('NOTIFY_MODULE_NO_ACCOUNT_ADDED_ADDRESS_BOOK_RECORD', array_merge(array('address_id' => $address_id), $sql_data_array));
    $sql = "update " . TABLE_CUSTOMERS . "
              set customers_default_address_id = '" . (int)$address_id . "'
              where customers_id = '" . (int)$_SESSION['customer_id'] . "'";

    $db->Execute($sql);

    $sql = "insert into " . TABLE_CUSTOMERS_INFO . "
                          (customers_info_id, customers_info_number_of_logons,
                           customers_info_date_account_created, customers_info_date_of_last_logon)
              values ('" . (int)$_SESSION['customer_id'] . "', '1', now(), now())";

    $db->Execute($sql);

    if (SESSION_RECREATE == 'True') {
      zen_session_recreate();
    }

    $_SESSION['customer_first_name'] = $firstname;
    $_SESSION['customer_default_address_id'] = $address_id;
    $_SESSION['customer_country_id'] = $country;
    $_SESSION['customer_zone_id'] = $zone_id;
    $_SESSION['customers_authorization'] = $customers_authorization;

    // restore cart contents
    $_SESSION['cart']->restore_contents();

    // hook notifier class
    $zco_notifier->notify('NOTIFY_LOGIN_SUCCESS_VIA_NO_ACCOUNT');
    

    if ($_SESSION['cart']->count_contents() > 0)
      zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
    else
      zen_redirect(zen_href_link(FILENAME_SHOPPING_CART)); 
  } //endif !error
}


/*
 * Set flags for template use:
 */
  $selected_country = (isset($_POST['zone_country_id']) && $_POST['zone_country_id'] != '') ? $country : SHOW_CREATE_ACCOUNT_DEFAULT_COUNTRY;
  $flag_show_pulldown_states = ((($process == true || $entry_state_has_zones == true) && $zone_name == '') || ACCOUNT_STATE_DRAW_INITIAL_DROPDOWN == 'true' || $error_state_input) ? true : false;
  $state = ($flag_show_pulldown_states) ? ($state == '' ? ' ' : $state) : $zone_name;
  $state_field_label = ($flag_show_pulldown_states) ? '' : ENTRY_STATE;

  if (!isset($email_format)) $email_format = (ACCOUNT_EMAIL_PREFERENCE == '1' ? 'HTML' : 'TEXT');
  if (!isset($newsletter))   $newsletter = (ACCOUNT_NEWSLETTER_STATUS == '1' ? false : true);

// This should be last line of the script:
$zco_notifier->notify('NOTIFY_MODULE_END_NO_ACCOUNT');
31 Oct 2012, 12:04 PM
#19
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Any ideas on how to do this based on language? I tried this:

if ($_SESSION['languages_id'] == '1') {
 $sql_data_array(['customers_group_pricing'] => '3');
 } else {
 if ($_SESSION['languages_id'] == '3') {
 $sql_data_array(['customers_group_pricing'] => '7');
 }

But it locked up my page... I'm not great at php, so not sure where I am going wrong. If anyone can point me in the right direction, I would appreciate it! Thanks!

2 Nov 2012, 9:28 PM
#20
abcisme avatar

abcisme

Zen Follower

Join Date:
Jun 2006
Posts:
298
Plugin Contributions:
0

Re: New customers automatically join defined pricing group

Just in case anyone is looking to do this, here is what worked for me.. just modify it to suit your corresponding language/group numbers.

if($_SESSION['languages_id']==1){$customer_group_pricing=3;}
      elseif($_SESSION['languages_id']==3){$customer_group_pricing=7;}
      else{$customer_group_pricing = 3;}

    $sql_data_array = array('customers_firstname' => $firstname,
                            'customers_lastname' => $lastname,
                            'customers_email_address' => $email_address,
                            'customers_nick' => $nick,
                            'customers_telephone' => $telephone,
                            'customers_fax' => $fax,
                            'customers_newsletter' => (int)$newsletter,
                            'customers_email_format' => $email_format,
                            'customers_default_address_id' => 0,
    			    'customers_group_pricing' => $customer_group_pricing,
                            'customers_password' => zen_encrypt_password($password),
                            'customers_authorization' => (int)CUSTOMERS_APPROVAL_AUTHORIZATION
    );