Quote Originally Posted by davewest View Post
I tend to make a mess of things so had to spend some time looking back at my code... I started some time back with the first COWOA, then changed to FEC which had COWOA. Then I've modified things sense so not sure how this will look to you. I noticed it's still not been addressed in the new version of FEC.

I had the same issues with multiple email addresses due to more then one entry as COWOA users. Then I had one customer that after 6 checkouts without an account decided to create one. Now I had 5 entries as COWOA and one standard account with the same email.

I hate copping with such, so went back into the code and fixed the source of it all, lest it works for me.

I found that in includes/modules/YOUR_TEMPLATE/no_account.php creates the account, but never checks to see if one is already there. So I modified it as done in create_account which checks to see if COWOA account exists and updates it to become a standard account... with the modified code I'm checking for an existing COWOA account with the same email address and updating it instead of creating a new one. Thus, only one COWOA account exist for that same email address. I have the one account, but still get the orders and mailing addresses each time they order. Then if they do create a standard account, all the past orders, mailing address fall back to that user... I haven't found any problems so far.

Nab a bit of code on both sides of the modified section so to help where it all fits in...
Code:
      // create billing address
      $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' => $cowoa,
                              'customers_authorization' => (int)CUSTOMERS_APPROVAL_AUTHORIZATION
      );
      
      ////////////bof modified for existing cowoa member ////////////////////////////////////
        // check if COWOA account exists for email_address
    $cowoa_accounts = 0;
    if (FEC_NOACCOUNT_COMBINE == 'true') {
      $cowoa_account = $db->Execute("SELECT customers_id, customers_default_address_id FROM " . TABLE_CUSTOMERS . " 
                                     WHERE customers_email_address = '" . $email_address . "'
                                     ORDER BY customers_id DESC
                                     LIMIT 1;");
      $cowoa_accounts = $cowoa_account->RecordCount();
    
    }
    if ($cowoa_accounts > 0) {
      // cowoa account exists, use that
      $db_action = 'update';
      $sql_data_array['customers_id'] = $_SESSION['customer_id'] = $cowoa_account->fields['customers_id'];
      $sql_data_array['customers_default_address_id'] = $address_id = $cowoa_account->fields['customers_default_address_id'];
      $sql_data_array['COWOA_account'] = 1;
      $db_customers_where = 'customers_id = "' . $cowoa_account->fields['customers_id'] . '"'; 
    } else {
      $db_action = 'insert';
      $db_customers_where = '';
    }
    //end modified

      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, $db_action, $db_customers_where); //added for modified cowoa

          if ($db_action == 'insert') {
      $_SESSION['customer_id'] = $db->Insert_ID();
    }

      $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;
        }
      }
    
    if ($db_action == 'update') {
      $sql_data_array['address_book_id'] = $address_id;
      $db_address_table_where = 'address_book_id = ' . $address_id; 
    } else {
      $db_address_table_where = '';
    }

    zen_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array, $db_action, $db_address_table_where);

    if ($db_action == 'insert') { 
      $address_id = $db->Insert_ID();

      $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)
                values ('" . (int)$_SESSION['customer_id'] . "', '0', now())";

      $db->Execute($sql);
  }
  //////////// eof modified for existing cowoa member ////////////////////////////////////
      if (enable_shippingAddress()) {
        // create shipping address
Hopefully it makes some scene to you... I've been running it like this for almost a year and haven't found any problems. Both in live and testing it's working out, running now on zencart 1.5.1


The other thing I did so I can just email COWOA users was to make a entry for it in the quary_builder. This is just my phpmyadmin dump. Could do the same for none standard accounts by adding a COWOA_account = 0 check.

Code:
INSERT INTO `query_builder` (`query_id`, `query_category`, `query_name`, `query_description`, `query_string`, `query_keys_list`) VALUES
(, 'email', 'COWOA Customers Only', 'Returns COWOA customers name and email address for sending mass emails (ie: for newsletters, coupons, GVs, messages, etc).', 'select customers_email_address, customers_firstname, customers_lastname from TABLE_CUSTOMERS where COWOA_account = 1 order by customers_lastname, customers_firstname, customers_email_address', '');
Hey Dave...

Thanks for the share, and you are soooo right.. The e-mail list fix is a bandaid, but certainly not a long term solution.. ULTIMATELY what you posted is the RIGHT solution.. I'm afraid this is a bit over my limited skillset to figure out.. FEC's COWOA is just different enough from this module's COWOA to make it over my head to figure out what code to "borrow" from this.. I have an idea as to what I need to do, but it would be trial and error before I got it all worked out.. As an example, my first attempt to "borrow" the right code lead to a SQL duplicate record error.. I'll keep playing, but time is an issue for me, and I don't really have much to keep going at it by trial and error..

Hoping a more astute member of the community can jump in here and provide some guidance..

Again thanks for the share and the push in the right direction..