Jump to content

[Solved]Add new column in prestashop backend


daniele dexter

Recommended Posts

Hello everybody, in the product list I would like to add a new column (supplier).

 

I saw the query that is used at the moment and on db I did the test by adding what I needed.

Now my doubt is how to go about adding the LEFT JOIN to make sure it is correctly added to the current selection.

I found a guide that said to take action in the file override / controllers / admin / AdminProductsController.php

 

Here inside the __construct () function I added the following code:

parent :: __ construct ();

$ this -> _ join. = 'LEFT JOIN `pr_manufacturer` m ON p.`id_manufacturer` = m.id_manufacturer';

$ this-> fields_list ['manufacturer'] = array ( 'title' => $ this-> l ('Manufacturer'), 'filter_key' => 'm! name' );

 

I also deleted the cache / class_index.php file I don't see the new column added yet.

Can anyone help me figure out where to act or if I was wrong to write the code?

 

Thanks in advance

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

Kindly use the folowing hook for the same :  actionAdminProductsListingFieldsModifier , below code is get supplier data in your product list page

 

public function hookActionAdminProductsListingFieldsModifier($params)
    {
        $params['sql_select']['supplier'] = [
            'table' => 'sup',
            'field' => 'name',
            'filtering' => \PrestaShop\PrestaShop\Adapter\Admin\AbstractAdminQueryBuilder::FILTERING_LIKE_BOTH
        ];

        $params['sql_table']['sup'] = [
            'table' => 'supplier',
            'join' => 'LEFT JOIN',
            'on' => 'p.`id_supplier` = sup.`id_supplier`',
        ];

        $supplier_filter = Tools::getValue('filter_column_name_supplier', false);
        if ($supplier_filter && $supplier_filter != '') {
            $params['sql_where'][] .= " p.id_supplier = " . $supplier_filter;
        }
    }

Link to comment
Share on other sites

15 hours ago, Knowband Plugins said:

Kindly use the folowing hook for the same :  actionAdminProductsListingFieldsModifier , below code is get supplier data in your product list page

 

public function hookActionAdminProductsListingFieldsModifier($params)
    {
        $params['sql_select']['supplier'] = [
            'table' => 'sup',
            'field' => 'name',
            'filtering' => \PrestaShop\PrestaShop\Adapter\Admin\AbstractAdminQueryBuilder::FILTERING_LIKE_BOTH
        ];

        $params['sql_table']['sup'] = [
            'table' => 'supplier',
            'join' => 'LEFT JOIN',
            'on' => 'p.`id_supplier` = sup.`id_supplier`',
        ];

        $supplier_filter = Tools::getValue('filter_column_name_supplier', false);
        if ($supplier_filter && $supplier_filter != '') {
            $params['sql_where'][] .= " p.id_supplier = " . $supplier_filter;
        }
    }

Hello @Knowband Plugins,

i can't find the indicated hook on the Design / Positions section.

So I looked if the string was present in some file and I found it in two files:

  • public_html / src / PrestaShopBundle / Controller / Admin / ProductController.php
  • public_html / src / Adapter / Product / AdminProductDataProvider.php

In the first file I find this comment: / ** * 2 hooks are triggered here: * - actionAdminProductsListingFieldsModifier * - actionAdminProductsListingResultsModifier. * /

In the second I find it with: Hook :: exec ('actionAdminProductsListingFieldsModifier', [

 

Now I'd like to ask you where should I add the function you indicated to me.

I changed it by putting the exact name of my table and that's it.

Thanks for your help

Daniele

Link to comment
Share on other sites

On 6/21/2022 at 2:03 PM, daniele dexter said:

Hello @Knowband Plugins,

i can't find the indicated hook on the Design / Positions section.

So I looked if the string was present in some file and I found it in two files:

  • public_html / src / PrestaShopBundle / Controller / Admin / ProductController.php
  • public_html / src / Adapter / Product / AdminProductDataProvider.php

In the first file I find this comment: / ** * 2 hooks are triggered here: * - actionAdminProductsListingFieldsModifier * - actionAdminProductsListingResultsModifier. * /

In the second I find it with: Hook :: exec ('actionAdminProductsListingFieldsModifier', [

 

Now I'd like to ask you where should I add the function you indicated to me.

I changed it by putting the exact name of my table and that's it.

Thanks for your help

Daniele

@Daniele,

You need to register that hook in your module before using that. Kindly check the screenshot that the hook is present in the admin product listing page : https://nimb.ws/6u5VwX

 

Link to comment
Share on other sites

  • daniele dexter changed the title to [Solved]Add new column in prestashop backend

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