From 6c87e4615a4b51b354c7f475b4623cbb33b0b17d Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Sun, 15 Feb 2026 15:32:23 +0100 Subject: [PATCH] refactor(shop_category): migrate admin module to Domain+DI with routing and ajax cleanup --- admin/ajax/shop-category.php | 6 +- admin/ajax/shop.php | 6 +- .../categories-list-custom-script.php | 153 ++ .../shop-category/categories-list.php | 112 +- .../category-browse-custom-script.php | 106 ++ .../shop-category/category-browse-list.php | 57 +- .../category-edit-custom-script.php | 53 + .../templates/shop-category/category-edit.php | 63 +- .../category-products-custom-script.php | 62 + .../shop-category/category-products.php | 56 +- .../shop-category/subcategories-list.php | 6 +- .../shop-category/subcategory-browse-list.php | 6 +- admin/templates/shop-product/mass-edit.php | 2 +- admin/templates/shop-product/product-edit.php | 2 +- .../shop-product/subcategories-list.php | 2 +- admin/templates/site/main-layout.php | 2 +- .../Domain/Category/CategoryRepository.php | 422 +++++ .../Controllers/ShopCategoryController.php | 163 ++ .../Controllers/ShopProductController.php | 5 +- autoload/admin/class.Site.php | 8 + .../admin/controls/class.ShopCategory.php | 66 - autoload/admin/controls/class.ShopProduct.php | 2 +- autoload/admin/factory/class.ShopCategory.php | 245 --- autoload/admin/factory/class.ShopProduct.php | 2 +- autoload/admin/view/class.ShopCategory.php | 21 - docs/CHANGELOG.md | 19 + docs/DATABASE_STRUCTURE.md | 36 + docs/PROJECT_STRUCTURE.md | 10 + docs/REFACTORING_PLAN.md | 7 +- docs/TESTING.md | 9 + libraries/grid/config.php | 1 - temp/update_build/delete_files_0.275.txt | 3 + .../tmp_0.275/admin/ajax/shop-category.php | 15 + .../tmp_0.275/admin/ajax/shop.php | 60 + .../categories-list-custom-script.php | 153 ++ .../shop-category/categories-list.php | 61 + .../category-browse-custom-script.php | 106 ++ .../shop-category/category-browse-list.php | 59 + .../category-edit-custom-script.php | 53 + .../templates/shop-category/category-edit.php | 209 +++ .../category-products-custom-script.php | 62 + .../shop-category/category-products.php | 37 + .../shop-category/subcategories-list.php | 36 + .../shop-category/subcategory-browse-list.php | 25 + .../templates/shop-product/mass-edit.php | 114 ++ .../templates/shop-product/product-edit.php | 1348 ++++++++++++++ .../shop-product/subcategories-list.php | 24 + .../admin/templates/site/main-layout.php | 273 +++ .../Controllers/ShopCategoryController.php | 163 ++ .../Controllers/ShopProductController.php | 73 + .../tmp_0.275/autoload/admin/class.Site.php | 493 +++++ .../admin/controls/class.ShopProduct.php | 373 ++++ .../admin/factory/class.ShopProduct.php | 1578 +++++++++++++++++ temp/update_build/tmp_0.275/docs/CHANGELOG.md | 458 +++++ .../tmp_0.275/docs/DATABASE_STRUCTURE.md | 630 +++++++ .../tmp_0.275/docs/PROJECT_STRUCTURE.md | 338 ++++ .../tmp_0.275/docs/REFACTORING_PLAN.md | 297 ++++ temp/update_build/tmp_0.275/docs/TESTING.md | 456 +++++ .../tmp_0.275/libraries/grid/config.php | 48 + .../ShopCategoryControllerTest.php | 80 + temp/update_build/update_0.275.zip | Bin 0 -> 77819 bytes .../Category/CategoryRepositoryTest.php | 208 +++ .../ShopCategoryControllerTest.php | 80 + 63 files changed, 8998 insertions(+), 625 deletions(-) create mode 100644 admin/templates/shop-category/categories-list-custom-script.php create mode 100644 admin/templates/shop-category/category-browse-custom-script.php create mode 100644 admin/templates/shop-category/category-edit-custom-script.php create mode 100644 admin/templates/shop-category/category-products-custom-script.php create mode 100644 autoload/Domain/Category/CategoryRepository.php create mode 100644 autoload/admin/Controllers/ShopCategoryController.php delete mode 100644 autoload/admin/controls/class.ShopCategory.php delete mode 100644 autoload/admin/factory/class.ShopCategory.php delete mode 100644 autoload/admin/view/class.ShopCategory.php create mode 100644 temp/update_build/delete_files_0.275.txt create mode 100644 temp/update_build/tmp_0.275/admin/ajax/shop-category.php create mode 100644 temp/update_build/tmp_0.275/admin/ajax/shop.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/categories-list-custom-script.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/categories-list.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-browse-custom-script.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-browse-list.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-edit-custom-script.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-edit.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-products-custom-script.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/category-products.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/subcategories-list.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-category/subcategory-browse-list.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-product/mass-edit.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-product/product-edit.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/shop-product/subcategories-list.php create mode 100644 temp/update_build/tmp_0.275/admin/templates/site/main-layout.php create mode 100644 temp/update_build/tmp_0.275/autoload/admin/Controllers/ShopCategoryController.php create mode 100644 temp/update_build/tmp_0.275/autoload/admin/Controllers/ShopProductController.php create mode 100644 temp/update_build/tmp_0.275/autoload/admin/class.Site.php create mode 100644 temp/update_build/tmp_0.275/autoload/admin/controls/class.ShopProduct.php create mode 100644 temp/update_build/tmp_0.275/autoload/admin/factory/class.ShopProduct.php create mode 100644 temp/update_build/tmp_0.275/docs/CHANGELOG.md create mode 100644 temp/update_build/tmp_0.275/docs/DATABASE_STRUCTURE.md create mode 100644 temp/update_build/tmp_0.275/docs/PROJECT_STRUCTURE.md create mode 100644 temp/update_build/tmp_0.275/docs/REFACTORING_PLAN.md create mode 100644 temp/update_build/tmp_0.275/docs/TESTING.md create mode 100644 temp/update_build/tmp_0.275/libraries/grid/config.php create mode 100644 temp/update_build/tmp_0.275/tests/Unit/admin/Controllers/ShopCategoryControllerTest.php create mode 100644 temp/update_build/update_0.275.zip create mode 100644 tests/Unit/Domain/Category/CategoryRepositoryTest.php create mode 100644 tests/Unit/admin/Controllers/ShopCategoryControllerTest.php diff --git a/admin/ajax/shop-category.php b/admin/ajax/shop-category.php index df6f00e..a16c6b6 100644 --- a/admin/ajax/shop-category.php +++ b/admin/ajax/shop-category.php @@ -4,8 +4,10 @@ $a = \S::get( 'a' ); if ( $a == 'save_products_order' ) { $response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kolejności wyświetlania produktów wystąpił błąd. Proszę spróbować ponownie.' ]; - - if ( \admin\factory\ShopCategory::save_product_order( \S::get( 'category_id' ), \S::get( 'products' ) ) ) + + $categoryRepository = new \Domain\Category\CategoryRepository( $mdb ); + + if ( $categoryRepository->saveProductOrder( \S::get( 'category_id' ), \S::get( 'products' ) ) ) $response = [ 'status' => 'ok' ]; echo json_encode( $response ); diff --git a/admin/ajax/shop.php b/admin/ajax/shop.php index 899f611..48af10e 100644 --- a/admin/ajax/shop.php +++ b/admin/ajax/shop.php @@ -16,8 +16,10 @@ if ( $a == 'cookie_categories' ) if ( $a == 'save_categories_order' ) { $response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania kolejności kategorii wystąpił błąd. Proszę spróbować ponownie.' ]; - - if ( \admin\factory\ShopCategory::save_categories_order( \S::get( 'categories' ) ) ) + + $categoryRepository = new \Domain\Category\CategoryRepository( $mdb ); + + if ( $categoryRepository->saveCategoriesOrder( \S::get( 'categories' ) ) ) $response = [ 'status' => 'ok' ]; echo json_encode( $response ); diff --git a/admin/templates/shop-category/categories-list-custom-script.php b/admin/templates/shop-category/categories-list-custom-script.php new file mode 100644 index 0000000..16b4953 --- /dev/null +++ b/admin/templates/shop-category/categories-list-custom-script.php @@ -0,0 +1,153 @@ + + + diff --git a/admin/templates/shop-category/categories-list.php b/admin/templates/shop-category/categories-list.php index 3c32e80..3a4ef4c 100644 --- a/admin/templates/shop-category/categories-list.php +++ b/admin/templates/shop-category/categories-list.php @@ -8,7 +8,9 @@ ob_start(); categories ) ): foreach ( $this -> categories as $category ):?>
  • - + ';?> dlang]['title'];?>
    @@ -27,7 +29,7 @@ ob_start();
    \admin\factory\ShopCategory::subcategories( $category['id'] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category['id'] ), 'level' => $this -> level + 1, 'dlang' => $this -> dlang ] );?> @@ -56,108 +58,4 @@ $grid -> external_code = $out; echo $grid -> draw(); ?> - - \ No newline at end of file + \ No newline at end of file diff --git a/admin/templates/shop-category/category-browse-custom-script.php b/admin/templates/shop-category/category-browse-custom-script.php new file mode 100644 index 0000000..a27a2e0 --- /dev/null +++ b/admin/templates/shop-category/category-browse-custom-script.php @@ -0,0 +1,106 @@ + + + diff --git a/admin/templates/shop-category/category-browse-list.php b/admin/templates/shop-category/category-browse-list.php index dff8aa9..0ad148f 100644 --- a/admin/templates/shop-category/category-browse-list.php +++ b/admin/templates/shop-category/category-browse-list.php @@ -7,7 +7,9 @@ ob_start(); categories ) ): foreach ( $this -> categories as $category ):?>
  • - + ';?> dlang]['title'];?>
    @@ -17,7 +19,7 @@ ob_start();
    \admin\factory\ShopCategory::subcategories( $category['id'] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category['id'] ), 'level' => $this -> level + 1, 'dlang' => $this -> dlang ] );?> @@ -54,53 +56,4 @@ echo $grid -> draw(); float: none; } - - \ No newline at end of file + \ No newline at end of file diff --git a/admin/templates/shop-category/category-edit-custom-script.php b/admin/templates/shop-category/category-edit-custom-script.php new file mode 100644 index 0000000..bd2a72d --- /dev/null +++ b/admin/templates/shop-category/category-edit-custom-script.php @@ -0,0 +1,53 @@ + diff --git a/admin/templates/shop-category/category-edit.php b/admin/templates/shop-category/category-edit.php index 9ef6831..9053b6c 100644 --- a/admin/templates/shop-category/category-edit.php +++ b/admin/templates/shop-category/category-edit.php @@ -1,64 +1,5 @@ - 'Sortowanie produktĂłw', 'name' => 'sort_type', 'id' => 'sort_type', - 'values' => \admin\factory\ShopCategory::$_sort_types, + 'values' => is_array( $this -> sort_types ) ? $this -> sort_types : [], 'value' => $this -> category['sort_type'] ] );?> @@ -264,3 +205,5 @@ $grid -> id_param = 'id'; echo $grid -> draw(); ?> + + diff --git a/admin/templates/shop-category/category-products-custom-script.php b/admin/templates/shop-category/category-products-custom-script.php new file mode 100644 index 0000000..3a43fa0 --- /dev/null +++ b/admin/templates/shop-category/category-products-custom-script.php @@ -0,0 +1,62 @@ + + + diff --git a/admin/templates/shop-category/category-products.php b/admin/templates/shop-category/category-products.php index 29d4d8f..7885fd8 100644 --- a/admin/templates/shop-category/category-products.php +++ b/admin/templates/shop-category/category-products.php @@ -9,7 +9,7 @@ ob_start(); { ?>
  • -
    +
  • buttons = [ ]; echo $grid -> draw(); ?> - - \ No newline at end of file + $this -> category_id ] ); ?> \ No newline at end of file diff --git a/admin/templates/shop-category/subcategories-list.php b/admin/templates/shop-category/subcategories-list.php index 24b09d5..739fe25 100644 --- a/admin/templates/shop-category/subcategories-list.php +++ b/admin/templates/shop-category/subcategories-list.php @@ -3,7 +3,9 @@ categories as $category ):?>
  • - + ';?> dlang]['title'];?>
    @@ -24,7 +26,7 @@
    \admin\factory\ShopCategory::subcategories( $category['id'] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category['id'] ), 'level' => $this -> level + 1, 'dlang' => $this -> dlang ] );?> diff --git a/admin/templates/shop-category/subcategory-browse-list.php b/admin/templates/shop-category/subcategory-browse-list.php index 7218ed7..1fafb54 100644 --- a/admin/templates/shop-category/subcategory-browse-list.php +++ b/admin/templates/shop-category/subcategory-browse-list.php @@ -3,7 +3,9 @@ categories as $category ):?>
  • - + ';?> dlang]['title'];?>
    @@ -13,7 +15,7 @@
    \admin\factory\ShopCategory::subcategories( $category['id'] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category['id'] ), 'level' => $this -> level + 1, 'dlang' => $this -> dlang ] );?> diff --git a/admin/templates/shop-product/mass-edit.php b/admin/templates/shop-product/mass-edit.php index 5ed732e..0823132 100644 --- a/admin/templates/shop-product/mass-edit.php +++ b/admin/templates/shop-product/mass-edit.php @@ -97,7 +97,7 @@ dlang]['title']; ?> \admin\factory\ShopCategory::subcategories( $category['id'] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category['id'] ), 'level' => ($this->level ?? 0) + 1, 'dlang' => $this->dlang, 'name' => 'mass_categories[]' diff --git a/admin/templates/shop-product/product-edit.php b/admin/templates/shop-product/product-edit.php index cb36693..8d1519c 100644 --- a/admin/templates/shop-product/product-edit.php +++ b/admin/templates/shop-product/product-edit.php @@ -511,7 +511,7 @@ ob_start(); \admin\factory\ShopCategory::subcategories($category['id']), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories($category['id']), 'product_categories' => $this->product['categories'], 'dlang' => $this->dlang ]); diff --git a/admin/templates/shop-product/subcategories-list.php b/admin/templates/shop-product/subcategories-list.php index 9037323..5c7f796 100644 --- a/admin/templates/shop-product/subcategories-list.php +++ b/admin/templates/shop-product/subcategories-list.php @@ -12,7 +12,7 @@ \admin\factory\ShopCategory::subcategories( $category[ 'id' ] ), + 'categories' => ( new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ) )->subcategories( $category[ 'id' ] ), 'product_categories' => $this -> product_categories, 'dlang' => $this -> dlang, 'name' => $this -> name diff --git a/admin/templates/site/main-layout.php b/admin/templates/site/main-layout.php index c8f92f0..e090e08 100644 --- a/admin/templates/site/main-layout.php +++ b/admin/templates/site/main-layout.php @@ -56,7 +56,7 @@