need to add data to a new database table on creat account sucsess but how?
Hi,
As Title says, I need to add data to a new database table I've made when a customer create a new account but I don't really want to place code in the "includes\modules\create_account.php" what's the best way to do this please?
Or if the only way is to is the named file above where in the file would be best to place the code I'm only thinking this is the best place as i need the new customer ID number.
This is a new site not live yet so being able to get this working from day one of going live means all customers are included from the start.
Re: need to add data to a new database table on creat account sucsess but how?
I think I've found the best place I can do this , that being "includes\templates\MYTEMPLATE\templates\tpl_create_account_success_default. php"
Re: need to add data to a new database table on creat account sucsess but how?
I think modules/create_account.php logically is the best place for this.
Look for this code -
$result = $customer->create($data);
if (!empty($result)) {
$customer->login($result['customers_id'], $restore_cart = true);
if (SESSION_RECREATE == 'True') {
zen_session_recreate();
}
}
and place your code after.
Re: need to add data to a new database table on creat account sucsess but how?
A better approach would be to create an observer to catch the NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT notification sent by modules/create_account.php
That way you avoid editing core files so your changes can be in a separate file and will not need to be re-applied following an upgrade. I don't know what information you need to write to the database but that notification provides the new user's e-mail address, among other things, which should allow you to look up the user's info.
Re: need to add data to a new database table on creat account sucsess but how?
Quote:
Originally Posted by
BillJ
A better approach would be to create an observer to catch the NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT notification sent by modules/create_account.php
That way you avoid editing core files so your changes can be in a separate file and will not need to be re-applied following an upgrade. I don't know what information you need to write to the database but that notification provides the new user's e-mail address, among other things, which should allow you to look up the user's info.
:thumbsup:
Re: need to add data to a new database table on creat account sucsess but how?
Quote:
Originally Posted by
BillJ
A better approach would be to create an observer to catch the NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT notification sent by modules/create_account.php
That way you avoid editing core files so your changes can be in a separate file and will not need to be re-applied following an upgrade. I don't know what information you need to write to the database but that notification provides the new user's e-mail address, among other things, which should allow you to look up the user's info.
Thank you for this, as this is what I was think of first.
Now my question is:
I have multi points I would like to observer to catch actions and save to database tables I've made, they are:
NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT
NOTIFY_PRODUCT_VIEWS_HIT_INCREMENTOR
and I somehow need to also catch the following:
products_options_id,
products_options_value_id,
products_options_value_text
and possible if it is really relevant products_options_sort_order if this doesn't change?
Can this all be done within one files or is it best to have a file for create_account, one for product viewed and one for product options as each go into there own different database tables?
Re: need to add data to a new database table on creat account sucsess but how?
Quote:
Originally Posted by
OJ_SIMON
Thank you for this, as this is what I was think of first.
Now my question is:
I have multi points I would like to observer to catch actions and save to database tables I've made, they are:
NOTIFY_LOGIN_SUCCESS_VIA_CREATE_ACCOUNT
NOTIFY_PRODUCT_VIEWS_HIT_INCREMENTOR
and I somehow need to also catch the following:
products_options_id,
products_options_value_id,
products_options_value_text
and possible if it is really relevant products_options_sort_order if this doesn't change?
Can this all be done within one files or is it best to have a file for create_account, one for product viewed and one for product options as each go into there own different database tables?
My suggestion is to have a single file that watches for those multiple (but similar) notifications. It'll help you keep your sanity and you'll have only one file to update if you need to make changes!
2 Attachment(s)
Re: need to add data to a new database table on creat account sucsess but how?
I can't get the below to work nothing is inserted in to the database,
can you help me on this please.
this is the code I have in includes\classes\observers\class.bh_products_viewed_counter.php
PHP Code:
<?php
/** * @copyright Copyright 2003-2022 Zen Cart Development Team * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0 * @version $Id: DrByte 2020 Jul 28 Modified in v1.5.8-alpha $ * * Designed for v1.5.7 */
class bh_products_viewed_counter extends base{ function __construct() { $this->attach($this, array('NOTIFY_PRODUCT_VIEWS_HIT_INCREMENTOR')); } function update(&$class, $eventID, $paramsArray = array()) { global $db;
$sql = "INSERT INTO `ctgvzfpjxs`.`customers_browsing_history` AS `customers_browsing_history` (`products_id`, `customers_id`, `date_added`) VALUES (" . (int) $paramsArray . ", " . (int) $_SESSION['customer_id'] . ", now())"; $res = $db->Execute($sql); }
}
this is the code I have in admin\includes\extra_datafiles\browsing_history_database_tables.php
and in includes\extra_datafiles\browsing_history_database_tables.php
PHP Code:
<?php
/** * browsing history Database Table Name Definitions. * * @package browsing history * @author Simon * @copyright Copyright 2023-2024 Simon * @copyright Portions Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @link * @license http://www.gnu.org/copyleft/gpl.html GNU Public License V2.0 * @version $Id: browsing_history_database_tables.php 07-03-2024 Simon $ */
if (!defined('DB_PREFIX')) { define('DB_PREFIX', '');}
define('TABLE_BROWSING_HISTORY', DB_PREFIX . 'browsing_history');define('TABLE_CUSTOMERS_BROWSING_HISTORY', DB_PREFIX . 'customers_browsing_history');
this is the database table
Attachment 20537
Re: need to add data to a new database table on creat account sucsess but how?
did you ever get this working?
it seems your observer is not loading. i would use an auto loading observer. review this info:
https://docs.zen-cart.com/dev/code/n...aded-observers
in addition, i am not sure why you have that DB_PREFIX define added in the extra files. it is not used in your observer, as well as looking wrong. from your code it seems your DB_PREFIX is ctgvzfpjxs.
finally for this line:
PHP Code:
VALUES (" . (int) $paramsArray . ", " . (int) $_SESSION['customer_id'] . ", now())";
for the notifier that you are observing, the $paramsArray is passing an integer. it is always passing (int)$_GET['products_id']. you can safely change that to:
PHP Code:
VALUES (" . (int)$_GET['products_id'] . ", " . (int) $_SESSION['customer_id'] . ", now())";
best.
Re: need to add data to a new database table on creat account sucsess but how?
Quote:
Originally Posted by
carlwhat
did you ever get this working?
it seems your observer is not loading. i would use an auto loading observer. review this info:
https://docs.zen-cart.com/dev/code/n...aded-observers
in addition, i am not sure why you have that DB_PREFIX define added in the extra files. it is not used in your observer, as well as looking wrong. from your code it seems your DB_PREFIX is ctgvzfpjxs.
finally for this line:
PHP Code:
VALUES (" . (int) $paramsArray . ", " . (int) $_SESSION['customer_id'] . ", now())";
for the notifier that you are observing, the $paramsArray is passing an integer. it is always passing (int)$_GET['products_id']. you can safely change that to:
PHP Code:
VALUES (" . (int)$_GET['products_id'] . ", " . (int) $_SESSION['customer_id'] . ", now())";
best.
Yes I got it to working in the end.
I did end up using a auto loading observer.
and just now tied up by removing the DB_PREFIX and ctgvzfpjxs (which is the DB was not sure why i had put it in .
as to $paramsArray i had changed this buy i could not just use the get product id because i have to do some if statements to take in to account some option controles I have give to customer to contral there wishes.
So now my customer have products they have view in the past offered to them in different places on my site.