Reputation: 13
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/).
$this->registerHook('actionCustomerGridDefinitionModifier')
/**
* 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:
$this->registerHook('actionProductGridDefinitionModifier')
/**
* 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?
Upvotes: 0
Views: 1484
Reputation: 9
$this->registerHook('actionProductGridDefinitionModifier')
These hooks only work when New product page setting is enabled
For old product page you can make overrides in the twig files for them.
Upvotes: 0
Reputation: 16
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
Upvotes: 0
Reputation: 441
Parameter 'submit_route'
is the route to your controller, which handles the bulk action. This means that you have to create a Symfony based controller. The example of such controller exists in standard 1.7 module ps_linklist
- the LinkBlockController (ps_linklist\src\Controller\Admin\Improve\Design\LinkBlockController.php)
.
For Prestashop to map such controllers to a specific route, you also have to create file config/routes.yml
in your module's root folder.
You have to define your route in the following format:
admin_link_block_list:
path: /link-widget/list
methods: [GET]
defaults:
_controller: 'PrestaShop\Module\LinkList\Controller\Admin\Improve\Design\LinkBlockController::listAction'
The listAction
method will be called, if route admin_link_block_list
is used.
Finally, the controller has to be autoloaded into the Prestashop.
The simplest why is to create composer.json
with the following content:
{
"autoload": {
"psr-4": {
"YourNamespace\\": "src/"
}
}
}
Hit the composer install
and it will create the autoload class-map. Then, just make sure that your controller is in the correct namespace. For example, if you have SubscribtionController
in {your_module}\src\Controller\Admin\SubscribtionController.php
then add the correct namespace in your SubscribtionController.php
:
namespace YourNamespace\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
class SubscribtionControllerextends FrameworkBundleAdminController
{
public function listAction(Request $request)
{
// do your work here
}
}
After these steps, the bulk action should appear in your desired grid.
Upvotes: 0