Jump to content

Add new custom field in customers list - backend - PrestaShop 1.7.


Recommended Posts

Hi all, 

I need to add two new fields in customers listing, in backend, in PrestaShop 1.7.

These two new fields are two new fields created in the table named ps_customer, in particular, optin1 and optin2.

I read official doc, like this: https://devdocs.prestashop.com/1.7/modules/concepts/templating/admin-views/

But I have not it clear at all, for customers listings...

Could you help me?

Thanks in advance.

Link to comment
Share on other sites

I solved it, thanks to these two posts:

1. https://devdocs.prestashop.com/1.7/development/components/grid/tutorials/modify-grid-in-module/

2. https://webkul.com/blog/adding-a-new-column-in-prestashop-new-symfony-admin-controller-grid-page-with-module/

Summary, thanks to hooks actionCustomerGridDefinitionModifier and actionCustomerGridQueryBuilderModifier

Best regards.

  • Like 2
Link to comment
Share on other sites

  • 4 months later...
On 12/3/2019 at 9:30 AM, garciasanchezdani said:

I solved it, thanks to these two posts:

1. https://devdocs.prestashop.com/1.7/development/components/grid/tutorials/modify-grid-in-module/

2. https://webkul.com/blog/adding-a-new-column-in-prestashop-new-symfony-admin-controller-grid-page-with-module/

Summary, thanks to hooks actionCustomerGridDefinitionModifier and actionCustomerGridQueryBuilderModifier

Best regards.

Hello,

yeah it looks like easy one, but I have one question - where exactly I should put code from Webkuls tutorial? It should be new module? Or put it in some controller?

 

Best regards

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
4 hours ago, garciasanchezdani said:

Yes, always try to use overrides or hooks.

thank  you for your response @garciasanchezdani.

but other questions is .. ..

 

we can override this files ?

 

Quote

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType;

https://webkul.com/blog/adding-a-new-column-in-prestashop-new-symfony-admin-controller-grid-page-with-module/

Link to comment
Share on other sites

  • 1 year later...

@Vincent Decaux Thanks for the example you provided.

I'm having trouble modifying it for my needs.

The SQL in particular I can't get my head around. I have this but it's not working...

		  $searchQueryBuilder->leftJoin(
            'c',
            '`' . pSQL(_DB_PREFIX_) . 'customer`',
            'pa',
            'pa.`id_customer` = c.`id_customer`
                 = (
                    SELECT
                      pa2.`agecheck`
                    FROM
                      `'. pSQL(_DB_PREFIX_) .'customer` pa2
                    WHERE pa2.`id_customer` = pa.`id_customer`
                    ORDER BY LENGTH(pa2.`agecheck`) DESC
                    LIMIT 1
                )'
        );

The field I'm trying to get is in ps_customer and is called agecheck.

Im guessing it might not need the "leftJoin" part ?

Any chance you could point me in the right direction :)

Thanks

Ray

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

That simple hey lol.

Thank you, it is now showing and filling in the column.

agecheck.jpg.b6c82892ece246c5a74c8bd469eb1ffe.jpg

Is there a list of these hooks available? The next one I'm looking for is the orders list page. It needs to show the same on that page.

Ive tried, in the same module the following code (it does nothing)

		// Create hook in Order List
    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        /** @var GridDefinitionInterface $definition */
        $definition = $params['definition'];

        $definition
            ->getColumns()
            ->addAfter(
                'total',
                (new DataColumn('agecheck'))
                    ->setName($this->l('18?'))
                    ->setOptions([
                        'field' => 'agecheck',
                    ])
		)
			 ->addAfter(
                'agecheck',
                (new DataColumn('agecheckdate'))
                    ->setName($this->l('Check Date'))
                    ->setOptions([
                        'field' => 'agecheckdate',
                    ])
		);

		
        // For search filter
        $definition->getFilters()->add(
            (new Filter('agecheck', TextType::class))
                ->setAssociatedColumn('agecheck')
        );
    }

 

Can multiple hooks be done in this one module ?

The 3rd one, and last one, will be on the customer B.O profile page. This will have the 2 following fields which will be editable

		$searchQueryBuilder->addSelect( 'c.`agecheck`' );
		$searchQueryBuilder->addSelect( 'c.`agecheckdate`' );

 

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

