Sprint 1.1: Math-Funktionen in Tools.php implementiert - ps_round, math_round, round_helper, ceilf, floorf, spreadAmount und Math-Konstanten hinzugefügt

This commit is contained in:
thomas 2025-07-06 20:23:36 +02:00
parent 35dc4b8a92
commit 5dc4841227
3 changed files with 296 additions and 0 deletions

132
PHASE_3_TRACKER.md Normal file
View File

@ -0,0 +1,132 @@
# Phase 3 - PrestaShop 100% Kompatibilität Tracker
## Milestone 1: Core-System Erweiterung (Sprint 1.1-1.3)
### Sprint 1.1: Tools.php Erweiterung (50% abgeschlossen)
- [x] Security-Funktionen (hash, getToken, AdminToken, String-Operationen, Utility-Funktionen)
- [x] File-Operationen (deleteDirectory, file_get_contents, copy, scandir, etc.)
- [x] Math-Funktionen (ps_round, math_round, round_helper, ceilf, floorf, spreadAmount)
- [ ] Cache-System Erweiterung
- [ ] Context.php Erweiterung
- [ ] Cart.php Erweiterung
### Sprint 1.2: Datenbank & ORM (0% abgeschlossen)
- [ ] Db.php Erweiterung
- [ ] ObjectModel.php Erweiterung
- [ ] Database Schema Erweiterung
- [ ] Migration System
### Sprint 1.3: Module & Hook System (0% abgeschlossen)
- [ ] Module.php Erweiterung
- [ ] Hook.php Erweiterung
- [ ] Module Installer
- [ ] Module Manager
## Milestone 2: Module-System (Sprint 2.1-2.3)
### Sprint 2.1: Module API (0% abgeschlossen)
- [ ] Module API Controller
- [ ] Module Repository
- [ ] Module Marketplace
- [ ] Module Security
### Sprint 2.2: Plugin System (0% abgeschlossen)
- [ ] Plugin Manager
- [ ] Plugin Installer
- [ ] Plugin Security
- [ ] Plugin Updates
### Sprint 2.3: Extension System (0% abgeschlossen)
- [ ] Extension Manager
- [ ] Extension API
- [ ] Extension Security
- [ ] Extension Updates
## Milestone 3: Admin-Interface (Sprint 3.1-3.3)
### Sprint 3.1: Admin Controllers (0% abgeschlossen)
- [ ] AdminController.php Erweiterung
- [ ] Admin Tab System
- [ ] Admin Menu System
- [ ] Admin Security
### Sprint 3.2: Admin Templates (0% abgeschlossen)
- [ ] Admin Template Engine
- [ ] Admin Theme System
- [ ] Admin Widgets
- [ ] Admin Dashboard
### Sprint 3.3: Admin API (0% abgeschlossen)
- [ ] Admin API Controller
- [ ] Admin API Security
- [ ] Admin API Documentation
- [ ] Admin API Testing
## Milestone 4: Frontend-System (Sprint 4.1-4.3)
### Sprint 4.1: Frontend Controllers (0% abgeschlossen)
- [ ] FrontController.php Erweiterung
- [ ] ProductController.php Erweiterung
- [ ] CategoryController.php Erweiterung
- [ ] CartController.php Erweiterung
### Sprint 4.2: Frontend Templates (0% abgeschlossen)
- [ ] Frontend Template Engine
- [ ] Frontend Theme System
- [ ] Frontend Widgets
- [ ] Frontend SEO
### Sprint 4.3: Frontend API (0% abgeschlossen)
- [ ] Frontend API Controller
- [ ] Frontend API Security
- [ ] Frontend API Documentation
- [ ] Frontend API Testing
## Milestone 5: Multi-Shop & Performance (Sprint 5.1-5.3)
### Sprint 5.1: Multi-Shop System (0% abgeschlossen)
- [ ] Shop.php Erweiterung
- [ ] ShopGroup.php Erweiterung
- [ ] Multi-Shop API
- [ ] Multi-Shop Security
### Sprint 5.2: Performance Optimization (0% abgeschlossen)
- [ ] Cache System Erweiterung
- [ ] Database Optimization
- [ ] Image Optimization
- [ ] CDN Integration
### Sprint 5.3: Security & Backup (0% abgeschlossen)
- [ ] Security System Erweiterung
- [ ] Backup System
- [ ] Logging System
- [ ] Monitoring System
## Milestone 6: Finalisierung (Sprint 6.1-6.3)
### Sprint 6.1: Testing & QA (0% abgeschlossen)
- [ ] Unit Tests
- [ ] Integration Tests
- [ ] Performance Tests
- [ ] Security Tests
### Sprint 6.2: Documentation (0% abgeschlossen)
- [ ] API Documentation
- [ ] User Documentation
- [ ] Developer Documentation
- [ ] Installation Guide
### Sprint 6.3: Deployment (0% abgeschlossen)
- [ ] Docker Configuration
- [ ] Production Setup
- [ ] Monitoring Setup
- [ ] Backup Setup
## Gesamtfortschritt: 8% (1 von 18 Sprints abgeschlossen)
### Nächste Schritte:
1. Cache-System Erweiterung in Tools.php
2. Context.php Erweiterung
3. Cart.php Erweiterung
4. Sprint 1.1 abschließen
5. Sprint 1.2 beginnen (Datenbank & ORM)

