Skip to content

Commit

Permalink
fix: missing hooks (employees and translations) (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
fox-john authored Mar 26, 2024
1 parent 6401991 commit 9a85fd3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
82 changes: 82 additions & 0 deletions ps_eventbus.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

use PrestaShop\Module\PsEventbus\Config\Config;
use PrestaShopBundle\EventListener\ActionDispatcherLegacyHooksSubscriber;

if (!defined('_PS_VERSION_')) {
exit;
Expand Down Expand Up @@ -124,6 +125,12 @@ class Ps_eventbus extends Module
'actionObjectZoneDeleteAfter',
'actionObjectZoneUpdateAfter',
'actionShippingPreferencesPageSave',

'actionObjectEmployeeAddAfter',
'actionObjectEmployeeDeleteAfter',
'actionObjectEmployeeUpdateAfter',

'actionDispatcherBefore',
];

/**
Expand Down Expand Up @@ -1348,6 +1355,81 @@ public function hookActionShippingPreferencesPageSave()
);
}

/**
* @return void
*/
public function hookActionObjectEmployeeAddAfter()
{
$this->insertIncrementalSyncObject(
0,
Config::COLLECTION_EMPLOYEES,
date(DATE_ATOM),
$this->shopId
);
}

/**
* @return void
*/
public function hookActionObjectEmployeeDeleteAfter()
{
$this->insertIncrementalSyncObject(
0,
Config::COLLECTION_EMPLOYEES,
date(DATE_ATOM),
$this->shopId
);
}

/**
* @return void
*/
public function hookActionObjectEmployeeUpdateAfter()
{
$this->insertIncrementalSyncObject(
0,
Config::COLLECTION_EMPLOYEES,
date(DATE_ATOM),
$this->shopId
);
}

/**
* This is global hook. This hook is called at the beginning of the dispatch method of the Dispatcher
* It's possible to use this hook all time when we don't have specific hook.
* Available since: 1.7.1
*
* Unable to use hookActionDispatcherAfter. Seem to be have a strange effect. When i use
* this hook and try to dump() the content, no dump appears in the symfony debugger, and no more hooks appear.
* For security reasons, I like to use the before hook, and put it in a try/catch
*
* @param array $parameters
*
* @return void
*/
public function hookActionDispatcherBefore($parameters)
{
try {
if ($parameters['controller_type'] != ActionDispatcherLegacyHooksSubscriber::BACK_OFFICE_CONTROLLER) {
return;
}

$route = $parameters['route'];

// when translation is edited or reset, add to incremental sync
if ($route == 'api_translation_value_edit' || $route == 'api_translation_value_reset') {
$this->insertIncrementalSyncObject(
0,
Config::COLLECTION_TRANSLATIONS,
date(DATE_ATOM),
$this->shopId
);
}
} catch (\Exception $e) {
return;
}
}

/**
* @param array $parameters
*
Expand Down
13 changes: 13 additions & 0 deletions upgrade/Upgrade-3.0.5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* @return bool
*/
function upgrade_module_3_0_5($module)
{
$module->registerhook('actionObjectEmployeeAddAfter');
$module->registerhook('actionObjectEmployeeDeleteAfter');
$module->registerhook('actionObjectEmployeeUpdateAfter');

return true;
}

0 comments on commit 9a85fd3

Please sign in to comment.