Ok so I forgot to add the hooks

    public function install()
    {
        return (
            parent::install()
            && $this->registerHook('actionCustomerGridDefinitionModifier')
            && $this->registerHook('actionCustomerGridQueryBuilderModifier')
            && $this->registerHook('actionOrderGridDefinitionModifier')
            && $this->registerHook('actionOrderGridQueryBuilderModifier')
        );
    }

It is now showing the new field, just not filling data yet.

After some thought, I'm thinking this one does now need the leftJoin 😕

So I tried this

// join the customer table to get the pass details
        $searchQueryBuilder->leftJoin(
            'c',
            '`' . pSQL( _DB_PREFIX_ ) . 'customer`',
            'pa',
            'pa.`id_customer` = c.`id_customer`
			AND pa.`id_customer` = (
			SELECT
			pa2.`id_customer`
                FROM
                  `' . pSQL( _DB_PREFIX_ ) . 'customer` pa2
                WHERE pa2.`id_customer` = pa.`id_customer`
                ORDER BY LENGTH(pa2.`agecheck`) DESC
                LIMIT 1
            )'
        );

and get the error "Call to a member function leftJoin() on null"

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

HI @Vincent Decaux,

That seems to be an old post.

I have the fields both appearing in the orders list, and the customer edit page, I just can't get them to fill with data.

customer_profile.png.a99fc0bd43a35124a4c0bd2154777df3.png

It's probably the SQL statement that I cannot get right.

Here is my code now.

<?php

if (!defined('_PS_VERSION_')) {
    exit;
}

use PrestaShop\PrestaShop\Core\Grid\Column\Type\DataColumn;
use PrestaShop\PrestaShop\Core\Grid\Filter\Filter;
use Symfony\Component\Form\Extension\Core\Type\TextType;

class AgeCheck extends Module
{
	/**
     * List of hooks used
     */
    const HOOKS = [
        'actionCustomerGridDefinitionModifier',
        'actionCustomerGridQueryBuilderModifier',
        'actionCustomerFormBuilderModifier',
        'actionOrderGridDefinitionModifier',
        'actionOrderGridQueryBuilderModifier',
    ];
	
    public function __construct()
    {
        $this->name = 'agecheck';
        $this->tab = 'administration';
        $this->version = '1.0.0';
        $this->author = 'Ray Rigby';

        parent::__construct();

        $this->displayName = $this->trans('Age Check for Customer');
        $this->description = $this->trans('Add the extra B.O fields for the Age Verification records');
    }

    public function install()
    {
        return parent::install()
			&& $this->registerHook(static::HOOKS);
    }

    public function uninstall()
    {
        return parent::uninstall();
    }

	// ****************************** CUSTOMER LIST ****************************** 
	
	// Create new column in Customer List
    public function hookActionCustomerGridDefinitionModifier(array $params)
    {
				
        $definition = $params['definition'];

        $definition
            ->getColumns()
            ->addAfter(
                'email',
                (new DataColumn('agecheck'))
                    ->setName($this->l('18?'))
                    ->setOptions([
                        'field' => 'agecheck',
                    ])
		);
		
		/** Remove the following columns */
		$columns = $definition->getColumns();
		$columns->remove('social_title')
			->remove('active')
			->remove('optin')
			->remove('newsletter')
			;
		
		/** Remove the following filters */
		$filters = $definition->getFilters();
		$filters->remove('social_title')
			->remove('active')
			->remove('optin')
			->remove('newsletter')
			;

    }
	
	    /**
     * Add data to the new field in Customer List
     */
    public function hookActionCustomerGridQueryBuilderModifier(array $params)
    {
        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
		
		$searchQueryBuilder->addSelect( 'c.`agecheck`' );
    }
	
	
		// ****************************** CUSTOMER PAGE ****************************** 
	
	// Create new column in Customer List
    public function hookActionCustomerFormBuilderModifier(array $params)
    {
    $formBuilder = $params['form_builder'];
		
    $allFields = $formBuilder->all();
    foreach ($allFields as $inputField => $input) {
        $formBuilder->remove($inputField);
    }
		
    foreach ($allFields as $inputField => $input) {
        $formBuilder->add($input);
        if ($inputField == 'email') {
            /** @var TextType::class \Symfony\Component\Form\Extension\Core\Type\TextType */
            $formBuilder->add(
                'agecheck', 
                 TextType::class, 
                 ['label' => 'Age Verified ?']
            );
			$formBuilder->add(
                'agecheckdate', 
                 TextType::class, 
                 ['label' => 'Date of Check']
            );
			
        }
     }
		
		$formBuilder->get('agecheck')->setRequired(false);
		$formBuilder->get('agecheckdate')->setRequired(false);
  }
	
	    
     // Add data to the new field in Customer List
    
