update
This commit is contained in:
4
.vscode/ftp-kr.sync.cache.json
vendored
4
.vscode/ftp-kr.sync.cache.json
vendored
@@ -386,9 +386,9 @@
|
||||
},
|
||||
".htaccess": {
|
||||
"type": "-",
|
||||
"size": 18985,
|
||||
"size": 19570,
|
||||
"lmtime": 1772451998229,
|
||||
"modified": false
|
||||
"modified": true
|
||||
},
|
||||
".htaccess.2025-01-27-1738009656": {
|
||||
"type": "-",
|
||||
|
||||
12
changelog/2026-03-16.md
Normal file
12
changelog/2026-03-16.md
Normal file
@@ -0,0 +1,12 @@
|
||||
# 2026-03-16
|
||||
|
||||
## Co zrobiono
|
||||
- Naprawiono wyświetlanie ceny w fallbacku modułu `omnibuseufree` i dopasowano zaokrąglanie do sposobu prezentacji cen na froncie.
|
||||
- Dodano tryb debug uruchamiany parametrem `omnibuseufree_debug=1`, aby podejrzeć wartości wejściowe i wyliczone (`price`, `price_amount`, `regular_price`, fallback, minimalna).
|
||||
- Uporządkowano logikę braku historii: gdy brak historii do wyświetlenia, moduł pokazuje cenę regularną (bez promocji).
|
||||
- Dodano warunek dla promocji: jeśli w historii z okresu nie ma ceny różnej od bieżącej ceny promocyjnej, moduł traktuje to jako brak historii „sprzed obniżki” i wymusza fallback na cenę regularną.
|
||||
- Zweryfikowano na przypadkach testowych poprawne wyjście (w tym przypadki z wcześniejszym błędem 4 067,52 / 4 068,00 oraz z historią zawierającą tylko aktualną cenę promocyjną).
|
||||
|
||||
## Zmienione pliki
|
||||
- `modules/omnibuseufree/omnibuseufree.php`
|
||||
- `modules/omnibuseufree/views/templates/hook/presta_studio_omnibus_price.tpl`
|
||||
@@ -111,7 +111,7 @@ class OmnibusEuFree extends Module
|
||||
return $tab->delete();
|
||||
}
|
||||
|
||||
protected function getLastMinimalPrice($id_product = null, $id_product_attribute = 0, $currency = null, $hasDiscountNow = null)
|
||||
protected function getLastMinimalPrice($id_product = null, $id_product_attribute = 0, $currency = null)
|
||||
{
|
||||
if (!isset($id_product)) {
|
||||
throw new Exception('Missing parameter: $id_product');
|
||||
@@ -119,152 +119,124 @@ class OmnibusEuFree extends Module
|
||||
|
||||
if (!isset($currency)) {
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
$currency = (int)$defaultCurrency->id;
|
||||
$currency = $defaultCurrency->id;
|
||||
}
|
||||
|
||||
$info_version = (int) Configuration::get('OMNIBUSEUFREE_INFORMATION_VERSION', null, null, null, 2);
|
||||
$info_version = Configuration::get('OMNIBUSEUFREE_INFORMATION_VERSION', null, null, null, 2);
|
||||
$NumberOfDays = (int) Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30);
|
||||
|
||||
// Jeżeli v2 ma sens tylko przy rabacie - jeśli nie ma rabatu, nie pokazuj
|
||||
if ($info_version === 2) {
|
||||
if ($hasDiscountNow === null) {
|
||||
// pewne sprawdzenie: porównaj regular vs sale w tej walucie
|
||||
$snap = $this->getPricesSnapshot((int)$id_product, (int)$id_product_attribute, (int)$currency);
|
||||
$hasDiscountNow = (bool)$snap['has_discount'];
|
||||
}
|
||||
|
||||
if (!$hasDiscountNow) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 1) data ostatniego wpisu (bieżący stan)
|
||||
$sqlLast = new DbQuery();
|
||||
$sqlLast->select('date_add');
|
||||
$sqlLast->from('omnibus_eu_free');
|
||||
$sqlLast->where('id_product = ' . (int)$id_product);
|
||||
$sqlLast->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlLast->where('id_currency = ' . (int)$currency);
|
||||
$sqlLast->where('is_default_currency = 1');
|
||||
$sqlLast->where('is_last = 1');
|
||||
$lastRow = Db::getInstance()->getRow($sqlLast);
|
||||
|
||||
if (empty($lastRow['date_add'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$lastDate = $lastRow['date_add'];
|
||||
|
||||
// 2) znajdź ostatni moment przed lastDate, kiedy rabatu NIE było (has_discount=0)
|
||||
$sqlPrevNoDisc = new DbQuery();
|
||||
$sqlPrevNoDisc->select('MAX(date_add) AS prev_no_disc');
|
||||
$sqlPrevNoDisc->from('omnibus_eu_free');
|
||||
$sqlPrevNoDisc->where('id_product = ' . (int)$id_product);
|
||||
$sqlPrevNoDisc->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlPrevNoDisc->where('id_currency = ' . (int)$currency);
|
||||
$sqlPrevNoDisc->where('is_default_currency = 1');
|
||||
$sqlPrevNoDisc->where('date_add < "' . pSQL($lastDate) . '"');
|
||||
$sqlPrevNoDisc->where('has_discount = 0');
|
||||
$rowPrev = Db::getInstance()->getRow($sqlPrevNoDisc);
|
||||
|
||||
// 3) start rabatu = pierwszy rekord z has_discount=1 po prev_no_disc
|
||||
// jeśli nigdy nie było has_discount=0, start = pierwszy rekord w historii z has_discount=1
|
||||
if (!empty($rowPrev['prev_no_disc'])) {
|
||||
$sqlStart = new DbQuery();
|
||||
$sqlStart->select('MIN(date_add) AS disc_start');
|
||||
$sqlStart->from('omnibus_eu_free');
|
||||
$sqlStart->where('id_product = ' . (int)$id_product);
|
||||
$sqlStart->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlStart->where('id_currency = ' . (int)$currency);
|
||||
$sqlStart->where('is_default_currency = 1');
|
||||
$sqlStart->where('has_discount = 1');
|
||||
$sqlStart->where('date_add > "' . pSQL($rowPrev['prev_no_disc']) . '"');
|
||||
$rowStart = Db::getInstance()->getRow($sqlStart);
|
||||
} else {
|
||||
$sqlStart = new DbQuery();
|
||||
$sqlStart->select('MIN(date_add) AS disc_start');
|
||||
$sqlStart->from('omnibus_eu_free');
|
||||
$sqlStart->where('id_product = ' . (int)$id_product);
|
||||
$sqlStart->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlStart->where('id_currency = ' . (int)$currency);
|
||||
$sqlStart->where('is_default_currency = 1');
|
||||
$sqlStart->where('has_discount = 1');
|
||||
$rowStart = Db::getInstance()->getRow($sqlStart);
|
||||
}
|
||||
|
||||
if (empty($rowStart['disc_start'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$discStart = $rowStart['disc_start'];
|
||||
|
||||
// okno 30 dni przed startem rabatu
|
||||
$startDateTime = (new DateTime($discStart))->modify('-' . $NumberOfDays . ' days')->format('Y-m-d H:i:s');
|
||||
|
||||
// minimalna cena REGULARNA w oknie przed rabatem
|
||||
$sqlMin = new DbQuery();
|
||||
$sqlMin->select('MIN(price_regular) AS price');
|
||||
$sqlMin->from('omnibus_eu_free');
|
||||
$sqlMin->where('id_product = ' . (int)$id_product);
|
||||
$sqlMin->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlMin->where('id_currency = ' . (int)$currency);
|
||||
$sqlMin->where('is_default_currency = 1');
|
||||
$sqlMin->where('date_add >= "' . pSQL($startDateTime) . '"');
|
||||
$sqlMin->where('date_add < "' . pSQL($discStart) . '"');
|
||||
|
||||
$minRow = Db::getInstance()->getRow($sqlMin);
|
||||
|
||||
if (empty($minRow) || !isset($minRow['price']) || $minRow['price'] === null) {
|
||||
|
||||
$sqlStartPrice = new DbQuery();
|
||||
$sqlStartPrice->select('price_regular AS price');
|
||||
$sqlStartPrice->from('omnibus_eu_free');
|
||||
$sqlStartPrice->where('id_product = ' . (int)$id_product);
|
||||
$sqlStartPrice->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sqlStartPrice->where('id_currency = ' . (int)$currency);
|
||||
$sqlStartPrice->where('is_default_currency = 1');
|
||||
$sqlStartPrice->where('has_discount = 1');
|
||||
$sqlStartPrice->orderBy('date_add ASC, id_omnibuseufree ASC');
|
||||
|
||||
$startPriceRow = Db::getInstance()->getRow($sqlStartPrice, false);
|
||||
|
||||
return (!empty($startPriceRow) && isset($startPriceRow['price'])) ? $startPriceRow : [];
|
||||
}
|
||||
|
||||
return (!empty($minRow) && isset($minRow['price'])) ? $minRow : [];
|
||||
}
|
||||
|
||||
// v1: najniższa z ostatnich X dni (tu możesz liczyć po regularnej albo po sale – zależnie od interpretacji)
|
||||
$date = new DateTime();
|
||||
$date->modify('-' . $NumberOfDays . ' days');
|
||||
$CutOffDate = $date->format('Y-m-d');
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('MIN(price_sale) AS price');
|
||||
$sql->select('price');
|
||||
$sql->from('omnibus_eu_free');
|
||||
$sql->where('id_product = ' . (int)$id_product);
|
||||
$sql->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sql->where('id_currency = ' . (int)$currency);
|
||||
$sql->where('is_default_currency = 1');
|
||||
$sql->where('id_product = ' . (int) $id_product);
|
||||
$sql->where('id_product_attribute = ' . (int) $id_product_attribute);
|
||||
$sql->where('id_currency = ' . (int) $currency);
|
||||
$sql->where('date_add >= "'.$CutOffDate.' 00:00:00"');
|
||||
|
||||
$row = Db::getInstance()->getRow($sql);
|
||||
if ($info_version == 2) {
|
||||
$sql->where('is_last = 0');
|
||||
}
|
||||
|
||||
return (!empty($row) && isset($row['price'])) ? $row : [];
|
||||
$sql->orderBy('price ASC');
|
||||
$sql->limit(1);
|
||||
$sqlResult = Db::getInstance()->executeS($sql);
|
||||
|
||||
return (!empty($sqlResult)) ? $sqlResult[0] : array();
|
||||
}
|
||||
|
||||
protected function hasDifferentHistoricalPrice($id_product, $id_product_attribute, $currency, $currentPrice)
|
||||
{
|
||||
$info_version = Configuration::get('OMNIBUSEUFREE_INFORMATION_VERSION', null, null, null, 2);
|
||||
$numberOfDays = (int) Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30);
|
||||
|
||||
$date = new DateTime();
|
||||
$date->modify('-' . $numberOfDays . ' days');
|
||||
$cutOffDate = $date->format('Y-m-d');
|
||||
|
||||
$sql = new DbQuery();
|
||||
$sql->select('id_omnibuseufree');
|
||||
$sql->from('omnibus_eu_free');
|
||||
$sql->where('id_product = ' . (int) $id_product);
|
||||
$sql->where('id_product_attribute = ' . (int) $id_product_attribute);
|
||||
$sql->where('id_currency = ' . (int) $currency);
|
||||
$sql->where('date_add >= "' . pSQL($cutOffDate . ' 00:00:00') . '"');
|
||||
$sql->where('ABS(price - ' . (float) $currentPrice . ') > 0.000001');
|
||||
|
||||
if ($info_version == 2) {
|
||||
$sql->where('is_last = 0');
|
||||
}
|
||||
|
||||
$sql->limit(1);
|
||||
|
||||
return (bool) Db::getInstance()->getValue($sql);
|
||||
}
|
||||
|
||||
protected function formatDisplayPrice($price, $currency, $precisionOverride = null)
|
||||
{
|
||||
if ($precisionOverride !== null) {
|
||||
$priceDisplayPrecision = (int) $precisionOverride;
|
||||
} else {
|
||||
$priceDisplayPrecision = (int) Configuration::get('PS_PRICE_DISPLAY_PRECISION', null, null, null, _PS_PRICE_DISPLAY_PRECISION_);
|
||||
}
|
||||
$roundedPrice = Tools::ps_round((float) $price, $priceDisplayPrecision);
|
||||
|
||||
return PrestashopCompatibility::formatPrice(_PS_VERSION_, $roundedPrice, $currency);
|
||||
}
|
||||
|
||||
public function hookDisplayOmnibusEuFree($params)
|
||||
{
|
||||
$currency = $this->context->currency;
|
||||
$lastMinimalPrice = $this->getLastMinimalPrice(
|
||||
(int)$params['product']['id_product'],
|
||||
(int)$params['product']['id_product_attribute'],
|
||||
(int)$currency->id,
|
||||
(bool)$params['product']['has_discount']
|
||||
);
|
||||
$debugEnabled = (bool) Tools::getValue('omnibuseufree_debug');
|
||||
$idProduct = isset($params['product']['id_product']) ? (int) $params['product']['id_product'] : 0;
|
||||
$idProductAttribute = isset($params['product']['id_product_attribute']) ? (int) $params['product']['id_product_attribute'] : 0;
|
||||
$lastMinimalPrice = $this->getLastMinimalPrice($idProduct, $idProductAttribute, $currency->id);
|
||||
$regularPrice = isset($params['product']['regular_price']) ? $params['product']['regular_price'] : null;
|
||||
$displayPrecisionOverride = null;
|
||||
$forcedFallbackNoPreDiscountHistory = false;
|
||||
|
||||
if (isset($params['product']['price_amount']) && is_numeric($params['product']['price_amount'])) {
|
||||
$priceAmount = (float) $params['product']['price_amount'];
|
||||
if (abs($priceAmount - round($priceAmount)) < 0.000001) {
|
||||
$displayPrecisionOverride = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$fallbackPrice = null;
|
||||
if (is_string($regularPrice) && $regularPrice !== '') {
|
||||
// Prefer the already prepared regular (non-discounted) price from product presenter.
|
||||
$fallbackPrice = $regularPrice;
|
||||
} elseif ($idProduct > 0) {
|
||||
// Compute regular (without reduction) price if presenter did not provide it.
|
||||
$useTax = Product::getTaxCalculationMethod((int) $this->context->customer->id) != PS_TAX_EXC;
|
||||
$regularRaw = Product::getPriceStatic($idProduct, $useTax, $idProductAttribute, 6, null, false, false);
|
||||
$fallbackPrice = $this->formatDisplayPrice((float) $regularRaw, $currency, $displayPrecisionOverride);
|
||||
} elseif (isset($params['product']['price_amount']) && is_numeric($params['product']['price_amount'])) {
|
||||
// Last resort if product id is missing in hook params.
|
||||
$fallbackPrice = $this->formatDisplayPrice((float) $params['product']['price_amount'], $currency, $displayPrecisionOverride);
|
||||
} elseif (isset($params['product']['price']) && is_numeric($params['product']['price'])) {
|
||||
$fallbackPrice = $this->formatDisplayPrice((float) $params['product']['price'], $currency, $displayPrecisionOverride);
|
||||
} elseif (isset($params['product']['price']) && is_string($params['product']['price']) && $params['product']['price'] !== '') {
|
||||
$fallbackPrice = $params['product']['price'];
|
||||
}
|
||||
|
||||
if (!empty($lastMinimalPrice)) {
|
||||
$minimalPrice = PrestashopCompatibility::formatPrice(_PS_VERSION_, $lastMinimalPrice['price'], $currency);
|
||||
if (
|
||||
!empty($params['product']['has_discount']) &&
|
||||
isset($params['product']['price_amount']) &&
|
||||
is_numeric($params['product']['price_amount']) &&
|
||||
!$this->hasDifferentHistoricalPrice($idProduct, $idProductAttribute, $currency->id, (float) $params['product']['price_amount'])
|
||||
) {
|
||||
$lastMinimalPrice = array();
|
||||
$forcedFallbackNoPreDiscountHistory = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($lastMinimalPrice)) {
|
||||
$minimalPrice = $this->formatDisplayPrice($lastMinimalPrice['price'], $currency, $displayPrecisionOverride);
|
||||
}
|
||||
else {
|
||||
$minimalPrice = null;
|
||||
@@ -274,8 +246,27 @@ class OmnibusEuFree extends Module
|
||||
'OmnibuseufreeInfoVersion' => (int) Configuration::get('OMNIBUSEUFREE_INFORMATION_VERSION', null, null, null, 2),
|
||||
'OmnibuseufreeProductPriceMin' => $minimalPrice,
|
||||
'OmnibuseufreeProductPriceCurrent' => $params['product']['price'],
|
||||
'OmnibuseufreeProductPriceRegular' => $regularPrice,
|
||||
'OmnibuseufreeProductPriceFallback' => $fallbackPrice,
|
||||
'OmnibuseufreeProductDiscount' => (bool) $params['product']['has_discount'],
|
||||
'OmnibuseufreeNumberOfDays' => (int) Configuration::get('OMNIBUSEUFREE_DAYS', null, null, null, 30),
|
||||
'OmnibuseufreeDebugEnabled' => $debugEnabled,
|
||||
'OmnibuseufreeDebugData' => [
|
||||
'marker' => 'omnibuseufree-debug-2026-03-16',
|
||||
'product_id' => $idProduct,
|
||||
'product_attribute_id' => $idProductAttribute,
|
||||
'currency_id' => isset($currency->id) ? (int) $currency->id : null,
|
||||
'currency_iso' => isset($currency->iso_code) ? (string) $currency->iso_code : '',
|
||||
'price_display_precision' => (int) Configuration::get('PS_PRICE_DISPLAY_PRECISION', null, null, null, _PS_PRICE_DISPLAY_PRECISION_),
|
||||
'display_precision_override' => $displayPrecisionOverride === null ? 'null' : (string) $displayPrecisionOverride,
|
||||
'param_price' => isset($params['product']['price']) ? (string) $params['product']['price'] : null,
|
||||
'param_price_amount' => isset($params['product']['price_amount']) ? (string) $params['product']['price_amount'] : null,
|
||||
'param_regular_price' => isset($params['product']['regular_price']) ? (string) $params['product']['regular_price'] : null,
|
||||
'computed_fallback' => (string) $fallbackPrice,
|
||||
'computed_minimal' => (string) $minimalPrice,
|
||||
'has_discount' => !empty($params['product']['has_discount']) ? '1' : '0',
|
||||
'forced_fallback_no_pre_discount_history' => $forcedFallbackNoPreDiscountHistory ? '1' : '0',
|
||||
],
|
||||
]);
|
||||
|
||||
return $this->display(__FILE__, '/views/templates/hook/presta_studio_omnibus_price.tpl');
|
||||
@@ -302,7 +293,7 @@ class OmnibusEuFree extends Module
|
||||
foreach ($rowValue as $key => $value) {
|
||||
if (isset($OmnibusData[$rowId]['price']) && $key == 'id_currency') {
|
||||
$currency = Currency::getCurrencyInstance((int) $value);
|
||||
$OmnibusData[$rowId]['price_locale'] = PrestashopCompatibility::formatPrice(_PS_VERSION_, $OmnibusData[$rowId]['price'], $currency);
|
||||
$OmnibusData[$rowId]['price_locale'] = $this->formatDisplayPrice($OmnibusData[$rowId]['price'], $currency);
|
||||
$OmnibusData[$rowId]['currency_iso_code'] = $currency->iso_code;
|
||||
}
|
||||
elseif ($key == 'id_product_attribute') {
|
||||
@@ -370,7 +361,7 @@ class OmnibusEuFree extends Module
|
||||
|
||||
// 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.
|
||||
// This hook fires once PER combination, so running here is wasteful.
|
||||
if ($combinationCount > 30) {
|
||||
return;
|
||||
}
|
||||
@@ -502,7 +493,6 @@ 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',
|
||||
@@ -657,249 +647,91 @@ class OmnibusEuFree extends Module
|
||||
return $ToChange == 0 ? false : true;
|
||||
}
|
||||
|
||||
protected function getLastSnapshot($id_product = 0, $id_product_attribute = 0, $id_currency = null)
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('price_regular, price_sale, has_discount, currency_conversion_rate');
|
||||
$sql->from('omnibus_eu_free');
|
||||
$sql->where('id_product = ' . (int)$id_product);
|
||||
$sql->where('id_product_attribute = ' . (int)$id_product_attribute);
|
||||
$sql->where('is_last = 1');
|
||||
$sql->where('is_default_currency = 1');
|
||||
|
||||
if ($id_currency !== null) {
|
||||
$sql->where('id_currency = ' . (int)$id_currency);
|
||||
}
|
||||
|
||||
$sql->limit(1);
|
||||
return Db::getInstance()->getRow($sql);
|
||||
}
|
||||
|
||||
protected function getPricesSnapshot($id_product, $id_product_attribute, $id_currency)
|
||||
{
|
||||
$context = Context::getContext();
|
||||
|
||||
$oldCurrency = $context->currency;
|
||||
if ((int)$id_currency > 0) {
|
||||
$context->currency = new Currency((int)$id_currency);
|
||||
}
|
||||
|
||||
// regularna (bez redukcji)
|
||||
$regular = (float) Product::getPriceStatic(
|
||||
(int)$id_product,
|
||||
true,
|
||||
(int)$id_product_attribute,
|
||||
6,
|
||||
null,
|
||||
false,
|
||||
false // use_reduction = false
|
||||
);
|
||||
|
||||
// sprzedażowa (z redukcją)
|
||||
$sale = (float) Product::getPriceStatic(
|
||||
(int)$id_product,
|
||||
true,
|
||||
(int)$id_product_attribute,
|
||||
6,
|
||||
null,
|
||||
false,
|
||||
true // use_reduction = true
|
||||
);
|
||||
|
||||
// przywróć walutę
|
||||
$context->currency = $oldCurrency;
|
||||
|
||||
$hasDiscount = ($sale > 0 && $regular > 0 && ($sale + 0.0001) < $regular) ? 1 : 0;
|
||||
$diff = $hasDiscount ? ($regular - $sale) : 0.0;
|
||||
|
||||
return [
|
||||
'regular' => $regular,
|
||||
'sale' => $sale,
|
||||
'has_discount' => $hasDiscount,
|
||||
'diff' => $diff,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function normalizeCurrency($currency)
|
||||
{
|
||||
if (is_array($currency)) {
|
||||
return [
|
||||
'id' => (int) ($currency['id_currency'] ?? $currency['id'] ?? 0),
|
||||
'rate' => (float) ($currency['conversion_rate'] ?? $currency['rate'] ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
// obiekt Currency
|
||||
return [
|
||||
'id' => (int) ($currency->id ?? 0),
|
||||
'rate' => (float) ($currency->conversion_rate ?? 0),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function addProductPrice($id_product = null)
|
||||
{
|
||||
if (!isset($id_product)) {
|
||||
throw new Exception('Missing parameter: $id_product');
|
||||
}
|
||||
|
||||
$id_product = (int)$id_product;
|
||||
$product = new Product($id_product);
|
||||
$product_price = $product->getPrice();
|
||||
|
||||
$currencies = Currency::getCurrencies(true, true);
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
|
||||
// snapshot w default walucie do porównania (żeby nie dopisywać non stop)
|
||||
$snapDefault = $this->getPricesSnapshot($id_product, 0, (int)$defaultCurrency->id);
|
||||
|
||||
if ((float)$snapDefault['sale'] != 0.0) {
|
||||
$last = $this->getLastSnapshot($id_product, 0);
|
||||
if($product_price != 0){
|
||||
$omnibus_price = array();
|
||||
$omnibus_price = $this->getLastPrice($id_product, 0);
|
||||
|
||||
$check_currency = $this->checkCurrencyConversionRate($id_product, 0);
|
||||
|
||||
$changed =
|
||||
empty($last)
|
||||
|| abs((float)$last['price_regular'] - (float)$snapDefault['regular']) > 0.0001
|
||||
|| abs((float)$last['price_sale'] - (float)$snapDefault['sale']) > 0.0001
|
||||
|| (int)$last['has_discount'] !== (int)$snapDefault['has_discount']
|
||||
|| (bool)$check_currency === true;
|
||||
|
||||
if ($changed) {
|
||||
$this->clearLastPrice($id_product, 0);
|
||||
if (empty($omnibus_price) || $product_price != $omnibus_price[0]['price'] || (bool) $check_currency == true) {
|
||||
$this->clearLastPrice($id_product);
|
||||
$currencies = Currency::getCurrencies();
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
$c = $this->normalizeCurrency($currency);
|
||||
|
||||
$id_currency = (int)$c['id'];
|
||||
$conversion_rate = (float)$c['rate'];
|
||||
|
||||
if ($id_currency <= 0) {
|
||||
continue;
|
||||
if ($currency['id_currency'] == $defaultCurrency->id) {
|
||||
$isDefaultCurrency = 1;
|
||||
$product_price_currency = $product_price;
|
||||
}
|
||||
else {
|
||||
$isDefaultCurrency = 0;
|
||||
$product_price_currency = Tools::convertPrice($product_price, $currency);
|
||||
}
|
||||
|
||||
$isDefaultCurrency = ($id_currency === (int)$defaultCurrency->id) ? 1 : 0;
|
||||
|
||||
$snap = $this->getPricesSnapshot($id_product, 0, $id_currency);
|
||||
|
||||
if ((float)$snap['sale'] <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->insertToOmnibusTable(
|
||||
$id_product,
|
||||
0,
|
||||
$snap,
|
||||
$id_currency,
|
||||
$isDefaultCurrency,
|
||||
$conversion_rate
|
||||
);
|
||||
$this->insertToOmnibusTable($id_product, 0, $product_price_currency, $currency['id_currency'], $isDefaultCurrency, $currency['conversion_rate']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function addProductPriceWithCombinations($id_product = null)
|
||||
{
|
||||
if (!isset($id_product))
|
||||
{
|
||||
throw new Exception('Missing parameter: $id_product');
|
||||
}
|
||||
|
||||
$id_product = (int)$id_product;
|
||||
|
||||
Product::flushPriceCache();
|
||||
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
$id_default_currency = (int)$defaultCurrency->id;
|
||||
|
||||
// Najstabilniejsza lista kombinacji (bez powtórek)
|
||||
$attributeRows = Product::getProductAttributesIds($id_product);
|
||||
if (empty($attributeRows))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Lista walut (aktywnych)
|
||||
$currencies = Currency::getCurrencies(true, true);
|
||||
|
||||
foreach ($attributeRows as $row)
|
||||
{
|
||||
$id_product_attribute = (int)$row['id_product_attribute'];
|
||||
|
||||
// Snapshot w default walucie do porównania zmian
|
||||
$snapDefault = $this->getPricesSnapshot($id_product, $id_product_attribute, $id_default_currency);
|
||||
|
||||
if ((float)$snapDefault['sale'] <= 0.0)
|
||||
{
|
||||
continue;
|
||||
if (!isset($id_product)) {
|
||||
throw new Exception('Missing parameter: $id_product');
|
||||
}
|
||||
|
||||
$last = $this->getLastSnapshot($id_product, $id_product_attribute);
|
||||
$check_currency = $this->checkCurrencyConversionRate($id_product, $id_product_attribute);
|
||||
$product = new Product($id_product);
|
||||
$product_combinations = $product->getAttributeCombinations();
|
||||
|
||||
$changed =
|
||||
empty($last)
|
||||
|| abs((float)$last['price_regular'] - (float)$snapDefault['regular']) > 0.0001
|
||||
|| abs((float)$last['price_sale'] - (float)$snapDefault['sale']) > 0.0001
|
||||
|| (int)$last['has_discount'] !== (int)$snapDefault['has_discount']
|
||||
|| (bool)$check_currency === true;
|
||||
if (!empty($product_combinations)) {
|
||||
$currencies = Currency::getCurrencies();
|
||||
$defaultCurrency = Currency::getDefaultCurrency();
|
||||
|
||||
if (!$changed)
|
||||
{
|
||||
continue;
|
||||
foreach ($product_combinations as $combination) {
|
||||
$product_price = $product->getPrice(true, $combination['id_product_attribute']);
|
||||
|
||||
if($product_price != 0){
|
||||
$omnibus_price = array();
|
||||
$omnibus_price = $this->getLastPrice($id_product, $combination['id_product_attribute']);
|
||||
|
||||
$check_currency = $this->checkCurrencyConversionRate($id_product, $combination['id_product_attribute']);
|
||||
|
||||
if (empty($omnibus_price) || $product_price != $omnibus_price[0]['price'] || (bool) $check_currency == true) {
|
||||
$this->clearLastPrice($id_product, $combination['id_product_attribute']);
|
||||
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency['id_currency'] == $defaultCurrency->id) {
|
||||
$isDefaultCurrency = 1;
|
||||
$product_price_currency = $product_price;
|
||||
}
|
||||
else {
|
||||
$isDefaultCurrency = 0;
|
||||
$product_price_currency = Tools::convertPrice($product_price, $currency);
|
||||
}
|
||||
|
||||
$this->insertToOmnibusTable($id_product, $combination['id_product_attribute'], $product_price_currency, $currency['id_currency'], $isDefaultCurrency, $currency['conversion_rate']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Zerujemy is_last dla tej kombinacji (dla wszystkich walut)
|
||||
$this->clearLastPrice($id_product, $id_product_attribute);
|
||||
|
||||
// Wstawiamy nowe snapshoty dla wszystkich walut
|
||||
foreach ($currencies as $currency)
|
||||
{
|
||||
$c = $this->normalizeCurrency($currency);
|
||||
$id_currency = (int)$c['id'];
|
||||
$conversion_rate = (float)$c['rate'];
|
||||
|
||||
if ($id_currency <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$isDefaultCurrency = ($id_currency === $id_default_currency) ? 1 : 0;
|
||||
|
||||
$snap = $this->getPricesSnapshot($id_product, $id_product_attribute, $id_currency);
|
||||
|
||||
if ((float)$snap['sale'] <= 0.0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->insertToOmnibusTable(
|
||||
$id_product,
|
||||
$id_product_attribute,
|
||||
$snap,
|
||||
$id_currency,
|
||||
$isDefaultCurrency,
|
||||
$conversion_rate
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function insertToOmnibusTable($id_product = 0, $id_product_attribute = 0, $snap = [], $currency = 0, $isDefaultCurrency = 0, $CurrencyConversionRate = 0)
|
||||
protected function insertToOmnibusTable($id_product = 0, $id_product_attribute = 0, $product_price = 0, $currency = 0, $isDefaultCurrency = 0, $CurrencyConversionRate = 0)
|
||||
{
|
||||
return Db::getInstance()->insert('omnibus_eu_free', [
|
||||
$result = Db::getInstance()->insert('omnibus_eu_free', [
|
||||
'id_product' => (int) $id_product,
|
||||
'id_product_attribute' => (int) $id_product_attribute,
|
||||
|
||||
// zostaw stare price jako "sale" dla kompatybilności szablonu / starego kodu
|
||||
'price' => pSQL($snap['sale']),
|
||||
|
||||
'price_regular' => pSQL($snap['regular']),
|
||||
'price_sale' => pSQL($snap['sale']),
|
||||
'has_discount' => (int) $snap['has_discount'],
|
||||
'discount_diff' => pSQL($snap['diff']),
|
||||
|
||||
'price' => pSQL($product_price),
|
||||
'id_currency' => (int) $currency,
|
||||
'is_default_currency' => (int) $isDefaultCurrency,
|
||||
'is_last' => 1,
|
||||
|
||||
@@ -21,11 +21,30 @@
|
||||
{l s='Lowest price in %d days before discount: ' sprintf=[$OmnibuseufreeNumberOfDays] mod='omnibuseufree'}<span class="presta-studio-price-history-price">{$OmnibuseufreeProductPriceMin}</span>
|
||||
{else}
|
||||
{* when history is empty *}
|
||||
{l s='Lowest price in %d days: ' sprintf=[$OmnibuseufreeNumberOfDays] mod='omnibuseufree'}<span class="presta-studio-price-history-price">{$OmnibuseufreeProductPriceCurrent}</span>
|
||||
{l s='Lowest price in %d days: ' sprintf=[$OmnibuseufreeNumberOfDays] mod='omnibuseufree'}<span class="presta-studio-price-history-price">{$OmnibuseufreeProductPriceFallback|default:$OmnibuseufreeProductPriceCurrent}</span>
|
||||
{/if}
|
||||
{else}
|
||||
{l s='Lowest price in %d days: ' sprintf=[$OmnibuseufreeNumberOfDays] mod='omnibuseufree'}<span class="presta-studio-price-history-price">{$OmnibuseufreeProductPriceMin}</span>
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{if isset($OmnibuseufreeDebugEnabled) && $OmnibuseufreeDebugEnabled && isset($OmnibuseufreeDebugData)}
|
||||
<div class="presta-studio-price-history" style="margin-top:6px;">
|
||||
<p class="presta-studio-price-history-text" style="font-size:12px; line-height:1.35;">
|
||||
<strong>OMNIBUS DEBUG</strong><br>
|
||||
marker: {$OmnibuseufreeDebugData.marker}<br>
|
||||
product_id: {$OmnibuseufreeDebugData.product_id}, attr_id: {$OmnibuseufreeDebugData.product_attribute_id}<br>
|
||||
currency: {$OmnibuseufreeDebugData.currency_iso} ({$OmnibuseufreeDebugData.currency_id}), precision: {$OmnibuseufreeDebugData.price_display_precision}<br>
|
||||
precision_override: {$OmnibuseufreeDebugData.display_precision_override}<br>
|
||||
has_discount: {$OmnibuseufreeDebugData.has_discount}<br>
|
||||
param price: {$OmnibuseufreeDebugData.param_price}<br>
|
||||
param price_amount: {$OmnibuseufreeDebugData.param_price_amount}<br>
|
||||
param regular_price: {$OmnibuseufreeDebugData.param_regular_price}<br>
|
||||
computed fallback: {$OmnibuseufreeDebugData.computed_fallback}<br>
|
||||
computed minimal: {$OmnibuseufreeDebugData.computed_minimal}<br>
|
||||
forced_fallback_no_pre_discount_history: {$OmnibuseufreeDebugData.forced_fallback_no_pre_discount_history}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
Reference in New Issue
Block a user