Skip to content

Commit

Permalink
#29 [Hook] add: improve number of competitor prices on tab
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Aug 29, 2024
1 parent 84dbbe8 commit 817b204
Showing 1 changed file with 31 additions and 29 deletions.
60 changes: 31 additions & 29 deletions class/actions_priseo.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function __construct($db)
public function printCommonFooter(array $parameters): int
{
global $object;

if (strpos($parameters['context'], 'productpricecard') !== false) {
require_once __DIR__ . './competitorprice.class.php';

Expand Down Expand Up @@ -108,32 +108,34 @@ public function printCommonFooter(array $parameters): int
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
}
/**
* 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 $langs;

if (strpos($parameters['context'], 'main') !== false) {
if (!empty($parameters['head'])) {
foreach ($parameters['head'] as $headKey => $tabsHead) {
if (is_array($tabsHead) && !empty($tabsHead)) {
if (isset($tabsHead[2]) && $tabsHead[2] === 'priseo' && strpos($tabsHead[1], $langs->transnoentities('CompetitorPrice')) && !strpos($parameters['head'][$headKey][1], 'badge')) {
require_once __DIR__ . '/competitorprice.class.php';

$competitorPrice = new CompetitorPrice($this->db);
$competitorPrices = $competitorPrice->getCountOfItemsLinkedByObjectID($parameters['object']->id, 'status >= 0 AND fk_product', $competitorPrice->table_element);
$parameters['head'][$headKey][1] .= '<span class="badge marginleftonlyshort">' . (max($competitorPrices, 0)) . '</span>';
}
}
}
}

$this->results = $parameters;
}

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

0 comments on commit 817b204

Please sign in to comment.