    public function hookActionCustomerFormQueryBuilderModifier(array $params)
    {
        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
		
		$searchQueryBuilder->addSelect( 'c.`agecheck`' );
		$searchQueryBuilder->addSelect( 'c.`agecheckdate`' );
    } 
	
	
	// ****************************** ORDER LIST ******************************

		// Create hook in Order List
    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        /** @var GridDefinitionInterface $definition */
        $definition = $params['definition'];

        $definition
            ->getColumns()
            ->addAfter(
                'customer',
                (new DataColumn('agecheck'))
                    ->setName($this->l('18?'))
                    ->setOptions([
                        'field' => 'agecheck',
                    ])
		);
    }
	
		    /**
     * Add data to the new field in Order List
     */
    public function hookActionOrderGridQueryBuilderModifier( array $params ) {

		$searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
		
		/** $searchQueryBuilder->addSelect( 'c.`agecheck`' );*/
		$searchQueryBuilder->leftJoin(
            'c',
            '`' . pSQL(_DB_PREFIX_) . 'customer`',
            'pa',
            'pa.`id_customer` = c.`id_customer`
                 = (
                    SELECT
                      pa2.`agecheck`
                    FROM
                      `'. pSQL(_DB_PREFIX_) .'customer` pa2
                    WHERE pa2.`id_customer` = pa.`id_customer`
                    ORDER BY LENGTH(pa2.`agecheck`) DESC
                    LIMIT 1
                )'
        );

    }

	


	
}

I'm not sure what the 'c', 'pa' & 'pa2' refer to, so I'm stuck there at the moment.

I'm also struggling to find the code to make this into a date picker field

$formBuilder->add(
                'agecheckdate', 
                 TextType::class, 
                 ['label' => 'Date of Check']
            );
			
        

 

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

Would anybody know the sql to enter here

$searchQueryBuilder->leftJoin(
            'c',
            '`' . pSQL(_DB_PREFIX_) . 'customer`',
            'pa',
            'pa.`id_customer` = c.`id_customer`
                 = (
                    SELECT
                      pa2.`agecheck`
                    FROM
                      `'. pSQL(_DB_PREFIX_) .'customer` pa2
                    WHERE pa2.`id_customer` = pa.`id_customer`
                    ORDER BY LENGTH(pa2.`agecheck`) DESC
                    LIMIT 1
                )'
        );

    

I need to get the column 'agecheck' from the 'ps_customer' table. The page this will be shown on is the orders list so doing a sql join from orders to customers.

And could somebody explain the format for the sql. ie, what 'c' & 'pa'/'pa2' are for.  Then maybe I can work out the correct query for myself.

Thanks

 

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

It's easy.
c = customer table
There is no need to create a JOIN on the same table.
You need to add where.
E.g.

$searchQueryBuilder->addSelect("IF(c.`agecheck` IS NULL, '--', c.`agecheck`) AS `agecheck`");

foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
	if ($filterName === 'agecheck' && $filterValue) {
		$searchQueryBuilder->andWhere("c.`agecheck` = :agecheck");
		$searchQueryBuilder->setParameter('agecheck', $filterValue);
		if (!$filterValue) {
			searchQueryBuilder->orWhere('c.`agecheck` IS NULL');
		}
	}
}

Of course you need to add your field to formBuilder.

E.g.

$formBuilder = $params['form_builder'];
$formBuilder->add('agecheck', TextType::class, [
	'label' => $this->l('Age ?'),
	'required' => false,
]);

