ver. 0.288: BasketCalculator + ShopBasketController migration, cms\Layout removal
- Migrate front\factory\ShopBasket → Domain\Basket\BasketCalculator (4 static methods, 18 callers updated) - Migrate front\controls\ShopBasket → front\Controllers\ShopBasketController (camelCase, instance methods) - Add snake_case→camelCase action dispatch for new controllers in Site::route() - Update title()/page_title() to check front\Controllers\ before fallback - Remove cms\Layout class (replaced by $layoutsRepo->find()) - Add 8 tests for BasketCalculator (484 tests, 1528 assertions) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
62
autoload/Domain/Basket/BasketCalculator.php
Normal file
62
autoload/Domain/Basket/BasketCalculator.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace Domain\Basket;
|
||||
|
||||
class BasketCalculator
|
||||
{
|
||||
public static function summaryWp($basket)
|
||||
{
|
||||
$wp = 0;
|
||||
if (is_array($basket)) {
|
||||
foreach ($basket as $product) {
|
||||
$wp += $product['wp'] * $product['quantity'];
|
||||
}
|
||||
}
|
||||
return $wp;
|
||||
}
|
||||
|
||||
public static function countProductsText($count)
|
||||
{
|
||||
$count = (int)$count;
|
||||
if ($count === 1) {
|
||||
return $count . ' produkt';
|
||||
}
|
||||
if ($count >= 2 && $count <= 4) {
|
||||
return $count . ' produkty';
|
||||
}
|
||||
return $count . ' produktów';
|
||||
}
|
||||
|
||||
public static function summaryPrice($basket, $coupon = null)
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$summary = 0;
|
||||
|
||||
if (is_array($basket)) {
|
||||
foreach ($basket as $position) {
|
||||
$product = \shop\Product::getFromCache((int)$position['product-id'], $lang_id);
|
||||
|
||||
$product_price_tmp = \shop\Product::calculate_basket_product_price(
|
||||
(float)$product['price_brutto_promo'],
|
||||
(float)$product['price_brutto'],
|
||||
$coupon,
|
||||
$position
|
||||
);
|
||||
$summary += $product_price_tmp['price_new'] * $position['quantity'];
|
||||
}
|
||||
}
|
||||
|
||||
return \Shared\Helpers\Helpers::normalize_decimal($summary);
|
||||
}
|
||||
|
||||
public static function countProducts($basket)
|
||||
{
|
||||
$count = 0;
|
||||
if (is_array($basket)) {
|
||||
foreach ($basket as $product) {
|
||||
$count += $product['quantity'];
|
||||
}
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user