diff --git a/ajax.php b/ajax.php index 076a823..1cdff48 100644 --- a/ajax.php +++ b/ajax.php @@ -63,7 +63,7 @@ if ( $a == 'basket_change_transport' ) \Shared\Helpers\Helpers::set_session( 'transport_id', \Shared\Helpers\Helpers::get( 'transport_id' ) ); $basket = \Shared\Helpers\Helpers::get_session( 'basket' ); - $basket_summary = \front\factory\ShopBasket::summary_price( $basket, null ); + $basket_summary = \Domain\Basket\BasketCalculator::summaryPrice( $basket, null ); $transport_cost = \front\factory\ShopTransport::transport_cost( \Shared\Helpers\Helpers::get( 'transport_id' ) ); echo json_encode( [ 'summary' => \Shared\Helpers\Helpers::decimal( $basket_summary + $transport_cost ) . ' zł' ] ); diff --git a/autoload/Domain/Basket/BasketCalculator.php b/autoload/Domain/Basket/BasketCalculator.php new file mode 100644 index 0000000..85082e0 --- /dev/null +++ b/autoload/Domain/Basket/BasketCalculator.php @@ -0,0 +1,62 @@ += 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; + } +} diff --git a/autoload/cms/class.Layout.php b/autoload/cms/class.Layout.php deleted file mode 100644 index c1f872a..0000000 --- a/autoload/cms/class.Layout.php +++ /dev/null @@ -1,44 +0,0 @@ - -namespace cms; -class Layout implements \ArrayAccess -{ - public function __construct( int $layout_id ) - { - global $mdb; - - $result = $mdb -> get( 'pp_layouts', '*', [ 'id' => $layout_id ] ); - if ( \Shared\Helpers\Helpers::is_array_fix( $result ) ) foreach ( $result as $key => $val ) - $this -> $key = $val; - } - - public function __get( $variable ) - { - if ( array_key_exists( $variable, $this -> data ) ) - return $this -> $variable; - } - - public function __set( $variable, $value ) - { - $this -> $variable = $value; - } - - public function offsetExists( $offset ) - { - return isset( $this -> $offset ); - } - - public function offsetGet( $offset ) - { - return $this -> $offset; - } - - public function offsetSet( $offset, $value ) - { - $this -> $offset = $value; - } - - public function offsetUnset( $offset ) - { - unset( $this -> $offset ); - } -} \ No newline at end of file diff --git a/autoload/front/controls/class.ShopBasket.php b/autoload/front/Controllers/ShopBasketController.php similarity index 70% rename from autoload/front/controls/class.ShopBasket.php rename to autoload/front/Controllers/ShopBasketController.php index c97ba0e..eeea899 100644 --- a/autoload/front/controls/class.ShopBasket.php +++ b/autoload/front/Controllers/ShopBasketController.php @@ -1,22 +1,20 @@ 'Koszyk' + 'mainView' => 'Koszyk' ]; - public static function basket_message_save() + public function basketMessageSave() { \Shared\Helpers\Helpers::set_session( 'basket_message', \Shared\Helpers\Helpers::get( 'basket_message' ) ); - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - public static function basket_remove_product() + public function basketRemoveProduct() { global $lang_id; @@ -31,24 +29,10 @@ class ShopBasket \Shared\Helpers\Helpers::set_session( 'basket', $basket ); - echo json_encode( [ - 'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [ - 'basket' => $basket, - 'lang_id' => $lang_id, - 'coupon' => $coupon - ] ), - 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), - 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), - 'products_count' => count( $basket ), - 'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [ - 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), - 'transport_id' => $basket_transport_method_id - ] ) - ] ); - exit; + $this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id ); } - public static function basket_increase_quantity_product() + public function basketIncreaseQuantityProduct() { global $lang_id; @@ -66,25 +50,10 @@ class ShopBasket \Shared\Helpers\Helpers::set_session( 'basket', $basket ); - echo json_encode( [ - 'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [ - 'basket' => $basket, - 'lang_id' => $lang_id, - 'coupon' => $coupon - ] ), - 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), - 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), - 'products_count' => count( $basket ), - 'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [ - 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), - 'transport_id' => $basket_transport_method_id - ] ) - ] - ); - exit; + $this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id ); } - public static function basket_decrease_quantity_product() + public function basketDecreaseQuantityProduct() { global $lang_id; @@ -102,24 +71,10 @@ class ShopBasket \Shared\Helpers\Helpers::set_session( 'basket', $basket ); - echo json_encode( [ - 'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [ - 'basket' => $basket, - 'lang_id' => $lang_id, - 'coupon' => $coupon - ] ), - 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), - 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), - 'products_count' => count( $basket ), - 'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [ - 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), - 'transport_id' => $basket_transport_method_id - ] ) - ] ); - exit; + $this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id ); } - public static function basket_change_quantity_product() + public function basketChangeQuantityProduct() { global $lang_id; @@ -139,24 +94,10 @@ class ShopBasket $basket = \Shared\Helpers\Helpers::get_session( 'basket' ); - echo json_encode( [ - 'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [ - 'basket' => $basket, - 'lang_id' => $lang_id, - 'coupon' => $coupon - ] ), - 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), - 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), - 'products_count' => count( $basket ), - 'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [ - 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), - 'transport_id' => $basket_transport_method_id - ] ) - ] ); - exit; + $this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id ); } - static public function product_message_change() + public function productMessageChange() { $basket = \Shared\Helpers\Helpers::get_session( 'basket' ); $basket[ \Shared\Helpers\Helpers::get( 'position_code' ) ]['message'] = \Shared\Helpers\Helpers::get( 'product_message' ); @@ -164,30 +105,29 @@ class ShopBasket exit; } - public static function basket_add_product() + public function basketAddProduct() { $basket = \shop\Basket::validate_basket( \Shared\Helpers\Helpers::get_session( 'basket' ) ); $values_tmp = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true ); + $values = []; + $attributes = []; + $custom_fields = []; foreach( $values_tmp as $key => $val ) $values[ $val['name'] ] = $val['value']; - // sprawdzam pola pod kątem wybranych atrybutów foreach( $values as $key => $val ) { if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false ) $attributes[] = $val; } - // stwórz tablicę dodatkowych pól wyszukując na podstawie custom_field[1], custom_field[2] itd. foreach( $values as $key => $val ) { if ( strpos( $key, 'custom_field' ) !== false ) { - // extract number from custom_field[1], custom_field[2] etc. preg_match( '/\d+/', $key, $matches ); $custom_field_id = $matches[0]; - $custom_fields[ $custom_field_id ] = $val; } } @@ -199,12 +139,10 @@ class ShopBasket $values['attributes'] = $attributes; } - $values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] ); $attributes_implode = ''; - // generuj unikalny kod produktu dodanego do koszyka - if ( is_array( $attributes ) ) + if ( is_array( $attributes ) and count( $attributes ) > 0 ) $attributes_implode = implode( '|', $attributes ); $product_code = md5( $values['product-id'] . $attributes_implode . $values['product-message'] . json_encode( $custom_fields ) ); @@ -225,95 +163,78 @@ class ShopBasket echo json_encode( [ 'result' => 'ok', - 'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ), - 'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ), + 'basket_mini_count' => \Domain\Basket\BasketCalculator::countProductsText( \Domain\Basket\BasketCalculator::countProducts( $basket ) ), + 'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ), 'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] ) ] ); exit; } - // sprawdzam czy została wybrana forma wysylki inpost i czy został wybrany paczkomat - static public function transport_method_inpost_check() + public function transportMethodInpostCheck() { - if ( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) === '2' or \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) === '1' ) + $transport_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ); + + if ( $transport_id === '2' or $transport_id === '1' ) { if ( !\Shared\Helpers\Helpers::get_session( 'basket-inpost-info' ) ) { - echo json_encode( [ - 'result' => 'bad' - ] ); + echo json_encode( [ 'result' => 'bad' ] ); exit; } } - if ( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) === '9' ) + if ( $transport_id === '9' ) { if ( !\Shared\Helpers\Helpers::get_session( 'basket_orlen_point_id' ) ) { - echo json_encode( [ - 'result' => 'bad' - ] ); + echo json_encode( [ 'result' => 'bad' ] ); exit; } } - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - // sprawdzam czy został wybrany paczkomat - static public function inpost_check() { + public function inpostCheck() + { if ( !\Shared\Helpers\Helpers::get_session( 'basket-inpost-info' ) ) - echo json_encode( [ - 'result' => 'bad' - ] ); + echo json_encode( [ 'result' => 'bad' ] ); else - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - static public function orlen_save() + public function orlenSave() { \Shared\Helpers\Helpers::set_session( 'basket_orlen_point_id', \Shared\Helpers\Helpers::get( 'orlen_point_id' ) ); \Shared\Helpers\Helpers::set_session( 'basket_orlen_point_info', \Shared\Helpers\Helpers::get( 'orlen_point_name' ) ); - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - public static function inpost_save() + public function inpostSave() { \Shared\Helpers\Helpers::set_session( 'basket-inpost-info', \Shared\Helpers\Helpers::get( 'paczkomat' ) ); - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - public static function basket_payment_method_set() + public function basketPaymentMethodSet() { \Shared\Helpers\Helpers::set_session( 'basket-payment-method-id', \Shared\Helpers\Helpers::get( 'payment_method_id' ) ); - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - public static function basket_transport_method_set() + public function basketTransportMethodSet() { \Shared\Helpers\Helpers::set_session( 'basket-transport-method-id', \Shared\Helpers\Helpers::get( 'transport_method_id' ) ); - echo json_encode( [ - 'result' => 'ok' - ] ); + echo json_encode( [ 'result' => 'ok' ] ); exit; } - public static function basket_payments_methods() + public function basketPaymentsMethods() { \Shared\Helpers\Helpers::set_session( 'basket-transport-method-id', \Shared\Helpers\Helpers::get( 'transport_method_id' ) ); @@ -327,7 +248,7 @@ class ShopBasket exit; } - public static function summary_view() + public function summaryView() { global $lang_id, $settings; @@ -352,11 +273,9 @@ class ShopBasket ] ); } - // zapisanie koszyka jako zamówienie - static public function basket_save() + public function basketSave() { $client = \Shared\Helpers\Helpers::get_session( 'client' ); - $payment_method = \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ); if ( \shop\Basket::check_product_quantity_in_stock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) ) { @@ -418,7 +337,7 @@ class ShopBasket } } - public static function main_view() + public function mainView() { global $lang_id, $page, $settings; @@ -456,4 +375,22 @@ class ShopBasket ] ); } -} \ No newline at end of file + private function jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id ) + { + echo json_encode( [ + 'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [ + 'basket' => $basket, + 'lang_id' => $lang_id, + 'coupon' => $coupon + ] ), + 'basket_mini_count' => \Domain\Basket\BasketCalculator::countProductsText( \Domain\Basket\BasketCalculator::countProducts( $basket ) ), + 'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon ), + 'products_count' => count( $basket ), + 'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [ + 'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ), + 'transport_id' => $basket_transport_method_id + ] ) + ] ); + exit; + } +} diff --git a/autoload/front/controls/class.Site.php b/autoload/front/controls/class.Site.php index e382bbb..6957a7d 100644 --- a/autoload/front/controls/class.Site.php +++ b/autoload/front/controls/class.Site.php @@ -5,30 +5,34 @@ class Site { static public function page_title() { - $class = '\front\controls\\'; + $moduleName = implode( '', array_map( 'ucfirst', explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ) ) ); + $action = \Shared\Helpers\Helpers::get( 'action' ); + $actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) ); - $results = explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ); - if ( is_array( $results ) ) foreach ( $results as $row ) - $class .= ucfirst( $row ); + $controllerClass = '\front\Controllers\\' . $moduleName . 'Controller'; + if ( class_exists( $controllerClass ) and property_exists( $controllerClass, 'title' ) and isset( $controllerClass::$title[$actionCamel] ) ) + return $controllerClass::$title[$actionCamel]; - $property = \Shared\Helpers\Helpers::get( 'action' ); + $class = '\front\controls\\' . $moduleName; if ( class_exists( $class ) and property_exists( new $class, 'page_title' ) ) - return $class::$title[$property]; + return $class::$title[$action]; } static public function title() { global $settings; - $class = '\front\controls\\'; + $moduleName = implode( '', array_map( 'ucfirst', explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ) ) ); + $action = \Shared\Helpers\Helpers::get( 'action' ); + $actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) ); - $results = explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ); - if ( is_array( $results ) ) foreach ( $results as $row ) - $class .= ucfirst( $row ); + $controllerClass = '\front\Controllers\\' . $moduleName . 'Controller'; + if ( class_exists( $controllerClass ) and property_exists( $controllerClass, 'title' ) and isset( $controllerClass::$title[$actionCamel] ) ) + return $controllerClass::$title[$actionCamel] . ' | ' . $settings['firm_name']; - $property = \Shared\Helpers\Helpers::get( 'action' ); + $class = '\front\controls\\' . $moduleName; if ( class_exists( $class ) and property_exists( new $class, 'title' ) ) - return $class::$title[$property] . ' | ' . $settings['firm_name']; + return $class::$title[$action] . ' | ' . $settings['firm_name']; } public static function route( $product = '', $category = '' ) @@ -64,8 +68,9 @@ class Site if ( isset( $controllerFactories[$moduleName] ) and $action ) { $controller = $controllerFactories[$moduleName](); - if ( method_exists( $controller, $action ) ) - return $controller->$action(); + $actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) ); + if ( method_exists( $controller, $actionCamel ) ) + return $controller->$actionCamel(); } // stare klasy @@ -162,6 +167,9 @@ class Site new \Domain\Newsletter\NewsletterRepository( $mdb ) ); }, + 'ShopBasket' => function() { + return new \front\Controllers\ShopBasketController(); + }, ]; } } diff --git a/autoload/front/factory/class.ShopBasket.php b/autoload/front/factory/class.ShopBasket.php deleted file mode 100644 index 4dc507b..0000000 --- a/autoload/front/factory/class.ShopBasket.php +++ /dev/null @@ -1,66 +0,0 @@ -= 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; - } - -} \ No newline at end of file diff --git a/autoload/front/factory/class.ShopOrder.php b/autoload/front/factory/class.ShopOrder.php index 39681cf..9414e84 100644 --- a/autoload/front/factory/class.ShopOrder.php +++ b/autoload/front/factory/class.ShopOrder.php @@ -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() ); diff --git a/autoload/front/factory/class.ShopTransport.php b/autoload/front/factory/class.ShopTransport.php index 994fb67..6f5b3d4 100644 --- a/autoload/front/factory/class.ShopTransport.php +++ b/autoload/front/factory/class.ShopTransport.php @@ -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) { diff --git a/autoload/front/view/class.Site.php b/autoload/front/view/class.Site.php index 113ecc7..7f16e05 100644 --- a/autoload/front/view/class.Site.php +++ b/autoload/front/view/class.Site.php @@ -29,7 +29,7 @@ class Site $scontainersRepo = new \Domain\Scontainers\ScontainersRepository( $GLOBALS['mdb'] ); if ( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) ) - $layout = new \cms\Layout( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) ); + $layout = $layoutsRepo->find( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) ); if ( \Shared\Helpers\Helpers::get( 'article' ) ) $layout = $layoutsRepo->getArticleLayout( (int) \Shared\Helpers\Helpers::get( 'article' ) ); diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 602fea1..743800d 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -4,6 +4,27 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze. --- +## ver. 0.288 (2026-02-17) - BasketCalculator + ShopBasketController + cms\Layout removal + +- **ShopBasket (factory → Domain)** — migracja na Domain + - NOWY: `Domain\Basket\BasketCalculator` — 4 statyczne metody (`summaryWp`, `countProductsText`, `summaryPrice`, `countProducts`) + - USUNIETA: `front\factory\class.ShopBasket.php` — logika przeniesiona do `BasketCalculator` + - UPDATE: 18 callerow w 7 plikach przepietych na `\Domain\Basket\BasketCalculator::` +- **ShopBasket (controls → Controllers)** — migracja kontrolera + - NOWY: `front\Controllers\ShopBasketController` — instancyjny kontroler z camelCase metodami + - Wyekstrahowano `jsonBasketResponse()` — wspolna odpowiedz JSON dla 4 metod koszyka + - Zainicjalizowano zmienne `$values`, `$attributes`, `$custom_fields` w `basketAddProduct()` + - USUNIETA: `front\controls\class.ShopBasket.php` — zastapiona przez `ShopBasketController` + - UPDATE: `front\controls\Site::route()` — konwersja `snake_case → camelCase` w dispatch dla nowych kontrolerow + - UPDATE: `front\controls\Site::title()` / `page_title()` — sprawdzanie `front\Controllers\*Controller` przed fallback + - Zarejestrowany `'ShopBasket'` w `getControllerFactories()` +- **cms\Layout removal** + - USUNIETA: `autoload/cms/class.Layout.php` — caly folder `autoload/cms/` (1 klasa, bug w `__get()`) + - UPDATE: `front\view\Site::show()` — `new \cms\Layout(...)` → `$layoutsRepo->find(...)` +- Testy: 484 OK, 1528 asercji (+8 testow: BasketCalculatorTest) + +--- + ## ver. 0.287 (2026-02-17) - Scontainers + ShopAttribute frontend migration - **Scontainers (frontend)** — migracja na Domain @@ -697,4 +718,4 @@ Logi zmian z migracji na Domain-Driven Architecture. Najnowsze na gorze. - Metoda `clear_product_cache()` w klasie S --- -*Dokument aktualizowany: 2026-02-17* +*Dokument aktualizowany: 2026-02-17 (ver. 0.288)* diff --git a/docs/FRONTEND_REFACTORING_PLAN.md b/docs/FRONTEND_REFACTORING_PLAN.md index 0f0e318..f71cdd8 100644 --- a/docs/FRONTEND_REFACTORING_PLAN.md +++ b/docs/FRONTEND_REFACTORING_PLAN.md @@ -14,7 +14,7 @@ Panel administratora (33 moduły) został w pełni zmigrowany na architekturę D | Klasa | Status | Logika biznesowa | |-------|--------|-----------------| | Site | Router główny | route(), check_url_params(), title() | -| ShopBasket | MIXED | Operacje koszyka, add/remove/quantity, checkout | +| ShopBasket | ZMIGROWANY do `front\Controllers\ShopBasketController` | Operacje koszyka, add/remove/quantity, checkout | | ShopClient | Fasada | Deleguje do factory | | ShopOrder | KRYTYCZNY | Webhooki płatności (tPay, Przelewy24, Hotpay) — bezpośrednie operacje DB | | ShopProduct | Fasada | lazy_loading, warehouse_message, draw_product_attributes | @@ -31,7 +31,7 @@ Panel administratora (33 moduły) został w pełni zmigrowany na architekturę D | ShopCategory | ORYGINALNA LOGIKA | WYSOKI — złożone SQL z language fallback | | Articles | ORYGINALNA LOGIKA | WYSOKI — złożone SQL z language fallback | | ShopPromotion | ORYGINALNA LOGIKA | WYSOKI — silnik promocji (5 typów) | -| ShopBasket | Fasada | ŚREDNI — summary_price, count | +| ShopBasket | ZMIGROWANA do `Domain\Basket\BasketCalculator` — usunięta | — | | ShopTransport | CZĘŚCIOWO zmigrowana | ŚREDNI — transport_methods z filtrowaniem | | ShopPaymentMethod | ZMIGROWANA (Domain) | — | | ShopStatuses | ZMIGROWANA (Domain) | — | @@ -95,7 +95,7 @@ Panel administratora (33 moduły) został w pełni zmigrowany na architekturę D ### cms/ (1 klasa) | Klasa | Status | |-------|--------| -| Layout | BUG w __get() — referuje $this->data które nie istnieje | +| Layout | USUNIETA — zastapiona przez `$layoutsRepo->find()` | ### templates/ (75 plików w 15 modułach) articles(8), banner(2), controls(1), menu(4), newsletter(2), scontainers(1), shop-basket(9), shop-category(6), shop-client(8), shop-coupon(1), shop-order(3), shop-producer(3), shop-product(12), shop-search(3), site(11) @@ -114,7 +114,7 @@ articles(8), banner(2), controls(1), menu(4), newsletter(2), scontainers(1), sho 1. **KRYTYCZNY** `front\factory\ShopClient::login()` — hardcoded password bypass `'Legia1916'` 2. `front\factory\Settings::get_single_settings_value()` — ignoruje `$param`, zawsze zwraca `firm_name` 3. ~~`front\factory\Newsletter::newsletter_unsubscribe()` — błędna składnia SQL w delete~~ **NAPRAWIONE** — `NewsletterRepository::unsubscribe()` z poprawną składnią medoo `delete()` -4. `cms\Layout::__get()` — referuje nieistniejące `$this->data` +4. ~~`cms\Layout::__get()` — referuje nieistniejące `$this->data`~~ **NAPRAWIONE** — klasa usunięta, zastąpiona przez `$layoutsRepo->find()` 5. `shop\Search` — typo w use: `shop\Produt` (brak 'c') --- diff --git a/docs/PROJECT_STRUCTURE.md b/docs/PROJECT_STRUCTURE.md index 9d3a651..3a03fb0 100644 --- a/docs/PROJECT_STRUCTURE.md +++ b/docs/PROJECT_STRUCTURE.md @@ -108,9 +108,9 @@ shopPRO/ │ │ ├── Helpers/ # Helpers (ex class.S.php) │ │ └── Tpl/ # Tpl (silnik szablonow) │ ├── front/ # Klasy frontendu -│ │ ├── Controllers/ # Nowe kontrolery DI (Newsletter) +│ │ ├── Controllers/ # Nowe kontrolery DI (Newsletter, ShopBasket) │ │ ├── Views/ # Nowe widoki (Newsletter, Articles, Languages, Banners, Menu, Scontainers) -│ │ ├── controls/ # Kontrolery legacy (Site, ShopBasket, ...) +│ │ ├── controls/ # Kontrolery legacy (Site, ...) │ │ ├── view/ # Widoki legacy (Site, ...) │ │ └── factory/ # Fabryki/helpery (fasady) │ └── shop/ # Klasy sklepu diff --git a/docs/TESTING.md b/docs/TESTING.md index b28b5e1..b8de6d0 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -36,7 +36,13 @@ Alternatywnie (Git Bash): Ostatnio zweryfikowano: 2026-02-17 ```text -OK (476 tests, 1512 assertions) +OK (484 tests, 1528 assertions) +``` + +Aktualizacja po migracji BasketCalculator + ShopBasketController + cms\Layout removal (2026-02-17, ver. 0.288): +```text +Pelny suite: OK (484 tests, 1528 assertions) +Nowe testy: BasketCalculatorTest (+8: summaryWp, countProducts, countProductsText — singular/plural/cast) ``` Aktualizacja po migracji Scontainers + ShopAttribute frontend (2026-02-17, ver. 0.287): @@ -130,6 +136,7 @@ tests/ | | |-- Article/ArticleRepositoryTest.php | | |-- Attribute/AttributeRepositoryTest.php | | |-- Banner/BannerRepositoryTest.php +| | |-- Basket/BasketCalculatorTest.php | | |-- Cache/CacheRepositoryTest.php | | |-- Coupon/CouponRepositoryTest.php | | |-- Category/CategoryRepositoryTest.php @@ -531,6 +538,16 @@ Nowe testy dodane 2026-02-17: - `tests/Unit/Domain/Layouts/LayoutsRepositoryTest.php` (rozszerzenie: +8 testow frontend: categoryDefaultLayoutId, getDefaultLayout, getProductLayout, getArticleLayout, getCategoryLayout, getActiveLayout) - `tests/Unit/Domain/Pages/PagesRepositoryTest.php` (rozszerzenie: +8 testow frontend: frontPageDetails, frontMainPageId, frontPageSort, frontLangUrl, frontMenuDetails, frontMenuPages) +## Aktualizacja suite (BasketCalculator + ShopBasketController, ver. 0.288) +Ostatnio zweryfikowano: 2026-02-17 + +```text +OK (484 tests, 1528 assertions) +``` + +Nowe testy dodane 2026-02-17: +- `tests/Unit/Domain/Basket/BasketCalculatorTest.php` (8 testow: summaryWp, summaryWpEmpty, countProducts, countProductsEmpty, countProductsTextSingular, countProductsTextPlural2to4, countProductsTextPlural5Plus, countProductsTextCastsToInt) + ## Aktualizacja suite (Scontainers + ShopAttribute frontend, ver. 0.287) Ostatnio zweryfikowano: 2026-02-17 diff --git a/docs/UPDATE_INSTRUCTIONS.md b/docs/UPDATE_INSTRUCTIONS.md index 4fe783e..41e1e53 100644 --- a/docs/UPDATE_INSTRUCTIONS.md +++ b/docs/UPDATE_INSTRUCTIONS.md @@ -18,16 +18,16 @@ Aktualizacje znajdują się w folderze `updates/0.XX/` gdzie XX oznacza dziesią ## Procedura tworzenia nowej aktualizacji -## Status biezacej aktualizacji (ver. 0.287) +## Status biezacej aktualizacji (ver. 0.288) -- Wersja udostepniona: `0.287` (data: 2026-02-17). +- Wersja udostepniona: `0.288` (data: 2026-02-17). - Pliki publikacyjne: - - `updates/0.20/ver_0.287.zip`, `ver_0.287_files.txt` + - `updates/0.20/ver_0.288.zip`, `ver_0.288_files.txt` - Pliki metadanych aktualizacji: - - `updates/changelog.php` (dodany wpis `ver. 0.287`) - - `updates/versions.php` (`$current_ver = 287`) + - `updates/changelog.php` (dodany wpis `ver. 0.288`) + - `updates/versions.php` (`$current_ver = 288`) - Weryfikacja testow przed publikacja: - - `OK (476 tests, 1512 assertions)` + - `OK (484 tests, 1528 assertions)` ### 1. Określ numer wersji Sprawdź ostatnią wersję w `updates/` i zwiększ o 1. diff --git a/templates/shop-basket/basket-mini.php b/templates/shop-basket/basket-mini.php index b23395b..8c01a76 100644 --- a/templates/shop-basket/basket-mini.php +++ b/templates/shop-basket/basket-mini.php @@ -7,7 +7,7 @@