$customerId = $params['id'];
$ageCheck = Db::getInstance()->getValue('SELECT agecheck FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$params['id']);

$params['data']['agecheck'] = $ageCheck;

$formBuilder->setData($params['data']); 

 

  • Like 1
Link to comment
Share on other sites

That's easy for you to say lol...

That part is now working fine. thankyou.

 

I am stuck (been trying most of the day) at getting the agecheckdate to fill in on the same page, and for data to save. agecheckdate is obviously a Datetype::class. The field is showing on the form but won't fill the data. (Jan 1 2017 is showing on all the customers I try)

agecheck1.png.18869d612b1b3b2d5700123824429749.png

 

here is my current code for this page

		// ****************************** CUSTOMER PAGE ****************************** 
	
	// Create new column in Customer List
    public function hookActionCustomerFormBuilderModifier(array $params)
    {
    $formBuilder = $params['form_builder'];
		
    $allFields = $formBuilder->all();
    foreach ($allFields as $inputField => $input) {
        $formBuilder->remove($inputField);
    }
		
    foreach ($allFields as $inputField => $input) {
        $formBuilder->add($input);
        if ($inputField == 'email') {
            /** @var TextType::class \Symfony\Component\Form\Extension\Core\Type\TextType */
            $formBuilder->add(
                'agecheck', 
                 TextType::class, 
                 ['label' => 'Age Verified ?']
            );
			$formBuilder->add(
                'agecheckdate', 
                 DateType::class, 
                 ['label' => 'Date of Check']
				
            );
			
        }
     }
		
		// Get data from db and assign it to variables
		$customerId = $params['id'];
		$ageCheck = Db::getInstance()->getValue('SELECT agecheck FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$params['id']);		
		$params['data']['agecheck'] = $ageCheck;
		$formBuilder->setData($params['data']); 


		$ageCheckDate = Db::getInstance()->getValue('SELECT agecheckdate FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$params['id']);
		// $params['data']['agecheckdate'] = $ageCheckDate;   <- IF I ENABLE THIS IT THROWS AN ERROR
		
		$formBuilder->setData($params['data']); 
	}
	
	    
     // Add data to the new field(s) in Customer List
    
    public function hookActionCustomerFormQueryBuilderModifier(array $params)
    {
        $searchQueryBuilder = $params("IF(c.`agecheck` IS NULL, '--', c.`agecheck`) AS `agecheck`");
		
		foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
			if ($filterName === 'agecheck' && $filterValue) {
				$searchQueryBuilder->andWhere("c.`agecheck` = :agecheck");
				$searchQueryBuilder->setParameter('agecheck', $filterValue);
				if (!$filterValue) {
					$searchQueryBuilder->orWhere('c.`agecheck` IS NULL');
				}
			}
		}
		
		$searchQueryBuilder = $params("IF(c.`agecheckdate` IS NULL, '--', c.`agecheckdate`) AS `agecheckdate`");
		
		foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
			if ($filterName === 'agecheckdate' && $filterValue) {
				$searchQueryBuilder->andWhere("c.`agecheckdate` = :agecheckdate");
				$searchQueryBuilder->setParameter('agecheckdate', $filterValue);
				if (!$filterValue) {
					$searchQueryBuilder->orWhere('c.`agecheckdate` IS NULL');
				}
			}
		}


    } 

Thanks for your help.. Ill get there one day :)

  • Like 1
Link to comment
Share on other sites

Ok So after hours of studying, I have managed to populate the field 'agecheckdate' with the data from the db

2 things im struggling with now.

1: Saving the data to the database. I am playing with this code but cant get it right.

	// Save the age check data to the db
	public function hookActionAfterUpdateCustomerFormHandler(array $params)
{
    $this->updateCustomerAgeCheck($params);
}
	private function updateCustomerAgeCheck(array $params)
{
    $customerId = $params['id'];
    /** @var array $customerFormData */
    $customerFormData = $params['form_data'];
    $ageCheck = $customerFormData['agecheck'];
    $ageCheckDate = $customerFormData['agecheckdate'];
    
    // implement review status saving here
}

2 Populating the data in the Orders list. Here is the code I'm having trouble getting right.

     // Populate data to the new field in Order List
    
   public function hookActionOrderGridQueryBuilderModifier( array $params ) {

		$searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];
		
		//$searchQueryBuilder->addSelect( 'c.`agecheck`' );
		
		$searchQueryBuilder->leftJoin(
            'c',
            '`' . pSQL(_DB_PREFIX_) . 'customer`',
            'o',
            'o.`id_customer` = c.`id_customer`
                 = (
                    SELECT
                      c.`agecheck`
                    FROM
                      `'. pSQL(_DB_PREFIX_) .'customer` 
                    WHERE o.`id_customer` = c.`id_customer`
                )'
        );

    }

any help appreciated :)

Link to comment
Share on other sites

Hi knacky,

I have the data showing in the customer profile page, it just won't save.

