feat: Enhance price comparison logic and improve code formatting
This commit is contained in:
@@ -1376,7 +1376,10 @@ class Gm_OmniPrice extends Module
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($lowestCachedPrice)
|
|
||||||
|
$checkIfProductIsDiscounted = self::checkIfProductIsDiscounted($this->getDiscountedProductIds($params['id_shop'], $params['id_currency'], $params['id_country'], $params['id_group']), $productId, $params['id_product_attribute']);
|
||||||
|
|
||||||
|
if ( $lowestCachedPrice and $checkIfProductIsDiscounted )
|
||||||
{
|
{
|
||||||
$this->context->smarty->assign(
|
$this->context->smarty->assign(
|
||||||
[
|
[
|
||||||
@@ -1478,8 +1481,8 @@ class Gm_OmniPrice extends Module
|
|||||||
|
|
||||||
protected function getLatestHistoricalPrice($params)
|
protected function getLatestHistoricalPrice($params)
|
||||||
{
|
{
|
||||||
$price_1 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false );
|
$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 );
|
$price_2 = Product::getPriceStatic($params['id_product'], true, $params['id_product_attribute'], 2, null, false, true);
|
||||||
|
|
||||||
$displayMethod = Group::getPriceDisplayMethod($params['id_group']);
|
$displayMethod = Group::getPriceDisplayMethod($params['id_group']);
|
||||||
if ($displayMethod)
|
if ($displayMethod)
|
||||||
@@ -1493,7 +1496,7 @@ class Gm_OmniPrice extends Module
|
|||||||
$arrayField = 'price_tin';
|
$arrayField = 'price_tin';
|
||||||
}
|
}
|
||||||
|
|
||||||
$date_history = date( 'Y-m-d', strtotime( '-30 days', time() ) );
|
$date_history = date('Y-m-d', strtotime('-30 days', time()));
|
||||||
|
|
||||||
$prices = Db::getInstance()->executeS(
|
$prices = Db::getInstance()->executeS(
|
||||||
'SELECT ' . $field . ', `is_specific_price`'
|
'SELECT ' . $field . ', `is_specific_price`'
|
||||||
@@ -1509,39 +1512,39 @@ class Gm_OmniPrice extends Module
|
|||||||
|
|
||||||
$price_find = null;
|
$price_find = null;
|
||||||
|
|
||||||
if ( is_array( $prices ) and count( $prices ) )
|
if (is_array($prices) and count($prices))
|
||||||
{
|
{
|
||||||
foreach ( $prices as $price_tmp )
|
foreach ($prices as $price_tmp)
|
||||||
{
|
{
|
||||||
if ( $price_tmp['is_specific_price'] )
|
if ($price_tmp['is_specific_price'])
|
||||||
{
|
{
|
||||||
if ( round( $price_2 ) != round( $price_tmp['price_tin'] ) )
|
if (round($price_2) != round($price_tmp['price_tin']))
|
||||||
{
|
{
|
||||||
if ( $price_find == null or $price_find > round( $price_tmp['price_tin'] ) )
|
if ($price_find == null or $price_find > round($price_tmp['price_tin']))
|
||||||
$price_find = round( $price_tmp['price_tin'] );
|
$price_find = round($price_tmp['price_tin']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $price_find )
|
if ($price_find)
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'formatted' => $this->getFormattedPrice( $price_find ),
|
'formatted' => $this->getFormattedPrice($price_find),
|
||||||
'raw' => $price_find
|
'raw' => $price_find
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// echo 'SELECT ' . $field . ', `is_specific_price`'
|
// echo 'SELECT ' . $field . ', `is_specific_price`'
|
||||||
// . ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
|
// . ' FROM `' . _DB_PREFIX_ . 'gm_omniprice_history`'
|
||||||
// . ' WHERE `id_shop` = ' . $params['id_shop']
|
// . ' WHERE `id_shop` = ' . $params['id_shop']
|
||||||
// . ' AND `id_product` = ' . $params['id_product']
|
// . ' AND `id_product` = ' . $params['id_product']
|
||||||
// . ' AND `id_currency` = ' . $params['id_currency']
|
// . ' AND `id_currency` = ' . $params['id_currency']
|
||||||
// . ' AND `id_country` = ' . $params['id_country']
|
// . ' AND `id_country` = ' . $params['id_country']
|
||||||
// . ' AND `id_group` = ' . $params['id_group']
|
// . ' AND `id_group` = ' . $params['id_group']
|
||||||
// . ' AND `id_product_attribute` = ' . $params['id_product_attribute']
|
// . ' AND `id_product_attribute` = ' . $params['id_product_attribute']
|
||||||
// . ' AND date >= \'' . $date_history . '\'';
|
// . ' AND date >= \'' . $date_history . '\'';
|
||||||
// echo '<pre>'; print_r($prices); echo '</pre>';
|
// echo '<pre>'; print_r($prices); echo '</pre>';
|
||||||
// if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
|
// if ((count($prices) == 1) && ($prices[0]['is_specific_price']))
|
||||||
// {
|
// {
|
||||||
// return
|
// return
|
||||||
@@ -1574,13 +1577,13 @@ class Gm_OmniPrice extends Module
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
$price_1 = Product::getPriceStatic( $params['id_product'], true, $params['id_product_attribute'], 2, null, false, false );
|
$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 );
|
$price_2 = Product::getPriceStatic($params['id_product'], true, $params['id_product_attribute'], 2, null, false, true);
|
||||||
if ( $price_1 != $price_2 )
|
if ($price_1 != $price_2)
|
||||||
return
|
return
|
||||||
[
|
[
|
||||||
'formatted' => $this->getFormattedPrice( round( $price_1 ) )
|
'formatted' => $this->getFormattedPrice(round($price_1))
|
||||||
];
|
];
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user