feat: update diagnostic scripts and configuration for improved product data handling
This commit is contained in:
@@ -48,6 +48,7 @@ class OmnibusEuFree extends Module
|
||||
Configuration::updateValue('OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK', 1);
|
||||
Configuration::updateValue('OMNIBUSEUFREE_CRON_STATUS', 2);
|
||||
Configuration::updateValue('OMNIBUSEUFREE_DAYS', 30);
|
||||
Configuration::updateValue('OMNIBUSEUFREE_HISTORY_DAYS', 60);
|
||||
|
||||
include(dirname(__FILE__) . '/sql/install.php');
|
||||
|
||||
@@ -68,6 +69,7 @@ class OmnibusEuFree extends Module
|
||||
Configuration::deleteByName('OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK');
|
||||
Configuration::deleteByName('OMNIBUSEUFREE_CRON_STATUS');
|
||||
Configuration::deleteByName('OMNIBUSEUFREE_DAYS');
|
||||
Configuration::deleteByName('OMNIBUSEUFREE_HISTORY_DAYS');
|
||||
|
||||
include(dirname(__FILE__) . '/sql/uninstall.php');
|
||||
|
||||
@@ -287,6 +289,9 @@ class OmnibusEuFree extends Module
|
||||
public function hookDisplayAdminProductsExtra($params)
|
||||
{
|
||||
$OmnibusData = array();
|
||||
$product = new Product((int) $params['id_product']);
|
||||
$hasCombinations = $product->hasCombinations();
|
||||
$nameCache = array();
|
||||
|
||||
foreach ($this->getOmnibusData($params['id_product']) as $rowId => $rowValue) {
|
||||
$OmnibusData[$rowId]['price_locale'] = '';
|
||||
@@ -301,9 +306,14 @@ class OmnibusEuFree extends Module
|
||||
$OmnibusData[$rowId]['currency_iso_code'] = $currency->iso_code;
|
||||
}
|
||||
elseif ($key == 'id_product_attribute') {
|
||||
$product = new Product($params['id_product']);
|
||||
$OmnibusData[$rowId]['name'] = $product->getProductName($params['id_product'], $value);
|
||||
($product->hasCombinations() && $value == 0) ? $OmnibusData[$rowId]['name'] .= ' ' . $this->l('(default combination)') : '';
|
||||
$attrId = (int) $value;
|
||||
if (!isset($nameCache[$attrId])) {
|
||||
$nameCache[$attrId] = $product->getProductName((int) $params['id_product'], $attrId);
|
||||
if ($hasCombinations && $attrId === 0) {
|
||||
$nameCache[$attrId] .= ' ' . $this->l('(default combination)');
|
||||
}
|
||||
}
|
||||
$OmnibusData[$rowId]['name'] = $nameCache[$attrId];
|
||||
}
|
||||
elseif ($key == 'is_last' && $value == 1) {
|
||||
$OmnibusData[$rowId]['is_last_icon'] = '<span class="material-icons text-success">done</span>';
|
||||
@@ -334,10 +344,18 @@ class OmnibusEuFree extends Module
|
||||
public function hookActionProductSave($hook_params)
|
||||
{
|
||||
if (Module::isEnabled('omnibuseufree')) {
|
||||
Product::flushPriceCache();
|
||||
$id_product = (int) $hook_params['id_product'];
|
||||
|
||||
$this->addProductPriceWithCombinations($hook_params['id_product']);
|
||||
$this->addProductPrice($hook_params['id_product']);
|
||||
$combinationCount = (int) Db::getInstance()->getValue(
|
||||
'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . $id_product
|
||||
);
|
||||
|
||||
Product::flushPriceCache();
|
||||
$this->addProductPrice($id_product);
|
||||
|
||||
if ($combinationCount <= 30) {
|
||||
$this->addProductPriceWithCombinations($id_product);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,10 +363,21 @@ class OmnibusEuFree extends Module
|
||||
{
|
||||
if (Module::isEnabled('omnibuseufree')) {
|
||||
$id_product = (int) Tools::getValue('id_product');
|
||||
Product::flushPriceCache();
|
||||
|
||||
$this->addProductPriceWithCombinations($id_product);
|
||||
$combinationCount = (int) Db::getInstance()->getValue(
|
||||
'SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'product_attribute` WHERE `id_product` = ' . $id_product
|
||||
);
|
||||
|
||||
// Skip entirely for products with many combinations.
|
||||
// hookActionProductSave already handles base price recording.
|
||||
// This hook fires once PER combination (168x), so running here is wasteful.
|
||||
if ($combinationCount > 30) {
|
||||
return;
|
||||
}
|
||||
|
||||
Product::flushPriceCache();
|
||||
$this->addProductPrice($id_product);
|
||||
$this->addProductPriceWithCombinations($id_product);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -473,11 +502,21 @@ class OmnibusEuFree extends Module
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Number of days'),
|
||||
'desc' => $this->l('Number of days for front-end lowest price display (Omnibus Directive).'),
|
||||
'name' => 'OMNIBUSEUFREE_DAYS',
|
||||
'class' => 'omnibus-input-days',
|
||||
'maxlength' => '3',
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('History retention (days)'),
|
||||
'desc' => $this->l('How many days of price history to keep and display in admin. Older entries (except current price) will be deleted by CRON.'),
|
||||
'name' => 'OMNIBUSEUFREE_HISTORY_DAYS',
|
||||
'class' => 'omnibus-input-days',
|
||||
'maxlength' => '4',
|
||||
'required' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Display on product page'),
|
||||
@@ -539,7 +578,8 @@ class OmnibusEuFree extends Module
|
||||
'OMNIBUSEUFREE_INFORMATION_VERSION' => Configuration::get('OMNIBUSEUFREE_INFORMATION_VERSION', null, null, null, 2),
|
||||
'OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK' => Configuration::get('OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK', null, null, null, 1),
|
||||
'OMNIBUSEUFREE_CRON_STATUS' => Configuration::get('OMNIBUSEUFREE_CRON_STATUS', null, null, null, 2),
|
||||
'OMNIBUSEUFREE_DAYS' => Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30)
|
||||
'OMNIBUSEUFREE_DAYS' => Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30),
|
||||
'OMNIBUSEUFREE_HISTORY_DAYS' => Configuration::get('OMNIBUSEUFREE_HISTORY_DAYS', null, null, null, 60)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -556,6 +596,7 @@ class OmnibusEuFree extends Module
|
||||
Configuration::updateValue('OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK', (int) Tools::getValue('OMNIBUSEUFREE_DISPLAY_PRODUCT_PRICE_BLOCK'));
|
||||
Configuration::updateValue('OMNIBUSEUFREE_CRON_STATUS', (int) Tools::getValue('OMNIBUSEUFREE_CRON_STATUS'));
|
||||
Configuration::updateValue('OMNIBUSEUFREE_DAYS', (int) Tools::getValue('OMNIBUSEUFREE_DAYS'));
|
||||
Configuration::updateValue('OMNIBUSEUFREE_HISTORY_DAYS', max(1, (int) Tools::getValue('OMNIBUSEUFREE_HISTORY_DAYS')));
|
||||
|
||||
$confirmation = $this->l('The settings have been updated.');
|
||||
|
||||
@@ -886,10 +927,13 @@ class OmnibusEuFree extends Module
|
||||
throw new Exception('Missing parameter: $id_product');
|
||||
}
|
||||
|
||||
$historyDays = (int) Configuration::get('OMNIBUSEUFREE_HISTORY_DAYS', null, null, null, 60);
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('*');
|
||||
$sql->from('omnibus_eu_free');
|
||||
$sql->where('id_product = ' . (int) $id_product);
|
||||
$sql->where('(`is_last` = 1 OR `date_add` >= DATE_SUB(NOW(), INTERVAL ' . $historyDays . ' DAY))');
|
||||
$sql->orderBy('is_default_currency DESC');
|
||||
$sql->orderBy('id_currency ASC');
|
||||
$sql->orderBy('id_product_attribute ASC');
|
||||
@@ -923,30 +967,14 @@ class OmnibusEuFree extends Module
|
||||
|
||||
public function removeOldDataFromOmnibusTable()
|
||||
{
|
||||
$NumberOfDays = (int) Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30);
|
||||
$NumberOfDays = 90;
|
||||
$numberOfDays = (int) Configuration::get('OMNIBUSEUFREE_HISTORY_DAYS', null, null, null, 60);
|
||||
|
||||
$date = new DateTime();
|
||||
$date->modify('-' . $NumberOfDays . ' days');
|
||||
$CutOffDate = $date->format('U');
|
||||
$counter = 0;
|
||||
Db::getInstance()->execute(
|
||||
'DELETE FROM `' . _DB_PREFIX_ . 'omnibus_eu_free`
|
||||
WHERE `is_last` = 0
|
||||
AND `date_add` < DATE_SUB(NOW(), INTERVAL ' . $numberOfDays . ' DAY)'
|
||||
);
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('id_omnibuseufree, date_add');
|
||||
$sql->from('omnibus_eu_free');
|
||||
$sql->where('is_last = 0');
|
||||
$result = Db::getInstance()->executeS($sql);
|
||||
|
||||
foreach ($result as $row) {
|
||||
$date = new DateTime($row['date_add']);
|
||||
$DatabaseDate = $date->format('U');
|
||||
|
||||
if ($DatabaseDate < $CutOffDate) {
|
||||
Db::getInstance()->delete('omnibus_eu_free', '`id_omnibuseufree` = ' . (int) $row['id_omnibuseufree']);
|
||||
$counter++;
|
||||
}
|
||||
}
|
||||
|
||||
return $counter;
|
||||
return (int) Db::getInstance()->Affected_Rows();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user