Jump to content

Edit History

Laetitia Bordon

Laetitia Bordon


correction du code

Le "matricule" se trouve dans "vat_number" et le "service" dans "address1", tous 2 dans l'adresse :

Ajouter le matricule et le service dans la liste des customers :

Dans src/Core/Grid/Query/CustomerQueryBuilder.php, ajouter:

* vat_number & address1 ligne 81, 196, 197

* left join avec address lignes 127 -> 132

* ajouter lastname et firstname dans la liste des champs ligne 204 sinon les filtres sur nom ou prénom ne fonctionnent pas et vous avez une erreur 500

* les filtres dans query lignes 212 -> 217

* les 2 champs en tri lignes 270 -> 274

public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria) 
{ 
	$searchQueryBuilder = $this->getCustomerQueryBuilder($searchCriteria) 
		->select('c.id_customer, c.firstname, c.lastname, c.email, c.active, c.newsletter, c.optin') 
		->addSelect('c.date_add, gl.name as social_title, s.name as shop_name, c.company, adr.vat_number as vat_number, adr.address1 as address1');

...

private function getCustomerQueryBuilder(SearchCriteriaInterface $searchCriteria) 
{ 
	$queryBuilder = $this->connection->createQueryBuilder() 
		->from($this->dbPrefix . 'customer', 'c') 
		->leftJoin( 'c', $this->dbPrefix . 'gender_lang', 'gl', 'c.id_gender = gl.id_gender AND gl.id_lang = :context_lang_id' ) 
		->leftJoin( 'c', $this->dbPrefix . 'shop', 's', 'c.id_shop = s.id_shop' ) 
		->leftJoin( 'c', $this->dbPrefix . 'address', 'adr', 'c.id_customer = adr.id_customer AND adr.deleted = 0 AND adr.active = 1' )

...

private function applyFilters(array $filters, QueryBuilder $qb) 
{ 
	$allowedFilters = [ 'id_customer', 'social_title', 'firstname', 'lastname', 'email', 'active', 'newsletter', 'optin', 'date_add', 'company', 'vat_number', 'address1', ];
	foreach ($filters as $filterName => $filterValue) 
	{ 
		if (!in_array($filterName, $allowedFilters)) { continue; } 
		if (in_array($filterName, ['active', 'newsletter', 'optin', 'id_customer', 'lastanem', 'firstname'])) { $qb->andWhere('c.`' . $filterName . '` = :' . $filterName); $qb->setParameter($filterName, $filterValue); continue; } 
		if (in_array($filterName, ['vat_number', 'address1'])) { $qb->andWhere('adr.`' . $filterName . '` LIKE :' . $filterName); $qb->setParameter($filterName, '%' . $filterValue . '%'); continue; }

...

private function applySorting(QueryBuilder $searchQueryBuilder, SearchCriteriaInterface $searchCriteria) 
{ 
	switch ($searchCriteria->getOrderBy()) 
	{ 
		case 'id_customer': 
		case 'firstname': 
		case 'lastname': 
		case 'email': 
		case 'date_add': 
		case 'company': 
		case 'active': 
		case 'newsletter': 
		case 'optin': 
			$orderBy = 'c.' . $searchCriteria->getOrderBy(); 
			break; 
		case 'vat_number': 
		case 'address1': 
			$orderBy = 'adr.' . $searchCriteria->getOrderBy();
			break;

Dans src/Core/Grid/Definition/Factory/CustomerGridDefinitionFactory.php, ajouter les champs dans :

* getColumns() lignes 157 -> 170

* getFilters() lignes 342 -> 361

Mettre en commentaire les lignes 189 -> 208 et 366 -> 373 

//Dans protected function getColumns() :

		->add( (new DataColumn('vat_number')) 
			->setName($this->trans('VAT number', [], 'Shop.Forms.Labels')) 
			->setOptions([ 'field' => 'vat_number', ]) ) 
		->add( (new DataColumn('address1')) 
			->setName($this->trans('Address', [], 'Shop.Forms.Labels')) 
			->setOptions([ 'field' => 'address1', ]) )
...

/* je n'en n'ai pas besoin
		->add( (new ToggleColumn('newsletter')) 
			->setName($this->trans('Newsletter', [], 'Admin.Global')) 
			->setOptions([ 
				'field' => 'newsletter', 
				'primary_field' => 'id_customer', 
				'route' => 'admin_customers_toggle_newsletter_subscription', 
				'route_param_name' => 'customerId', ]) ) 
		->add( (new ToggleColumn('optin')) 
			->setName($this->trans('Partner offers', [], 'Admin.Orderscustomers.Feature')) 
			->setOptions([ 
				'field' => 'optin', 
				'primary_field' => 'id_customer', 
				'route' => 'admin_customers_toggle_partner_offer_subscription', 
				'route_param_name' => 'customerId', ]) )*/
...

//Dans protected function getFilters() :


			->add(
                (new Filter('vat_number', TextType::class))
                ->setTypeOptions([
                    'attr' => [
                        'placeholder' => $this->trans('VAT number', [], 'Shop.Forms.Labels'),
                    ],
                    'required' => false,
                ])
                ->setAssociatedColumn('vat_number')
            )
			->add(
                (new Filter('address1', TextType::class))
                ->setTypeOptions([
                    'attr' => [
                        'placeholder' => $this->trans('Address', [], 'Shop.Forms.Labels'),
                    ],
                    'required' => false,
                ])
                ->setAssociatedColumn('address1')
            )
...
           /* ->add(
                (new Filter('newsletter', YesAndNoChoiceType::class))
                ->setAssociatedColumn('newsletter')
            )
            ->add(
                (new Filter('optin', YesAndNoChoiceType::class))
                ->setAssociatedColumn('optin')
            )*/

Attention, si vous prenez des champs existants (comme j'ai fait), pensez à changer les traductions dans app/Resources/translations (je l'ai fait par là plutôt que par le BO).

Et bien sur, si vous faites des mises à jour de module, vous risquez de devoir refaire cela. Mais comme nous fonctionnons en interne, ça ne devrait pas poser de soucis chez nous.

Laetitia Bordon

Laetitia Bordon

Le "matricule" se trouve dans "vat_number" et le "service" dans "address1", tous 2 dans l'adresse :

Ajouter le matricule et le service dans la liste des customers :

Dans src/Core/Grid/Query/CustomerQueryBuilder.php, ajouter:

* vat_number & address1 ligne 81, 196, 197

* left join avec address lignes 127 -> 132

* les filtres dans query lignes 212 -> 217

* les 2 champs en tri lignes 270 -> 274

public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria) 
{ 
	$searchQueryBuilder = $this->getCustomerQueryBuilder($searchCriteria) 
		->select('c.id_customer, c.firstname, c.lastname, c.email, c.active, c.newsletter, c.optin') 
		->addSelect('c.date_add, gl.name as social_title, s.name as shop_name, c.company, adr.vat_number as vat_number, adr.address1 as address1');

...

private function getCustomerQueryBuilder(SearchCriteriaInterface $searchCriteria) 
{ 
	$queryBuilder = $this->connection->createQueryBuilder() 
		->from($this->dbPrefix . 'customer', 'c') 
		->leftJoin( 'c', $this->dbPrefix . 'gender_lang', 'gl', 'c.id_gender = gl.id_gender AND gl.id_lang = :context_lang_id' ) 
		->leftJoin( 'c', $this->dbPrefix . 'shop', 's', 'c.id_shop = s.id_shop' ) 
		->leftJoin( 'c', $this->dbPrefix . 'address', 'adr', 'c.id_customer = adr.id_customer AND adr.deleted = 0 AND adr.active = 1' )

...

private function applyFilters(array $filters, QueryBuilder $qb) 
{ 
	$allowedFilters = [ 'id_customer', 'social_title', 'firstname', 'lastname', 'email', 'active', 'newsletter', 'optin', 'date_add', 'company', 'vat_number', 'address1', ];
	foreach ($filters as $filterName => $filterValue) 
	{ 
		if (!in_array($filterName, $allowedFilters)) { continue; } 
		if (in_array($filterName, ['active', 'newsletter', 'optin', 'id_customer'])) { $qb->andWhere('c.`' . $filterName . '` = :' . $filterName); $qb->setParameter($filterName, $filterValue); continue; } 
		if (in_array($filterName, ['vat_number', 'address1'])) { $qb->andWhere('adr.`' . $filterName . '` LIKE :' . $filterName); $qb->setParameter($filterName, '%' . $filterValue . '%'); continue; }

...

private function applySorting(QueryBuilder $searchQueryBuilder, SearchCriteriaInterface $searchCriteria) 
{ 
	switch ($searchCriteria->getOrderBy()) 
	{ 
		case 'id_customer': 
		case 'firstname': 
		case 'lastname': 
		case 'email': 
		case 'date_add': 
		case 'company': 
		case 'active': 
		case 'newsletter': 
		case 'optin': 
			$orderBy = 'c.' . $searchCriteria->getOrderBy(); 
			break; 
		case 'vat_number': 
		case 'address1': 
			$orderBy = 'adr.' . $searchCriteria->getOrderBy();
			break;

Dans src/Core/Grid/Definition/Factory/CustomerGridDefinitionFactory.php, ajouter les champs dans :

* getColumns() lignes 157 -> 170

* getFilters() lignes 342 -> 361

Mettre en commentaire les lignes 189 -> 208 et 366 -> 373 

//Dans protected function getColumns() :

		->add( (new DataColumn('vat_number')) 
			->setName($this->trans('VAT number', [], 'Shop.Forms.Labels')) 
			->setOptions([ 'field' => 'vat_number', ]) ) 
		->add( (new DataColumn('address1')) 
			->setName($this->trans('Address', [], 'Shop.Forms.Labels')) 
			->setOptions([ 'field' => 'address1', ]) )
...

/* je n'en n'ai pas besoin
		->add( (new ToggleColumn('newsletter')) 
			->setName($this->trans('Newsletter', [], 'Admin.Global')) 
			->setOptions([ 
				'field' => 'newsletter', 
				'primary_field' => 'id_customer', 
				'route' => 'admin_customers_toggle_newsletter_subscription', 
				'route_param_name' => 'customerId', ]) ) 
		->add( (new ToggleColumn('optin')) 
			->setName($this->trans('Partner offers', [], 'Admin.Orderscustomers.Feature')) 
			->setOptions([ 
				'field' => 'optin', 
				'primary_field' => 'id_customer', 
				'route' => 'admin_customers_toggle_partner_offer_subscription', 
				'route_param_name' => 'customerId', ]) )*/
...

//Dans protected function getFilters() :


			->add(
                (new Filter('vat_number', TextType::class))
                ->setTypeOptions([
                    'attr' => [
                        'placeholder' => $this->trans('VAT number', [], 'Shop.Forms.Labels'),
                    ],
                    'required' => false,
                ])
                ->setAssociatedColumn('vat_number')
            )
			->add(
                (new Filter('address1', TextType::class))
                ->setTypeOptions([
                    'attr' => [
                        'placeholder' => $this->trans('Address', [], 'Shop.Forms.Labels'),
                    ],
                    'required' => false,
                ])
                ->setAssociatedColumn('address1')
            )
...
           /* ->add(
                (new Filter('newsletter', YesAndNoChoiceType::class))
                ->setAssociatedColumn('newsletter')
            )
            ->add(
                (new Filter('optin', YesAndNoChoiceType::class))
                ->setAssociatedColumn('optin')
            )*/

Attention, si vous prenez des champs existants (comme j'ai fait), pensez à changer les traductions dans app/Resources/translations (je l'ai fait par là plutôt que par le BO).

Et bien sur, si vous faites des mises à jour de module, vous risquez de devoir refaire cela. Mais comme nous fonctionnons en interne, ça ne devrait pas poser de soucis chez nous.

×
×
  • Create New...