Add promotional price rounding module with price adjustment logic

This commit is contained in:
2025-04-13 23:31:32 +02:00
parent 3865d550a2
commit 1751e22e70
3 changed files with 61 additions and 1 deletions

View File

@@ -1082,7 +1082,7 @@
},
".htaccess": {
"type": "-",
"size": 7169,
"size": 5737,
"lmtime": 1743169569305,
"modified": true
},

View File

@@ -3851,6 +3851,7 @@ class ProductCore extends ObjectModel
$result = self::$_pricesLevel2[$cache_id_2][(int) $id_product_attribute];
// echo '<pre>' . print_r( $specific_price , true) . '</pre>';
if (!$specific_price || $specific_price['price'] < 0) {
$price = (float) $result['price'];
} else {
@@ -3954,6 +3955,11 @@ class ProductCore extends ObjectModel
$price -= $specific_price_reduction;
}
// Zaokrąglanie w górę tylko gdy mamy redukcję
if ($specific_price && $specific_price['reduction'] > 0) {
$price = Tools::ceilf($price);
}
// Group reduction
if ($use_group_reduction) {
$reduction_from_category = GroupReduction::getValueForProduct($id_product, $id_group);

View File

@@ -0,0 +1,54 @@
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class PromotionalPriceRounding extends Module
{
public function __construct()
{
$this->name = 'promotionalpricerounding';
$this->tab = 'pricing';
$this->version = '1.0.0';
$this->author = 'Twoja Nazwa';
$this->need_instance = 0;
$this->ps_versions_compliancy = ['min' => '1.7.0.0', 'max' => _PS_VERSION_];
parent::__construct();
$this->displayName = $this->l('Zaokrąglanie cen promocyjnych w górę');
$this->description = $this->l('Zaokrągla ceny promocyjne w górę, tak jak zwykłe ceny.');
$this->confirmUninstall = $this->l('Czy na pewno chcesz odinstalować ten moduł?');
}
public function install()
{
return parent::install() && $this->registerHook('actionProductGetPrice');
}
public function uninstall()
{
return parent::uninstall() && $this->unregisterHook('actionProductGetPrice');
}
public function hookActionProductGetPrice($params)
{
if (isset($params['product'])) {
$product = $params['product'];
$price = $params['price'];
$currency = Context::getContext()->currency;
$decimals = is_array($currency) ? (int) $currency['decimals'] : (int) $currency->decimals;
$factor = pow(10, $decimals);
// Sprawdź, czy produkt ma aktywną promocję
if (isset($product->specificPrice) && $product->specificPrice && $product->specificPrice['reduction'] > 0) {
$params['price'] = ceil($price * $factor) / $factor;
} elseif (isset($product->reduction) && $product->reduction > 0) {
// Obsługa reguł cenowych
$params['price'] = ceil($price * $factor) / $factor;
}
}
}
}