I used this to make the field.

			/** @var TextType::class \Symfony\Component\Form\Extension\Core\Type\DateType */
			$formBuilder->add(
                'agecheckdate', 
                 DateType::class, 
				 ['widget' => 'single_text',
				  'input'  => 'string',
				  'label' => 'Date of Check']
				
            );

I get the data from the db and populate it using this

		$ageCheckDate = Db::getInstance()->getValue('SELECT agecheckdate FROM '._DB_PREFIX_.'customer WHERE id_customer = '.$params['id']);
		$params['data']['agecheckdate'] = $ageCheckDate;

     // Populate data to the new field(s) in Customer Page
    
    public function hookActionCustomerFormQueryBuilderModifier(array $params)
    {
		$searchQueryBuilder->addSelect( 'c.`agecheck`' );
        $searchQueryBuilder->addSelect( 'c.`agecheckdate`' );
    } 

but it won't save to the db.  Here is my attempt.

	// Save the age check data to the db
	public function hookActionAfterUpdateCustomerFormHandler(array $params)
{
    $this->updateCustomerAgeCheck($params);
}
	private function updateCustomerAgeCheck(array $params)
{
    $customerId = $params['id'];
    /** @var array $customerFormData */
    $customerFormData = $params['form_data'];
    $ageCheck = $customerFormData['agecheck'];
    $ageCheckDate = $customerFormData['agecheckdate'];
    
}

 

Link to comment
Share on other sites

I understand.
And what to do if the customer changes the date of birth?
It is not a problem to calculate the age and, if it is under the age of 18, to cancel the validation and delete the check date.
Or every time the date of birth changes.

  • Like 1
Link to comment
Share on other sites

The customer create their profile.

We then have to do a check with authorities to confim they are over 18 from the details they provide.

Then we mark it to say "Pass" with the date of check so that we know we can sell to them.

It only for our records

 

  • Like 1
Link to comment
Share on other sites

Thank you so much.

I'll download now and try it.

UPDATE:

Ok so I have it installed but..
all customers have a red cross in the customer list. (the data is still in my db)
on the customer profile, the data does not save.
and lastly, the agecheck column isn't showing on the "Orders List" page

 

I have moved the agecheck to after email where its easier to see and don't need the date on the customer list so commented that out too.
The 18? column on this customer is Pass so should be a tick. Is the data in that column now a 1/0 option instead of Pass/Null

customer_list.png.698a6b3b9e0c806186fcb4645e030031.png

Edited by MerseyRay (see edit history)
  • Like 1
  • Confused 1
Link to comment
Share on other sites

And you still have your previous module installed?

Values for boolean must be 0/1 !!!

1. Make a backup of the customer table
2. uninstall your previous module
3. uninstall my module
4. install my module
5. check the hooks in position
6. upload a backup of the customer table

  • Like 1
Link to comment
Share on other sites

I have disabled my module whilst trying yours.

Ok so I have made some changes.

Moved both fields to underneath the email on the customer profile.
Updated all Pass values to 1 in the db and that is now showing the Ticks/Crosses correctly in the list, and the switch is also showing correct data in the customer profile.
Changed all occurrences of agedate to agecheckdate as this is the existing column. (Date is now showing correctly in customer profile)

So now everything is back to how I had it earlier, but using your module.

Just agecheck tick/cross is not showing in the Order list

And nothing is saving on customer profile.

NO ERRORS are showing when saving.

I have attached the 1 altered file with the alterations I made

ps_agecheck.zip

Edited by MerseyRay (see edit history)
  • Like 2
Link to comment
Share on other sites

Check if there are hooks !!!
Design> Positions

'actionCustomerGridQueryBuilderModifier',

'actionCustomerGridDefinitionModifier',

'actionAdminCustomersListingFieldsModifier',

 'actionCustomerFormBuilderModifier',

'actionAfterCreateCustomerFormHandler',

'actionAfterUpdateCustomerFormHandler',

  • Like 2
Link to comment
Share on other sites

Orders List page ?

You didn't mention it when I was writing the demo.

I haven't noticed any of your reactions to posts where the heart is gray and like 😉

You will need to create additional features for the Order List hook.

I've already spent a lot of time here and for free 🤪

 

  • Like 1
Link to comment
Share on other sites

Here's a working solution:

