prestashopprestashop-1.7prestashop-modules

Prestashop - bulk action on products grid


I need create action for selected products on admin products grid in my module. Like for now have presta implemented products group delete, copy, activate/deactivate. I first tried create bulk action for customers grid by official doc (https://devdocs.prestashop.com/1.7/development/components/grid/tutorials/work-with-bulk-actions/).

  1. Register hook in method install() in my module class
$this->registerHook('actionCustomerGridDefinitionModifier')
  1. Copy hook method for bulk actions to my module class
    /**
     * Use hook to add Bulk action for subscribing multiple customers to newsletter
     */
    public function hookActionCustomerGridDefinitionModifier(array $params)
    {
        // $params['definition'] is instance of \PrestaShop\PrestaShop\Core\Grid\Definition\GridDefinition
        $params['definition']->getBulkActions()->add(
                (new SubmitBulkAction('subscribe_newsletter'))
                    ->setName('Subscribe newsletter')
                    ->setOptions([
                        // in most cases submit action should be implemented by module
                        'submit_route' => 'admin_my_module_customers_bulk_subscribe_newsletter',
                    ]) 
            );
    }

But not working and nothing new was displayed in bulk actions.

Then I try same with product:

  1. Register hook in method install() in my module class
$this->registerHook('actionProductGridDefinitionModifier')
  1. Copy hook method for bulk actions to my module class
    /**
     * Use hook to add Bulk action for subscribing multiple customers to newsletter
     */
    public function hookActionProductGridDefinitionModifier(array $params)
    {
        // $params['definition'] is instance of \PrestaShop\PrestaShop\Core\Grid\Definition\GridDefinition
        $params['definition']->getBulkActions()->add(
                (new SubmitBulkAction('subscribe_newsletter'))
                    ->setName('Subscribe newsletter')
                    ->setOptions([
                        // in most cases submit action should be implemented by module
                        'submit_route' => 'admin_my_module_customers_bulk_subscribe_newsletter',
                    ]) 
            );
    }

But nothing happend too.

What I doing wrong? Could it be a problem that prestashop started switching with templates to twig?


Solution

  • in 8.0 we'll have a full new product list page, and it has as far as I know all the hooks you would need 😄 .

    But your focus in on 1.7.8.5 . Unfortunately on 1.7.8.x versions we only deliver bug fixes and adding a hook would be a new feature. We only deliver bug fixes in order to keep the version as stable as possible so we will not add a hook in 1.7.8.6 .

    However 8.0.0 should come in the summer so soon you should have all the hooks you need 👍

    I close this issue as

    for 8.x branch it's already OK (don't hesitate to check the new product page to see if you have all the hooks you want) for 1.7.8.x we cannot add new features

    https://github.com/PrestaShop/PrestaShop/issues/28239