Refactor price retrieval logic in gm_omniprice module for improved clarity and performance
This commit is contained in:
@@ -1436,6 +1436,7 @@ class Gm_OmniPrice extends Module
|
||||
. ' AND `id_group` = ' . $params['id_group']
|
||||
. ' AND `id_product_attribute` = ' . $params['id_product_attribute']
|
||||
);
|
||||
|
||||
if ($price)
|
||||
{
|
||||
return [
|
||||
@@ -1443,26 +1444,28 @@ class Gm_OmniPrice extends Module
|
||||
'raw' => $price
|
||||
];
|
||||
}
|
||||
else if ($params['id_product_attribute'] != 0)
|
||||
{
|
||||
$price = Db::getInstance()->getValue(
|
||||
'SELECT ' . $field
|
||||
. ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_cache`'
|
||||
. ' WHERE `id_shop` = ' . $params['id_shop']
|
||||
. ' AND `id_product` = ' . $params['id_product']
|
||||
. ' AND `id_currency` = ' . $params['id_currency']
|
||||
. ' AND `id_country` = ' . $params['id_country']
|
||||
. ' AND `id_group` = ' . $params['id_group']
|
||||
. ' AND `id_product_attribute` = 0'
|
||||
);
|
||||
if ($price)
|
||||
{
|
||||
return [
|
||||
'formatted' => $this->getFormattedPrice(round($price)),
|
||||
'raw' => $price
|
||||
];
|
||||
}
|
||||
}
|
||||
// else if ($params['id_product_attribute'] != 0)
|
||||
// {
|
||||
// $price = Db::getInstance()->getValue(
|
||||
// 'SELECT ' . $field
|
||||
// . ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_cache`'
|
||||
// . ' WHERE `id_shop` = ' . $params['id_shop']
|
||||
// . ' AND `id_product` = ' . $params['id_product']
|
||||
// . ' AND `id_currency` = ' . $params['id_currency']
|
||||
// . ' AND `id_country` = ' . $params['id_country']
|
||||
// . ' AND `id_group` = ' . $params['id_group']
|
||||
// . ' AND `id_product_attribute` = 0'
|
||||
// );
|
||||
|
||||
// if ($price)
|
||||
// {
|
||||
// return [
|
||||
// 'formatted' => $this->getFormattedPrice(round($price)),
|
||||
// 'raw' => $price
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
if (!$price)
|
||||
{
|
||||
if ($this->showIfNotEnoughHistoricalData)
|
||||
@@ -1475,6 +1478,9 @@ class Gm_OmniPrice extends Module
|
||||
|
||||
protected function getLatestHistoricalPrice($params)
|
||||
{
|
||||
$price_1 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false );
|
||||
$price_2 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, true );
|
||||
|
||||
$displayMethod = Group::getPriceDisplayMethod($params['id_group']);
|
||||
if ($displayMethod)
|
||||
{
|
||||
@@ -1500,41 +1506,81 @@ class Gm_OmniPrice extends Module
|
||||
. ' 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(round($prices[0][$arrayField])),
|
||||
'raw' => $prices[0][$arrayField]
|
||||
];
|
||||
}
|
||||
else if ($params['id_product_attribute'] != 0)
|
||||
{
|
||||
$prices = Db::getInstance()->executeS(
|
||||
'SELECT ' . $field . ', `is_specific_price`'
|
||||
. ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
|
||||
. ' WHERE `id_shop` = ' . $params['id_shop']
|
||||
. ' AND `id_product` = ' . $params['id_product']
|
||||
. ' AND `id_currency` = ' . $params['id_currency']
|
||||
. ' AND `id_country` = ' . $params['id_country']
|
||||
. ' AND `id_group` = ' . $params['id_group']
|
||||
. ' AND `id_product_attribute` = 0'
|
||||
. ' AND date >= \'' . $date_history . '\''
|
||||
);
|
||||
|
||||
if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
|
||||
$price_find = null;
|
||||
|
||||
if ( is_array( $prices ) and count( $prices ) )
|
||||
{
|
||||
foreach ( $prices as $price_tmp )
|
||||
{
|
||||
return
|
||||
[
|
||||
'formatted' => $this->getFormattedPrice(round($prices[0][$arrayField])),
|
||||
'raw' => $prices[0][$arrayField]
|
||||
];
|
||||
if ( $price_tmp['is_specific_price'] )
|
||||
{
|
||||
if ( round( $price_2 ) != round( $price_tmp['price_tin'] ) )
|
||||
{
|
||||
if ( $price_find == null or $price_find > round( $price_tmp['price_tin'] ) )
|
||||
$price_find = round( $price_tmp['price_tin'] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
[
|
||||
'formatted' => $this->getFormattedPrice(round(Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false ) ))
|
||||
];
|
||||
|
||||
if ( $price_find )
|
||||
{
|
||||
return [
|
||||
'formatted' => $this->getFormattedPrice( $price_find ),
|
||||
'raw' => $price_find
|
||||
];
|
||||
}
|
||||
|
||||
// echo 'SELECT ' . $field . ', `is_specific_price`'
|
||||
// . ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
|
||||
// . ' WHERE `id_shop` = ' . $params['id_shop']
|
||||
// . ' AND `id_product` = ' . $params['id_product']
|
||||
// . ' 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 date >= \'' . $date_history . '\'';
|
||||
// echo '<pre>'; print_r($prices); echo '</pre>';
|
||||
// if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
|
||||
// {
|
||||
// return
|
||||
// [
|
||||
// 'formatted' => $this->getFormattedPrice(round($prices[0][$arrayField])),
|
||||
// 'raw' => $prices[0][$arrayField]
|
||||
// ];
|
||||
// }
|
||||
// else if ($params['id_product_attribute'] != 0)
|
||||
// {
|
||||
// $prices = Db::getInstance()->executeS(
|
||||
// 'SELECT ' . $field . ', `is_specific_price`'
|
||||
// . ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
|
||||
// . ' WHERE `id_shop` = ' . $params['id_shop']
|
||||
// . ' AND `id_product` = ' . $params['id_product']
|
||||
// . ' AND `id_currency` = ' . $params['id_currency']
|
||||
// . ' AND `id_country` = ' . $params['id_country']
|
||||
// . ' AND `id_group` = ' . $params['id_group']
|
||||
// . ' AND `id_product_attribute` = 0'
|
||||
// . ' AND date >= \'' . $date_history . '\''
|
||||
// );
|
||||
|
||||
// if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
|
||||
// {
|
||||
// return
|
||||
// [
|
||||
// 'formatted' => $this->getFormattedPrice(round($prices[0][$arrayField])),
|
||||
// 'raw' => $prices[0][$arrayField]
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
$price_1 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false );
|
||||
$price_2 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, true );
|
||||
if ( $price_1 != $price_2 )
|
||||
return
|
||||
[
|
||||
'formatted' => $this->getFormattedPrice( round( $price_1 ) )
|
||||
];
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user