Jump to content

[SOLVED] Add new column to admin product list presta 1.7.8


Nikita9999

Recommended Posts

Hi,

I want to add a new column to backoffice list of product, so I've created a module to do that, here is the list of what I think I'll need to do and my questions :

Override twig file : 

  • Done : modules/cs_displaysupplier/views/PrestaShop/Admin/Product/CatalogPage/Lists/list.html.twig -> add the new column for each product
  • Done : modules/cs_displaysupplier/views/PrestaShop/Admin/Product/CatalogPage/Lists/products_table.html.twig -> add the title of my new column + filter ok it's working
  • ToDo : I need to bring the supplier reference to my twig file, I wanted to use a static method : ProductSupplier::getSupplierCollection but it's not possible directly inside the twig file, I've found this method : https://stackoverflow.com/questions/32920217/how-to-call-static-function-in-symfony2-twig-template#46636220 but I don't know wich controller do I need to override to do that ?
  • Todo : I need to add the filter for the column -> is it possible to override the file /src/PrestaShopBundle/Entity/AdminFilter.php ?

Perhaps there is an easiest way to do that ?

thanks

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

Hi
Use  actionAdminProductsListingFieldsModifier hook in your module. 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;
        }
    }


Thank you 

  • Like 2
Link to comment
Share on other sites

  • Nikita9999 changed the title to [SOLVED] Add new column to admin product list presta 1.7.8
  • 1 year later...
On 12/13/2021 at 4:30 AM, Nikita9999 said:

Hi,

I want to add a new column to backoffice list of product, so I've created a module to do that, here is the list of what I think I'll need to do and my questions :

Override twig file : 

  • Done : modules/cs_displaysupplier/views/PrestaShop/Admin/Product/CatalogPage/Lists/list.html.twig -> add the new column for each product
  • Done : modules/cs_displaysupplier/views/PrestaShop/Admin/Product/CatalogPage/Lists/products_table.html.twig -> add the title of my new column + filter ok it's working
  • ToDo : I need to bring the supplier reference to my twig file, I wanted to use a static method : ProductSupplier::getSupplierCollection but it's not possible directly inside the twig file, I've found this method : https://stackoverflow.com/questions/32920217/how-to-call-static-function-in-symfony2-twig-template#46636220 but I don't know wich controller do I need to override to do that ?
  • Todo : I need to add the filter for the column -> is it possible to override the file /src/PrestaShopBundle/Entity/AdminFilter.php ?

Perhaps there is an easiest way to do that ?

thanks

Hello please I'm new to prestashop, can you share the module you created please?

Link to comment
Share on other sites

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