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:
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
|
||||
class ShopBasket
|
||||
{
|
||||
|
||||
public static function summary_wp( $basket )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
foreach ( $basket as $product )
|
||||
{
|
||||
$wp += $product[ 'wp' ] * $product[ 'quantity' ];
|
||||
}
|
||||
return $wp;
|
||||
}
|
||||
|
||||
public static function count_products_text( $count )
|
||||
{
|
||||
$count_products = $count;
|
||||
switch ( true )
|
||||
{
|
||||
case ( $count == 0 ): $count_products .= ' produktów';
|
||||
break;
|
||||
case ( $count == 1 ): $count_products .= ' produkt';
|
||||
break;
|
||||
case ( $count == 2 or $count == 3 or $count == 4 ): $count_products .= ' produkty';
|
||||
break;
|
||||
case ( $count >= 5 ): $count_products .= ' produktów';
|
||||
break;
|
||||
}
|
||||
return $count_products;
|
||||
}
|
||||
|
||||
public static function summary_price( $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 count_products( $basket )
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
if ( is_array( $basket ) )
|
||||
foreach ( $basket as $product )
|
||||
$count += $product[ 'quantity' ];
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -97,7 +97,7 @@ class ShopOrder
|
||||
|
||||
$transport = \front\factory\ShopTransport::transport( $transport_id );
|
||||
$payment_method = \front\factory\ShopPaymentMethod::payment_method( $payment_id );
|
||||
$basket_summary = \front\factory\ShopBasket::summary_price( $basket, $coupon );
|
||||
$basket_summary = \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon );
|
||||
$order_number = self::generate_order_number();
|
||||
$order_date = date( 'Y-m-d H:i:s' );
|
||||
$hash = md5( $order_number . time() );
|
||||
|
||||
@@ -30,7 +30,7 @@ class ShopTransport
|
||||
$transports_tmp = unserialize( $objectData );
|
||||
}
|
||||
|
||||
$wp_summary = \front\factory\ShopBasket::summary_wp( $basket );
|
||||
$wp_summary = \Domain\Basket\BasketCalculator::summaryWp( $basket );
|
||||
|
||||
foreach ( $transports_tmp as $tr )
|
||||
{
|
||||
@@ -41,7 +41,7 @@ class ShopTransport
|
||||
}
|
||||
|
||||
|
||||
if ( \Shared\Helpers\Helpers::normalize_decimal( \front\factory\ShopBasket::summary_price( $basket, $coupon ) ) >= \Shared\Helpers\Helpers::normalize_decimal( $settings['free_delivery'] ) )
|
||||
if ( \Shared\Helpers\Helpers::normalize_decimal( \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ) ) >= \Shared\Helpers\Helpers::normalize_decimal( $settings['free_delivery'] ) )
|
||||
{
|
||||
for ( $i = 0; $i < count( $transports ); $i++ ){
|
||||
if($transports[ $i ]['delivery_free'] == 1) {
|
||||
|
||||
Reference in New Issue
Block a user