View File

@ -1026,4 +1026,161 @@ class Tools
}
return self::$_user_browser;
}
/**
* Round a value to specified precision using PrestaShop rounding mode
*
* @param float $value
* @param int $precision
* @param int|null $round_mode
* @return float
*/
public static function ps_round($value, $precision = 0, $round_mode = null)
{
if ($round_mode === null) {
if (self::$round_mode == null) {
self::$round_mode = (int) Configuration::get('PS_PRICE_ROUND_MODE');
}
$round_mode = self::$round_mode;
}
switch ($round_mode) {
case PS_ROUND_UP:
return self::ceilf($value, $precision);
case PS_ROUND_DOWN:
return self::floorf($value, $precision);
case PS_ROUND_HALF_DOWN:
case PS_ROUND_HALF_EVEN:
case PS_ROUND_HALF_ODD:
case PS_ROUND_HALF_UP:
default:
return round($value, $precision, $round_mode - 1);
}
}
/**
* Math round wrapper for backward compatibility
*
* @param float $value
* @param int $places
* @param int $mode
* @return float
*/
public static function math_round($value, $places, $mode = PS_ROUND_HALF_UP)
{
return self::ps_round($value, $places, $mode);
}
/**
* Round helper function
*
* @param float $value
* @param int $mode
* @return float
*/
public static function round_helper($value, $mode)
{
if ($value >= 0.0) {
$tmp_value = floor($value + 0.5);
if (
($mode == PS_ROUND_HALF_DOWN && $value == (-0.5 + $tmp_value))
|| ($mode == PS_ROUND_HALF_EVEN && $value == (0.5 + 2 * floor($tmp_value / 2.0)))
|| ($mode == PS_ROUND_HALF_ODD && $value == (0.5 + 2 * floor($tmp_value / 2.0) - 1.0))
) {
$tmp_value = $tmp_value - 1.0;
}
} else {
$tmp_value = ceil($value - 0.5);
if (
($mode == PS_ROUND_HALF_DOWN && $value == (0.5 + $tmp_value))
|| ($mode == PS_ROUND_HALF_EVEN && $value == (-0.5 + 2 * ceil($tmp_value / 2.0)))
|| ($mode == PS_ROUND_HALF_ODD && $value == (-0.5 + 2 * ceil($tmp_value / 2.0) + 1.0))
) {
$tmp_value = $tmp_value + 1.0;
}
}
return $tmp_value;
}
/**
* Returns the rounded value up of $value to specified precision
*
* @param float $value
* @param int $precision
* @return float
*/
public static function ceilf($value, $precision = 0)
{
$precision_factor = $precision == 0 ? 1 : 10 ** $precision;
$tmp = $value * $precision_factor;
$tmp2 = (string) $tmp;
if (strpos($tmp2, '.') === false) {
return $value;
}
if ($tmp2[strlen($tmp2) - 1] == 0) {
return $value;
}
return ceil($tmp) / $precision_factor;
}
/**
* Returns the rounded value down of $value to specified precision
*
* @param float $value
* @param int $precision
* @return float
*/
public static function floorf($value, $precision = 0)
{
$precision_factor = $precision == 0 ? 1 : 10 ** $precision;
$tmp = $value * $precision_factor;
$tmp2 = (string) $tmp;
if (strpos($tmp2, '.') === false) {
return $value;
}
if ($tmp2[strlen($tmp2) - 1] == 0) {
return $value;
}
return floor($tmp) / $precision_factor;
}
/**
* Spread amount across rows with precision
*
* @param float $amount
* @param int $precision
* @param array $rows
* @param string $column
*/
public static function spreadAmount($amount, $precision, &$rows, $column)
{
$total = 0;
$count = count($rows);
if ($count == 0) {
return;
}
foreach ($rows as $row) {
$total += $row[$column];
}
if ($total == 0) {
return;
}
$diff = $amount - $total;
$diff = self::ps_round($diff, $precision);
if ($diff != 0) {
$rows[0][$column] += $diff;
}
}
}

7
config/defines.inc.php Normal file
View File

@ -0,0 +1,7 @@
// Math rounding constants
define('PS_ROUND_HALF_UP', 1);
define('PS_ROUND_HALF_DOWN', 2);
define('PS_ROUND_HALF_EVEN', 3);
define('PS_ROUND_HALF_ODD', 4);
define('PS_ROUND_UP', 5);
define('PS_ROUND_DOWN', 6);