I need to add an attribute deactivation feature into Prestashop 1.7.8.7 admin panel. In order to achieve that, I've chosen to decorate the core controller PrestaShopBundle\Controller\Admin\Sell\Catalog\AttributeController via a custom module, created by myself.
I've followed PrestaShop Documentation about controller decoration, but nothing works : after resolving the few error messages encountered, and clearing the dev cache, nothing happens. When I click on Sell > Catalog > Attributes & Features and select an attribute, the original PrestaShop page is still displayed (while I rewrote the indexAction method of the controller with a simple die() ).
Here is what I have done so far:
I've created the custom module base as shown in the documentation. Here is the code of the cl_attribute.php file:
<?php declare(strict_types=1); use PrestaShop\PrestaShop\Adapter\Module\Module; if (!defined('_PS_VERSION_')) { exit; } require_once __DIR__ . '/vendor/autoload.php'; class Cl_attribute extends Module { public function __construct() { $this->name = 'cl_attribute'; $this->tab = 'administration'; $this->version = '1.0.0'; $this->author = 'John Doe'; $this->need_instance = 1; $this->ps_versions_compliancy = [ 'min' => '1.7', 'max' => _PS_VERSION_ ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->trans('Attributs', [], 'Modules.Clattribute.Admin'); $this->description = $this->trans("Module permettant d'activer ou de désactiver des attributs", [], 'Modules.Clattribute.Admin'); $this->confirmUninstall = $this->trans('Êtes-vous sur de vouloir désinstaller ce module?', [], 'Modules.Clattribute.Admin'); } public function install() { return parent::install(); } public function uninstall() { return parent::uninstall(); } }
I've added a composer.json at the root module :
{ "name": "xxx/cl_attribute", "license": "AFL-3.0", "autoload": { "psr-4": {"Namespace\\": "src/"}, "classmap": ["cl_attribute.php"], "config": {"prepend-autoloader": false}, "type": "prestashop-module" } }
I've created a config/services.yml file :
services: Cl_attribute: class: Cl_attribute\Controller\Admin\DemoController decorates: PrestaShopBundle\Controller\Admin\Sell\Catalog\AttributeController arguments: ['@cl_attribute.inner']
I've created a src/Controller/Admin/DemoController.php file :
<?php namespace Cl_attribute\Controller\Admin; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Controller\Admin\Sell\Catalog\AttributeController; use PrestaShop\PrestaShop\Core\Search\Filters\AttributeFilters; use Symfony\Component\HttpFoundation\Request; class DemoController extends FrameworkBundleAdminController { private $decoratedController; public function __construct(AttributeController $decoratedController) { $this->decoratedController = $decoratedController; } public function indexAction(Request $request, $attributeGroupId, AttributeFilters $attributeFilters) { die('lol'); // return $this->decoratedController->indexAction($request, $attributeGroupId, $attributeFilters); } }
I also followed another tutorial along with the documentation, but I still can't decorate this controller.
What did I miss ?