Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2023
    Location
    Hounslow
    Posts
    79
    Plugin Contributions
    0

    Default 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.

  2. #2
    Join Date
    Nov 2023
    Location
    Hounslow
    Posts
    79
    Plugin Contributions
    0

    Default 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"

  3. #3
    Join Date
    Aug 2013
    Location
    Perth, WA, AU
    Posts
    171
    Plugin Contributions
    3

    Default 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.
    Last edited by royaldave; 7 Mar 2024 at 06:26 AM.

  4. #4
    Join Date
    Sep 2013
    Location
    Devon, UK
    Posts
    76
    Plugin Contributions
    0

    Default 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.

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: need to add data to a new database table on creat account sucsess but how?

    Quote Originally Posted by BillJ View Post
    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.

  6. #6
    Join Date
    Nov 2023
    Location
    Hounslow
    Posts
    79
    Plugin Contributions
    0

    Default Re: need to add data to a new database table on creat account sucsess but how?

    Quote Originally Posted by BillJ View Post
    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?

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,498
    Plugin Contributions
    88

    Default Re: need to add data to a new database table on creat account sucsess but how?

    Quote Originally Posted by OJ_SIMON View Post
    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!

  8. #8
    Join Date
    Nov 2023
    Location
    Hounslow
    Posts
    79
    Plugin Contributions
    0

    Default 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
    Click image for larger version. 

Name:	Screenshot 2024-03-21 075955.png 
Views:	14 
Size:	23.1 KB 
ID:	20537
    Attached Images Attached Images  
    Last edited by OJ_SIMON; 21 Mar 2024 at 09:07 AM.

  9. #9
    Join Date
    Nov 2005
    Location
    los angeles
    Posts
    2,694
    Plugin Contributions
    9

    Default 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.
    author of square Webpay.
    mxWorks has premium plugins. donations: venmo or paypal accepted.
    premium consistent excellent support. available for hire.

  10. #10
    Join Date
    Nov 2023
    Location
    Hounslow
    Posts
    79
    Plugin Contributions
    0

    Default Re: need to add data to a new database table on creat account sucsess but how?

    Quote Originally Posted by carlwhat View Post
    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.

 

 

Similar Threads

  1. Restored Data in New Database but not showing
    By guyhancock in forum Upgrading from 1.3.x to 1.3.9
    Replies: 4
    Last Post: 19 Aug 2010, 11:49 AM
  2. how to show data from database table?
    By jibon in forum General Questions
    Replies: 1
    Last Post: 20 Oct 2009, 05:36 PM
  3. Register creat new account visual module?
    By marcopolo in forum General Questions
    Replies: 3
    Last Post: 9 Apr 2009, 07:46 PM
  4. Urgent Help!!----- Cant creat new account?
    By timzhou in forum Managing Customers and Orders
    Replies: 8
    Last Post: 27 Sep 2008, 09:47 PM
  5. How to insert data into a new table
    By MCanes in forum General Questions
    Replies: 3
    Last Post: 19 Feb 2008, 11:19 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR