Dodanie nowych plików tłumaczeń, aktualizacja wersji modułu gm_omniprice do 1.2.0 oraz poprawki w kodzie i logach

This commit is contained in:
2025-01-30 15:50:33 +01:00
parent 3ae138b01d
commit 3753eb902b
25 changed files with 990 additions and 94 deletions

View File

@@ -13,9 +13,12 @@ if (!defined('_PS_VERSION_'))
class Gm_OmniPrice extends Module
{
protected $prefix = '';
protected $ignoredGroups = [];
protected $batchSize = 100;
protected $ignoreCountries = false;
protected $ignoreNonEuCountries = false;
protected $ignoreCombinations = false;
protected $reindexOnSave = false;
protected $showIfNotEnoughHistoricalData = false;
@@ -24,6 +27,7 @@ class Gm_OmniPrice extends Module
protected $backgroundColor = '';
protected $showRealDiscount = false;
protected $indexInactive = false;
protected $skipBelowCost = false;
protected $activeMap = null;
protected $daysBack = 30;
protected $defaultShopId;
@@ -33,13 +37,44 @@ class Gm_OmniPrice extends Module
protected $today;
protected $yesterday;
protected $groupNames = [];
protected $euCountries = [
'AT', # Austria
'BE', # Belgium
'BG', # Bulgaria
'CY', # Cyprus
'CZ', # Czech Republic
'DE', # Germany
'DK', # Denmark
'EE', # Estonia
'GR', # Greece
'ES', # Spain
'FI', # Finland
'FR', # France
//'GB' # United Kingdom // in case they return ;-)
'HR', # Croatia
'HU', # Hungary
'IE', # Ireland
'IE2', # Ireland (2)
'IT', # Italy
'LT', # Lithuania
'LU', # Luxembourg
'LV', # Latvia
'MT', # Malta
'NL', # Netherlands
'PL', # Poland
'PT', # Portugal
'RO', # Romania
'SE', # Sweden
'SI', # Slovenia
'SK', # Slovakia
];
public function __construct()
{
$this->name = 'gm_omniprice';
$this->prefix = strtoupper($this->name);
$this->tab = 'front_office_features';
$this->version = '1.2.0';
$this->version = '1.2.11';
$this->author = 'GreenMouseStudio.com';
$this->need_instance = 0;
$this->bootstrap = true;
@@ -59,6 +94,7 @@ class Gm_OmniPrice extends Module
$this->daysBack = Configuration::get($this->prefix . '_DAYS');
$this->batchSize = Configuration::get($this->prefix . '_BATCH');
$this->ignoreCountries = Configuration::get($this->prefix . '_IGNORE_COUNTRIES');
$this->ignoreNonEuCountries = Configuration::get($this->prefix . '_IGNORE_NON_EU');
$this->ignoreCombinations = Configuration::get($this->prefix . '_IGNORE_COMBINATIONS');
$this->reindexOnSave = Configuration::get($this->prefix . '_REINDEX');
$this->textColor = Configuration::get($this->prefix . '_TEXT_COLOR');
@@ -67,11 +103,12 @@ class Gm_OmniPrice extends Module
$this->showIfNotEnoughHistoricalData = Configuration::get($this->prefix . '_SHOW_IF_NO_HISTORY');
$this->showRealDiscount = Configuration::get($this->prefix . '_SHOW_REAL_DISCOUNT');
$this->indexInactive = Configuration::get($this->prefix . '_INDEX_INACTIVE');
$this->skipBelowCost = Configuration::get($this->prefix . '_SKIP_BELOW_COST');
$this->defaultShopId = Configuration::get('PS_SHOP_DEFAULT');
$this->defaultCountryId = Configuration::get('PS_COUNTRY_DEFAULT');
$this->defaultGroupId = Configuration::get('PS_CUSTOMER_GROUP');
$this->defaultCurrencyId = Configuration::get('PS_CURRENCY_DEFAULT');
$this->defaultShopId = (int) Configuration::get('PS_SHOP_DEFAULT');
$this->defaultCountryId = (int) Configuration::get('PS_COUNTRY_DEFAULT');
$this->defaultGroupId = (int) Configuration::get('PS_CUSTOMER_GROUP');
$this->defaultCurrencyId = (int) Configuration::get('PS_CURRENCY_DEFAULT');
$this->today = date('Y-m-d');
$this->yesterday = date('Y-m-d', strtotime("-1 days"));
}
@@ -91,10 +128,12 @@ class Gm_OmniPrice extends Module
Configuration::updateValue($this->prefix . '_DAYS', 30);
Configuration::updateValue($this->prefix . '_BATCH', 100);
Configuration::updateValue($this->prefix . '_IGNORE_COUNTRIES', true);
Configuration::updateValue($this->prefix . '_IGNORE_NON_EU', true);
Configuration::updateValue($this->prefix . '_REINDEX', true);
Configuration::updateValue($this->prefix . '_SHOW_IF_NO_HISTORY', false);
Configuration::updateValue($this->prefix . '_SHOW_REAL_DISCOUNT', false);
Configuration::updateValue($this->prefix . '_INDEX_INACTIVE', false);
Configuration::updateValue($this->prefix . '_SKIP_BELOW_COST', false);
Configuration::updateValue($this->prefix . '_TEXT_COLOR', '#666666');
Configuration::updateValue($this->prefix . '_PRICE_COLOR', '#666666');
Configuration::updateValue($this->prefix . '_BG_COLOR', '#FFFFFF');
@@ -136,8 +175,9 @@ class Gm_OmniPrice extends Module
`id_group` INT(10) UNSIGNED NOT NULL,
`price_tex` DECIMAL(20,6),
`price_tin` DECIMAL(20,6),
`is_specific_price` TINYINT(1),
INDEX (`date`, `id_shop`, `id_product`)
`is_specific_price` TINYINT(1),
INDEX (`date`, `id_shop`, `id_product`),
INDEX (`date`, `id_product`)
) ENGINE = ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;') &&
Db::getInstance()->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'gm_omniprice_cache` (
@@ -157,7 +197,7 @@ class Gm_OmniPrice extends Module
`date` DATE NOT NULL,
`id_shop` INT(10) UNSIGNED NOT NULL,
`id_product` INT(10) UNSIGNED NOT NULL,
INDEX (`date`, `id_shop`)
INDEX (`date`, `id_shop`)
) ENGINE = ' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;');
}
@@ -177,6 +217,7 @@ class Gm_OmniPrice extends Module
!Configuration::deleteByName($this->prefix . '_TEXT_COLOR') ||
!Configuration::deleteByName($this->prefix . '_PRICE_COLOR') ||
!Configuration::deleteByName($this->prefix . '_IGNORE_COUNTRIES') ||
!Configuration::deleteByName($this->prefix . '_IGNORE_NON_EU') ||
!Configuration::deleteByName($this->prefix . '_IGNORE_COMBINATIONS') ||
!Configuration::deleteByName($this->prefix . '_TEXT_COLOR') ||
!Configuration::deleteByName($this->prefix . '_PRICE_COLOR') ||
@@ -204,6 +245,7 @@ class Gm_OmniPrice extends Module
{
$content = '';
$content .= $this->postProcess();
$content .= $this->displayGreenMouseModulesPanel();
$content .= $this->displayForm();
$content .= $this->displayInfo();
$content .= $this->displayInformationPanel();
@@ -216,6 +258,10 @@ class Gm_OmniPrice extends Module
if (Tools::isSubmit('submit' . $this->name))
{
$this->ignoredGroups = Tools::getValue('groupBox');
if (!is_array($this->ignoredGroups))
{
$this->ignoredGroups = [];
}
$groupsString = implode(',', $this->ignoredGroups);
Configuration::updateValue($this->prefix . '_GROUPS', $groupsString);
@@ -228,6 +274,9 @@ class Gm_OmniPrice extends Module
$this->ignoreCountries = Tools::getValue($this->prefix . '_IGNORE_COUNTRIES');
Configuration::updateValue($this->prefix . '_IGNORE_COUNTRIES', $this->ignoreCountries);
$this->ignoreNonEuCountries = Tools::getValue($this->prefix . '_IGNORE_NON_EU');
Configuration::updateValue($this->prefix . '_IGNORE_NON_EU', $this->ignoreNonEuCountries);
$this->ignoreCombinations = Tools::getValue($this->prefix . '_IGNORE_COMBINATIONS');
Configuration::updateValue($this->prefix . '_IGNORE_COMBINATIONS', $this->ignoreCombinations);
@@ -252,6 +301,9 @@ class Gm_OmniPrice extends Module
$this->indexInactive = Tools::getValue($this->prefix . '_INDEX_INACTIVE');
Configuration::updateValue($this->prefix . '_INDEX_INACTIVE', $this->indexInactive);
$this->skipBelowCost = Tools::getValue($this->prefix . '_SKIP_BELOW_COST');
Configuration::updateValue($this->prefix . '_SKIP_BELOW_COST', $this->skipBelowCost);
$output .= $this->displayConfirmation($this->l('Settings updated'));
}
return $output;
@@ -288,6 +340,25 @@ class Gm_OmniPrice extends Module
'hint' => $this->l('Analyze prices only for the default country, customers from other countries will see prices of the default country'),
'desc' => $this->l('Analyze prices only for the default country, customers from other countries will see prices of the default country')
),
array(
'type' => 'switch',
'label' => $this->l('Ignore non EU countries'),
'name' => $this->prefix . '_IGNORE_NON_EU',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
'hint' => $this->l('Skip non EU countries totally, customers from non EU countries will not see any message about previous price'),
'desc' => $this->l('Skip non EU countries totally, customers from non EU countries will not see any message about previous price')
),
array(
'type' => 'switch',
'label' => $this->l('Ignore combinations'),
@@ -417,6 +488,23 @@ class Gm_OmniPrice extends Module
'desc' => $this->l('Display price change percentage after the lowest previous price')
);
}
$inputs[] = array(
'type' => 'switch',
'label' => $this->l('Skip products sold below cost price'),
'name' => $this->prefix . '_SKIP_BELOW_COST',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Yes')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('No')
)
),
);
$fieldsForm = array(
'form' => array(
'legend' => array(
@@ -435,8 +523,7 @@ class Gm_OmniPrice extends Module
$helper->table = $this->table;
$helper->default_form_language = (int) Configuration::get('PS_LANG_DEFAULT');
$helper->module = $this;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG')
: 0;
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
$helper->identifier = $this->identifier;
$helper->submit_action = 'submit' . $this->name;
$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name;
@@ -448,6 +535,7 @@ class Gm_OmniPrice extends Module
$helper->fields_value[$this->prefix . '_DAYS'] = $this->daysBack;
$helper->fields_value[$this->prefix . '_BATCH'] = $this->batchSize;
$helper->fields_value[$this->prefix . '_IGNORE_COUNTRIES'] = $this->ignoreCountries;
$helper->fields_value[$this->prefix . '_IGNORE_NON_EU'] = $this->ignoreNonEuCountries;
$helper->fields_value[$this->prefix . '_IGNORE_COMBINATIONS'] = $this->ignoreCombinations;
$helper->fields_value[$this->prefix . '_REINDEX'] = $this->reindexOnSave;
$helper->fields_value[$this->prefix . '_TEXT_COLOR'] = $this->textColor;
@@ -455,6 +543,7 @@ class Gm_OmniPrice extends Module
$helper->fields_value[$this->prefix . '_BG_COLOR'] = $this->backgroundColor;
$helper->fields_value[$this->prefix . '_SHOW_REAL_DISCOUNT'] = $this->showRealDiscount;
$helper->fields_value[$this->prefix . '_INDEX_INACTIVE'] = $this->indexInactive;
$helper->fields_value[$this->prefix . '_SKIP_BELOW_COST'] = $this->skipBelowCost;
$helper->fields_value[$this->prefix . '_SHOW_IF_NO_HISTORY'] = $this->showIfNotEnoughHistoricalData;
return $helper->generateForm(array($fieldsForm));
@@ -484,12 +573,20 @@ class Gm_OmniPrice extends Module
{
$useReduction = false;
}
if ($this->skipBelowCost)
{
$rates = $this->getConversionRates();
$costPriceMap = $this->getCostPriceMap();
}
$specificPriceOutput = null;
foreach ($shopIds as $shopId)
{
$currencyIds = $this->getCurrencyIds($shopId);
$countryIds = $this->getCountryIds($shopId);
$groupIds = $this->getGroupIds($shopId);
$lastCurrencyId = end($currencyIds);
$lastCountryId = end($countryIds);
$lastGroupId = end($groupIds);
$attributesMap = $this->getProductAttributeMap($shopId);
if (!$productId)
{
@@ -591,8 +688,39 @@ class Gm_OmniPrice extends Module
$previousPrice = 0;
$previousDiscount = false;
}
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId);
if (Tools::isSubmit('init'))
{
$onDiscount = false;
}
else
{
if (Module::isEnabled('groupinc'))
{
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId) || (is_array($specificPriceOutput) && (count($specificPriceOutput) > 1)); //groupinc module support
}
else
{
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId);
}
}
$onDiscountText = ($onDiscount ? $this->l('Yes') : $this->l('No'));
//check if product is sold below cost price
if ($this->skipBelowCost)
{
if ($this->checkIfProductIsSoldBelowCost(
$priceTex,
$costPriceMap,
$rates,
$shopId,
$productId,
$attributeId,
$currencyId
))
{
$onDiscount = false;
$onDiscountText = $this->l('Below cost');
}
}
$output .= '<tr>'
. '<td>' . ++$counter . '</td>'
. '<td>' . $productId . '</td>'
@@ -602,7 +730,7 @@ class Gm_OmniPrice extends Module
. '<td>' . $groupId . '</td>'
. '<td>' . $priceTin . ' (' . $priceTex . ') </td>'
. '<td>' . $previousPrice . '</td>'
. '<td>' . ($onDiscount ? $this->l('Yes') : $this->l('No')) . '</td>';
. '<td>' . $onDiscountText . '</td>';
$priceIsCorrect = ($priceTin > 0);
$priceChanged = (abs($previousPrice - $priceTin) > 0.01);
$discountChanged = ($previousDiscount != $onDiscount);
@@ -646,7 +774,7 @@ class Gm_OmniPrice extends Module
}
else
{
$output .= '<td>' . $this->l('Unknown') . '<</td>';
$output .= '<td>' . $this->l('Unknown') . '</td>';
}
}
else
@@ -723,7 +851,38 @@ class Gm_OmniPrice extends Module
$previousPrice = 0;
$previousDiscount = false;
}
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId);
if (Tools::isSubmit('init'))
{
$onDiscount = false;
}
else
{
if (Module::isEnabled('groupinc'))
{
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId) || (is_array($specificPriceOutput) && (count($specificPriceOutput) > 1)); //groupinc module support
}
else
{
$onDiscount = $this->checkIfProductIsDiscounted($discountedIds, $productId, $attributeId);
}
}
$onDiscountText = ($onDiscount ? $this->l('Yes') : $this->l('No'));
if ($this->skipBelowCost)
{
if ($this->checkIfProductIsSoldBelowCost(
$priceTex,
$costPriceMap,
$rates,
$shopId,
$productId,
$attributeId,
$currencyId
))
{
$onDiscount = false;
$onDiscountText = $this->l('Below cost');
}
}
$output .= '<tr>'
. '<td>' . ++$counter . '</td>'
. '<td>' . $productId . '</td>'
@@ -733,7 +892,7 @@ class Gm_OmniPrice extends Module
. '<td>' . $groupId . '</td>'
. '<td>' . $priceTin . ' (' . $priceTex . ') </td>'
. '<td>' . $previousPrice . '</td>'
. '<td>' . ($onDiscount ? $this->l('Yes') : $this->l('No')) . '</td>';
. '<td>' . $onDiscountText . '</td>';
$priceIsCorrect = ($priceTin > 0);
$priceChanged = (abs($previousPrice - $priceTin) > 0.01);
$discountChanged = ($previousDiscount != $onDiscount);
@@ -813,7 +972,10 @@ class Gm_OmniPrice extends Module
}
}
}
$this->addProductToIndex($shopId, $productId, $this->today);
if ($currencyId == $lastCurrencyId && $groupId == $lastGroupId && $countryId == $lastCountryId)
{
$this->addProductToIndex($shopId, $productId, $this->today);
}
}
}
}
@@ -848,9 +1010,9 @@ class Gm_OmniPrice extends Module
. ' AND `date` <= \'' . $date . '\''
. ' ORDER BY `date` DESC'
);
if ($attributeId != 0 && $row == false)
{
$attributeId = 0;
$row = Db::getInstance()->getRow(
'SELECT `price_tin`, `price_tex` '
. ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history` '
@@ -1058,7 +1220,18 @@ class Gm_OmniPrice extends Module
{
if (!in_array($row['id_country'], $ids))
{
$ids[] = (int) $row['id_country'];
if ($this->ignoreNonEuCountries)
{
$country = new Country($row['id_country']);
if (in_array($country->iso_code, $this->euCountries))
{
$ids[] = (int) $row['id_country'];
}
}
else
{
$ids[] = (int) $row['id_country'];
}
}
}
}
@@ -1174,12 +1347,19 @@ class Gm_OmniPrice extends Module
if (Tools::isSubmit('omnidebug'))
{
var_export($params);
echo $this->context->country->iso_code;
}
if ($this->ignoreNonEuCountries)
{
if (!in_array($this->context->country->iso_code, $this->euCountries))
{
return false;
}
}
$lowestCachedPrice = $this->getLowestCachedPrice($params);
}
$realDiscount = '';
if ($showRealDiscount && isset($hookParams['product']['price_amount']))
if ($showRealDiscount && $lowestCachedPrice && isset($hookParams['product']['price_amount']))
{
$currentPrice = $hookParams['product']['price_amount'];
$previousPrice = $lowestCachedPrice['raw'];
@@ -1201,6 +1381,7 @@ class Gm_OmniPrice extends Module
$this->context->smarty->assign(
[
'gm_omniprice_lowest' => $lowestCachedPrice['formatted'],
'gm_omniprice_lowest_raw' => $lowestCachedPrice['raw'],
'gm_omniprice_days' => $this->daysBack,
'gm_omniprice_color' => $this->textColor,
'gm_omniprice_price_color' => $this->priceColor,
@@ -1258,7 +1439,7 @@ class Gm_OmniPrice extends Module
if ($price)
{
return [
'formatted' => $this->getFormattedPrice($price),
'formatted' => $this->getFormattedPrice(round($price)),
'raw' => $price
];
}
@@ -1272,13 +1453,12 @@ class Gm_OmniPrice extends Module
. ' AND `id_currency` = ' . $params['id_currency']
. ' AND `id_country` = ' . $params['id_country']
. ' AND `id_group` = ' . $params['id_group']
. ' AND `id_product_attribute` = ' . $params['id_product_attribute']
. ' AND `id_product_attribute` = 0'
);
if ($price)
{
return [
'formatted' => $this->getFormattedPrice($price),
'formatted' => $this->getFormattedPrice(round($price)),
'raw' => $price
];
}
@@ -1306,6 +1486,9 @@ class Gm_OmniPrice extends Module
$field = '`price_tin`';
$arrayField = 'price_tin';
}
$date_history = date( 'Y-m-d', strtotime( '-30 days', time() ) );
$prices = Db::getInstance()->executeS(
'SELECT ' . $field . ', `is_specific_price`'
. ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
@@ -1314,13 +1497,14 @@ class Gm_OmniPrice extends Module
. ' AND `id_currency` = ' . $params['id_currency']
. ' AND `id_country` = ' . $params['id_country']
. ' AND `id_group` = ' . $params['id_group']
. ' AND `id_product_attribute` = ' . $params['id_product_attribute'] . ' ORDER BY price_tin ASC LIMIT 1'
. ' AND `id_product_attribute` = ' . $params['id_product_attribute']
. ' AND date >= \'' . $date_history . '\''
);
if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
{
{;
return
[
'formatted' => $this->getFormattedPrice($prices[0][$arrayField]),
'formatted' => $this->getFormattedPrice(round($prices[0][$arrayField])),
'raw' => $prices[0][$arrayField]
];
}
@@ -1334,17 +1518,23 @@ class Gm_OmniPrice extends Module
. ' AND `id_currency` = ' . $params['id_currency']
. ' AND `id_country` = ' . $params['id_country']
. ' AND `id_group` = ' . $params['id_group']
. ' AND `id_product_attribute` = ' . $params['id_product_attribute'] . ' ORDER BY price_tin ASC LIMIT 1'
. ' AND `id_product_attribute` = 0'
. ' AND date >= \'' . $date_history . '\''
);
if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
{
return
[
'formatted' => $this->getFormattedPrice($prices[0][$arrayField]),
'formatted' => $this->getFormattedPrice(round($prices[0][$arrayField])),
'raw' => $prices[0][$arrayField]
];
}
}
return
[
'formatted' => $this->getFormattedPrice(round(Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false ) ))
];
return false;
}
@@ -1373,7 +1563,7 @@ class Gm_OmniPrice extends Module
{
foreach ($result as $row)
{
$prices[$row['id_product_attribute']] = $this->getFormattedPrice($row['price']);
$prices[$row['id_product_attribute']] = $this->getFormattedPrice(round($row['price']));
}
}
else
@@ -1394,7 +1584,7 @@ class Gm_OmniPrice extends Module
{
foreach ($result as $row)
{
$prices[$row['id_product_attribute']] = $this->getFormattedPrice($row['price']);
$prices[$row['id_product_attribute']] = $this->getFormattedPrice(round($row['price']));
}
}
}
@@ -1922,49 +2112,52 @@ class Gm_OmniPrice extends Module
$currencyIds = $this->getCurrencyIds($shopId);
$countryIds = $this->getCountryIds($shopId);
$groupIds = $this->getGroupIds($shopId);
$productIds = $this->getProductIdsInHistory($shopId);
foreach ($currencyIds as $currencyId)
{
foreach ($countryIds as $countryId)
{
foreach ($groupIds as $groupId)
{
$query = 'SELECT `date`, `id_product`, `id_product_attribute` FROM `' . _DB_PREFIX_ . 'gm_omniprice_history` '
. ' WHERE `id_shop` = ' . $shopId . ' AND `id_currency` = ' . $currencyId .
' AND `id_country` = ' . $countryId . ' AND `id_group` = ' . $groupId . ' ORDER BY `date` ASC';
$res = Db::getInstance()->executeS($query);
$datesMap = [];
if ($res)
foreach ($productIds as $productId)
{
foreach ($res as $row)
$query = 'SELECT `date`, `id_product`, `id_product_attribute` FROM `' . _DB_PREFIX_ . 'gm_omniprice_history` '
. ' WHERE `id_product` = ' . $productId . ' AND `id_shop` = ' . $shopId . ' AND `id_currency` = ' . $currencyId .
' AND `id_country` = ' . $countryId . ' AND `id_group` = ' . $groupId . ' ORDER BY `date` ASC';
$res = Db::getInstance()->executeS($query);
$datesMap = [];
if ($res)
{
$day = $row['date'];
$productId = $row['id_product'];
$attributeId = $row['id_product_attribute'];
if ($day < $date)
foreach ($res as $row)
{
$datesMap[$productId][$attributeId][] = $day;
}
}
//$output .= var_export($datesMap, true);
foreach ($datesMap as $productId => $dateItem)
{
foreach ($dateItem as $attributeId => $dates)
{
$output .= "Product ID {$productId}, attribute ID: {$attributeId}<br/>";
$datesCount = count($dates);
if ($datesCount > 1)
$day = $row['date'];
$productId = $row['id_product'];
$attributeId = $row['id_product_attribute'];
if ($day < $date)
{
for ($i = 0; $i < $datesCount - 1; $i++)
{
$output .= ' ' . $dates[$i] . ' ' . $this->l('this price may be deleted') . '<br/>';
$where = '`id_shop` = ' . $shopId . ' AND `id_currency` = ' . $currencyId .
' AND `id_country` = ' . $countryId . ' AND `id_group` = ' . $groupId;
$where .= ' AND `id_product` = ' . $productId . ' AND `id_product_attribute` = ' . $attributeId;
$where .= ' AND `date` = \'' . $dates[$i] . '\'';
Db::getInstance()->delete('gm_omniprice_history', $where);
}
$datesMap[$productId][$attributeId][] = $day;
}
}
foreach ($datesMap as $productId => $dateItem)
{
foreach ($dateItem as $attributeId => $dates)
{
$output .= "Product ID {$productId}, attribute ID: {$attributeId}<br/>";
$datesCount = count($dates);
if ($datesCount > 2)
{
for ($i = 0; $i < $datesCount - 2; $i++)
{
$output .= ' ' . $dates[$i] . ' ' . $this->l('this price may be deleted') . '<br/>';
$where = '`id_shop` = ' . $shopId . ' AND `id_currency` = ' . $currencyId .
' AND `id_country` = ' . $countryId . ' AND `id_group` = ' . $groupId;
$where .= ' AND `id_product` = ' . $productId . ' AND `id_product_attribute` = ' . $attributeId;
$where .= ' AND `date` = \'' . $dates[$i] . '\'';
Db::getInstance()->delete('gm_omniprice_history', $where);
}
}
$output .= ' ' . $dates[$datesCount - 1] . ' ' . $this->l('this price is still needed') . '<br/>';
}
$output .= ' ' . $dates[$datesCount - 1] . ' ' . $this->l('this price is still needed') . '<br/>';
}
}
}
@@ -1980,6 +2173,22 @@ class Gm_OmniPrice extends Module
}
}
protected function getProductIdsInHistory($shopId)
{
$ids = [];
$query = 'SELECT DISTINCT `id_product` FROM `' . _DB_PREFIX_ . 'gm_omniprice_history` '
. ' WHERE `id_shop` = ' . $shopId;
$res = Db::getInstance()->executeS($query);
if ($res)
{
foreach ($res as $row)
{
$ids[] = (int) $row['id_product'];
}
}
return $ids;
}
public function hookDisplayAdminProductsExtra(array $params)
{
$data = [];
@@ -2182,13 +2391,97 @@ class Gm_OmniPrice extends Module
public function productIsActive($productId, $shopId)
{
$activeMap = $this->getActiveMap();
if ($productId && isset($activeMap[$shopId]) && isset($activeMap[$shopId][$productId]))
if (isset($activeMap[$shopId][$productId]))
{
return ($activeMap[$shopId][$productId] == 1);
}
else
return false;
}
public function getCostPriceMap()
{
$map = [];
$query = 'SELECT `id_product`, `id_shop`, `wholesale_price` FROM `' . _DB_PREFIX_ . 'product_shop` WHERE `wholesale_price` > 0';
$res = Db::getInstance()->executeS($query);
if ($res)
{
return false;
foreach ($res as $row)
{
$shopId = (int) $row['id_shop'];
$productId = (int) $row['id_product'];
$costPrice = $row['wholesale_price'];
$map[$shopId][$productId][0] = $costPrice;
}
}
$query = 'SELECT `id_product`, `id_product_attribute`, `id_shop`, `wholesale_price` FROM `' . _DB_PREFIX_ . 'product_attribute_shop` WHERE `wholesale_price` > 0';
$res = Db::getInstance()->executeS($query);
if ($res)
{
foreach ($res as $row)
{
$shopId = (int) $row['id_shop'];
$productId = (int) $row['id_product'];
$attributeId = (int) $row['id_product_attribute'];
$costPrice = $row['wholesale_price'];
$map[$shopId][$productId][$attributeId] = $costPrice;
}
}
return $map;
}
public function getConversionRates()
{
$rates = [];
$currencies = Db::getInstance()->executeS('
SELECT `id_shop`, `id_currency`, `conversion_rate`
FROM `' . _DB_PREFIX_ . 'currency_shop`');
if ($currencies)
{
foreach ($currencies as $currency)
{
$shopId = (int) $currency['id_shop'];
$currencyId = (int) $currency['id_currency'];
$rate = $currency['conversion_rate'];
$rates[$currencyId][$shopId] = $rate;
}
}
return $rates;
}
public function checkIfProductIsSoldBelowCost($priceTex, $costPriceMap, $rates, $shopId, $productId, $attributeId, $currencyId)
{
$conversionRate = $rates[$currencyId][$shopId];
$costPrice = $costPriceMap[$shopId][$productId][$attributeId];
$convertedCostPrice = $costPrice / $conversionRate;
return ($priceTex < $convertedCostPrice);
}
protected function displayGreenMouseModulesPanel()
{
$url = 'https://codecanyon.net/user/greenmousestudio/portfolio';
$isoCode = Context::getContext()->language->iso_code;
$translations = [
'en' => "Check out more <a href=\"$url\" target=\"_blank\">PrestaShop modules from GreenMouseStudio</a>",
'fr' => "Découvrez plus de <a href=\"$url\" target=\"_blank\">modules PrestaShop de GreenMouseStudio</a>",
'es' => "Descubra más <a href=\"$url\" target=\"_blank\">módulos de PrestaShop de GreenMouseStudio</a>",
'de' => "Entdecken Sie mehr <a href=\"$url\" target=\"_blank\">PrestaShop-Module von GreenMouseStudio</a>",
'it' => "Scopri di più <a href=\"$url\" target=\"_blank\">moduli PrestaShop di GreenMouseStudio</a>",
'pl' => "Zobacz więcej <a href=\"$url\" target=\"_blank\">modułów PrestaShop od GreenMouseStudio</a>",
'pt' => "Confira mais <a href=\"$url\" target=\"_blank\">módulos PrestaShop do GreenMouseStudio</a>",
'nl' => "Bekijk meer <a href=\"$url\" target=\"_blank\">PrestaShop-modules van GreenMouseStudio</a>",
'sv' => "Upptäck fler <a href=\"$url\" target=\"_blank\">PrestaShop-moduler från GreenMouseStudio</a>",
'da' => "Se flere <a href=\"$url\" target=\"_blank\">PrestaShop-moduler fra GreenMouseStudio</a>",
'fi' => "Tutustu lisää <a href=\"$url\" target=\"_blank\">GreenMouseStudion PrestaShop-moduuleihin</a>",
'cs' => "Podívejte se na další <a href=\"$url\" target=\"_blank\">moduly PrestaShop od GreenMouseStudio</a>",
'sk' => "Pozrite si viac <a href=\"$url\" target=\"_blank\">modulov PrestaShop od GreenMouseStudio</a>",
'hu' => "Nézzen meg több <a href=\"$url\" target=\"_blank\">PrestaShop modult a GreenMouseStudio-tól</a>",
'ro' => "Descoperiți mai multe <a href=\"$url\" target=\"_blank\">module PrestaShop de la GreenMouseStudio</a>",
'el' => "Δείτε περισσότερες <a href=\"$url\" target=\"_blank\">μονάδες PrestaShop από το GreenMouseStudio</a>",
];
$message = isset($translations[$isoCode]) ? $translations[$isoCode] : $translations['en'];
$content = '';
$content .= '<p class="alert alert-warning">' . $message . '</p>';
return $content;
}
}