Skip to content

Commit

Permalink
Eoxia#29 [Hook] add: number of competitor prices on tab
Browse files Browse the repository at this point in the history
  • Loading branch information
evarisk-charles authored and nicolas-eoxia committed Aug 28, 2024
1 parent f84ba18 commit d429ddf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
29 changes: 28 additions & 1 deletion class/actions_priseo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,36 @@ public function printCommonFooter(array $parameters): int
</script>
<?php
}

}
return 0; // or return 1 to replace standard code
}

/**
* Overloading the completeTabsHead function : replacing the parent's function with the one below
*
* @param array $parameters Hook metadatas (context, etc...)
* @return int 0 < on error, 0 on success, 1 to replace standard code
*/
public function completeTabsHead(array $parameters): int
{
global $db;

require_once __DIR__ . '/competitorprice.class.php';

if (strpos($parameters['context'], 'main') !== false) {
$competitorPrice = new CompetitorPrice($db);
$competitorPrices = $competitorPrice->fetchAll('', '', 0, 0, ['customsql' => 't.status >= 0']);
if (!empty($parameters['head'])) {
foreach ($parameters['head'] as $headKey => $tabsHead) {
if (is_array($tabsHead) && !empty($tabsHead)) {
if (isset($tabsHead[2]) && $tabsHead[2] === 'priseo' && !strpos($parameters['head'][$headKey][1], 'badge')) {
$parameters['head'][$headKey][1] .= '<span class="badge marginleftonlyshort">' . (count($competitorPrices) > 0 ? count($competitorPrices) : 0) . '</span>';
}
}
}
}
$this->results = $parameters;
}
return 0; // or return 1 to replace standard code
}
}
1 change: 1 addition & 0 deletions core/modules/modPriseo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public function __construct($db)
'js' => [],
// Set here all hooks context managed by module. To find available hook context, make a "grep -r '>initHooks(' *" on source code. You can also set hook context to 'all'
'hooks' => [
'main',
'productpricecard'
],
// Set this to 1 if features of module are opened to external users
Expand Down

0 comments on commit d429ddf

Please sign in to comment.