public function hookActionOrderGridQueryBuilderModifier(array $params)
    {

        $searchQueryBuilder = $params['search_query_builder'];

        $searchCriteria = $params['search_criteria'];

        $searchQueryBuilder->addSelect(
            'cu.`agecheck` AS `agecheck`'
        );

        if ('agecheck' === $searchCriteria->getOrderBy()) {
            $searchQueryBuilder->orderBy('cu.`agecheck`', $searchCriteria->getOrderWay());
        }

        foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
            if ('agecheck' === $searchCriteria->getOrderBy()) {
                $searchQueryBuilder->orderBy('cu.`agecheck`', $searchCriteria->getOrderWay());
            }

            if ($filterName === 'agecheck') {
                $searchQueryBuilder->andWhere("cu.`agecheck` = :agecheck");
                $searchQueryBuilder->setParameter('agecheck', $filterValue);
            }
        }
    }

    public function hookActionOrderGridDefinitionModifier(array $params)
    {
        $definition = $params['definition'];
        
        $definition->getColumns()
            ->addAfter('reference', (new StatusColumn('agecheck'))->setName($this->l('18 ?'))
            ->setOptions(
                ['field' => 'agecheck',]
            )
        );

        $definition->getFilters()->add((new Filter('agecheck', YesAndNoChoiceType::class))
            ->setAssociatedColumn('agecheck')
            ->setTypeOptions([
                'required' => false,
            ])
        );
    }

 

Edited by knacky (see edit history)
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 months later...

Hi,

module still working fine, thanks again.

Just 1 little annoying problem I have with it.

On customer creation, the "agecheckdate" is always 0000-00-00 by default.
I have tried 2001-01-01 in the Default/As defined: in the sql, but it still puts 0000-00-00 on every new customer.

This brings up an error when trying to edit the customer in B.O because 0000-00-00 isnt a valid date.

How can I either, enter a default date such as 2001-01-01 or not throw an error.

 

(To edit a customer with 0000-00-00 I have to go into the database and enter a valid date so that we can edit the customer in the B.O)

Thank you

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

its not the old records that are causing issues. It's every new customer that registers, their agecheckdate is set to 0000-00-00 even though I have set a DEFAULT in the database

I have the DEFAULT already set in db.

879592555_Screenshot2022-06-13at12-15-45913525.vps-10.com8443_localhost_ps17_modified_ps_customerphpMyAdmin5.1.3.png.7d561692909e06ff7e69a41721c9a9ce.png

Then I create a NEW customer. In the db they are all set to 0000-00-00

agechekdate.png.e3ef9ea8ff088de4ee844bc84bb183b9.png

Edited by MerseyRay (see edit history)
Link to comment
Share on other sites

The customer does not see that agecheckdate, that is B.O only.

I have just created a new joe bloggs customer as per the images above.

in the db, 0000-00-00 is the value of agecheckdate, even though I have set it to be 2021-01-01 as the DEFAULT

Link to comment
Share on other sites

I havent changed anything in the module you done for me.

So I have set the default to be 2021-01-01 in the db.

654197755_Screenshot2022-06-13at12-15-45913525.vps-10.com8443_localhost_ps17_modified_ps_customerphpMyAdmin5.1.3.png.9c724281ea96168be2f07180a89bfadd.png

Customer creates a NEW account and the agecheckdate in db is 0000-00-00 like this

agechekdate.png.48585ec5e8cd8bff81aa4370002b4b08.png

I cannot edit that customer record then as I get an error like this

error.png.7be93fa014bf851df44d1a6316771ea1.png

The error is because 0000-00-00 is not a valid date.

 

Maybe the core ps account creation process needs the variable for the agecheckdate otherwise it updates the record with a blank value/0000-00-00

Link to comment
Share on other sites

hookActionCustomerFormBuilderModifier

There is an SQL query to the age checkdate table.
Here you can edit the code to return a different date.

$getAgeDate = Db::getInstance()->getValue('SELECT agecheckdate .......
if ($getAgeDate == '0000-00-00' OR $getAgeDate == ''){
	$getAgeDate = '2021-01-01';
}

 

Edited by knacky (see edit history)
  • Like 1
Link to comment
Share on other sites

Awesome, that has solved the error issue.

Its still 0000-00-00 to start with in the db, but changes it to 2021-01-01 when I go to edit the customer so no more error.

I had to change slightly  to

if ($getageCheckDate == '0000-00-00' OR $getageCheckDate == ''){
        $getageCheckDate = '2021-01-01';
      }

Thanks so much :)

Link to comment
Share on other sites

  • 1 month later...

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