Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send backend invitation through new hook #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions Trustpilot/trustpilot.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ public function updateProductList()

public function enable($force_all = false)
{
parent::enable($force_all);
$this->uninstallTabs();
$this->installTab();
return parent::enable($force_all);
}

public function install()
Expand Down Expand Up @@ -347,12 +347,12 @@ public function hookDisplayOrderConfirmation($params)
return $this->context->smarty->fetch(_PS_MODULE_DIR_.'trustpilot/views/templates/hook/confirmation.tpl');
}

// Let's delete this hook (after checking in prod) if hookActionOrderHistoryAddAfter will cover all invitations plus missing ones
public function hookPostUpdateOrderStatus($params)
// Hook on order status update
public function hookActionOrderStatusPostUpdate($params)
{
$this->sendBackendInvitation($params, 'postUpdateOrderStatus');
$this->sendBackendInvitation($params, 'actionOrderStatusPostUpdate');
}

public function hookActionOrderHistoryAddAfter($params)
{
$newOrderStatus = new OrderState((int) $params['order_history']->id_order_state, (int) $params['cart']->id_lang);
Expand Down Expand Up @@ -420,10 +420,29 @@ public function hookFilterProductSearch($params)

private function registerHooks()
{
$common_hooks = array('displayOrderConfirmation', 'displayHeader', 'postUpdateOrderStatus', 'displayBackOfficeHeader');
$hooks_v17 = array('displayBeforeBodyClosingTag', 'filterProductSearch'); // v1.7 +
$hooks = array('displayOrderConfirmation', 'displayHeader', 'displayBackOfficeHeader');
$hooks_v80 = array('actionOrderStatusPostUpdate'); // v8.0
$hooks_v17 = array('displayBeforeBodyClosingTag', 'filterProductSearch'); // v1.7
$hooks_v16 = array('displayFooter'); // v1.6 and older
$hooks = array_merge($common_hooks, version_compare(_PS_VERSION_, '1.7', '<') ? $hooks_v16 : $hooks_v17);

// PS 8.0
if (version_compare(_PS_VERSION_, '8.0', '>')) {
$hooks = array_merge($hooks, $hooks_v80);
}

// PS 1.7
if (version_compare(_PS_VERSION_, '8.0', '<') &&
version_compare(_PS_VERSION_, '1.7', '>'))
{
$hooks = array_merge($hooks, $hooks_v17);
}

// PS 1.6
if (version_compare(_PS_VERSION_, '1.7', '<'))
{
$hooks = array_merge($hooks, $hooks_v16);
}

foreach ($hooks as $hook) {
if (!Hook::getIdByName($hook)) {
Logger::addLog('Trustpilot module: ' . $hook . ' hook was not found', 2);
Expand Down