ver. 0.294: Remove all 12 legacy autoload/shop/ classes (~2363 lines)

Complete Domain-Driven Architecture migration:
- Phase 1-4: Transport, ProductSet, Coupon, Shop, Search, Basket,
  ProductCustomField, Category, ProductAttribute, Promotion
- Phase 5: Order (~562 lines) + Product (~952 lines)
- ~20 Product methods migrated to ProductRepository
- Apilo sync migrated to OrderAdminService
- Production hotfixes: stale Redis cache (prices 0.00), unqualified
  Product:: refs in LayoutEngine, object->array template conversion
- AttributeRepository::getAttributeValueById() Redis cache added

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 02:05:39 +01:00
parent c72ba388a0
commit e1cb421aaf
74 changed files with 2176 additions and 2669 deletions

View File

@@ -47,7 +47,7 @@ class App
// wyświetlenie pojedynczego produktu
if ( $product )
{
\shop\Product::add_visit( $product -> id );
( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->addVisit( (int)$product['id'] );
return \Shared\Tpl\Tpl::view( 'shop-product/product', [
'product' => $product,
'settings' => $settings,
@@ -76,18 +76,6 @@ class App
// stare klasy
$class = '\front\controls\\' . $moduleName;
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
// klasy sklepowe
$class = '\shop\\';
$results = explode( '_', \Shared\Helpers\Helpers::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$action = \Shared\Helpers\Helpers::get( 'action' );
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
@@ -188,8 +176,10 @@ class App
},
'ShopOrder' => function() {
global $mdb;
$orderRepo = new \Domain\Order\OrderRepository( $mdb );
return new \front\Controllers\ShopOrderController(
new \Domain\Order\OrderRepository( $mdb )
$orderRepo,
new \Domain\Order\OrderAdminService( $orderRepo )
);
},
'ShopProducer' => function() {
@@ -204,6 +194,9 @@ class App
new \Domain\Category\CategoryRepository( $mdb )
);
},
'Search' => function() {
return new \front\Controllers\SearchController();
},
];
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace front\Controllers;
class SearchController
{
public function searchResults()
{
global $lang_id;
$bs = \Shared\Helpers\Helpers::get( 'bs' );
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$results = $productRepo->searchProductsByName( \Shared\Helpers\Helpers::get( 'query' ), $lang_id, (int)$bs );
$out = \Shared\Tpl\Tpl::view( 'shop-search/products', [
'query' => \Shared\Helpers\Helpers::get( 'query' ),
'products' => $results['products']
] );
if ( $results['ls'] > 1 )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> link = 'wyszukiwarka/' . \Shared\Helpers\Helpers::get( 'query' );
$out .= $tpl -> render( 'site/pager' );
}
return $out;
}
public function searchProducts()
{
global $lang_id;
$products = [];
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$results = $productRepo->searchProductByNameAjax( \Shared\Helpers\Helpers::get( 'query' ), $lang_id );
if ( \Shared\Helpers\Helpers::is_array_fix( $results ) ) {
foreach ( $results as $row ) {
$products[] = \Shared\Tpl\Tpl::view( 'shop-search/product-search', [
'product' => $productRepo->findCached( $row['product_id'], $lang_id )
] );
}
}
echo json_encode( $products );
exit;
}
}

View File

@@ -34,7 +34,7 @@ class ShopBasketController
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
@@ -51,11 +51,11 @@ class ShopBasketController
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ]++;
\shop\Basket::check_product_quantity_in_stock( $basket, false );
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
@@ -76,7 +76,7 @@ class ShopBasketController
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
@@ -97,9 +97,9 @@ class ShopBasketController
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\shop\Basket::check_product_quantity_in_stock( $basket, false );
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
@@ -116,7 +116,7 @@ class ShopBasketController
public function basketAddProduct()
{
$basket = \shop\Basket::validate_basket( \Shared\Helpers\Helpers::get_session( 'basket' ) );
$basket = \Domain\Basket\BasketCalculator::validateBasket( \Shared\Helpers\Helpers::get_session( 'basket' ) );
$values_tmp = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
$values = [];
$attributes = [];
@@ -144,7 +144,7 @@ class ShopBasketController
if ( \Shared\Helpers\Helpers::is_array_fix( $attributes ) )
{
$values['parent_id'] = $values[ 'product-id' ];
$values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes );
$values['product-id'] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getProductIdByAttributes( $values[ 'product-id' ], $attributes );
$values['attributes'] = $attributes;
}
@@ -164,7 +164,7 @@ class ShopBasketController
$basket[ $product_code ]['message'] = $values['product-message'];
$basket[ $product_code ]['custom_fields'] = $custom_fields;
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
@@ -174,7 +174,7 @@ class ShopBasketController
'result' => 'ok',
'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'] )
'product_sets' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productSetsWhenAddToBasket( (int)$values['product-id'] )
] );
exit;
}
@@ -261,7 +261,7 @@ class ShopBasketController
{
global $lang_id, $settings;
if ( \shop\Basket::check_product_quantity_in_stock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
@@ -286,7 +286,7 @@ class ShopBasketController
{
$client = \Shared\Helpers\Helpers::get_session( 'client' );
if ( \shop\Basket::check_product_quantity_in_stock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
@@ -357,13 +357,13 @@ class ShopBasketController
$payment_method_id = \Shared\Helpers\Helpers::get_session( 'payment_method_id' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
if ( \shop\Basket::check_product_quantity_in_stock( $basket ) )
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket ) )
{
header( 'Location: /koszyk' );
exit;
}
$basket = \shop\Promotion::find_promotion( $basket );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
return \Shared\Tpl\Tpl::view( 'shop-basket/basket', [
'basket' => $basket,

View File

@@ -140,7 +140,7 @@ class ShopClientController
return \front\Views\ShopClient::clientOrders([
'client' => $client,
'orders' => $this->clientRepo->clientOrders((int)$client['id']),
'statuses' => \shop\Order::order_statuses(),
'statuses' => ( new \Domain\Order\OrderRepository( $GLOBALS['mdb'] ) )->orderStatuses(),
]);
}

View File

@@ -2,14 +2,17 @@
namespace front\Controllers;
use Domain\Order\OrderRepository;
use Domain\Order\OrderAdminService;
class ShopOrderController
{
private $repository;
private $adminService;
public function __construct( OrderRepository $repository )
public function __construct( OrderRepository $repository, OrderAdminService $adminService )
{
$this->repository = $repository;
$this->adminService = $adminService;
}
public function paymentConfirmation()
@@ -30,12 +33,11 @@ class ShopOrderController
if ( \Shared\Helpers\Helpers::get( 'tr_status' ) == 'TRUE' && \Shared\Helpers\Helpers::get( 'tr_crc' ) )
{
$order = new \shop\Order( 0, \Shared\Helpers\Helpers::get( 'tr_crc' ) );
$order = $this->repository->findRawByHash( \Shared\Helpers\Helpers::get( 'tr_crc' ) );
if ( $order->id )
if ( $order && $order['id'] )
{
$order->set_as_paid( true );
$order->update_status( 4, true );
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
echo 'TRUE';
exit;
}
@@ -68,14 +70,13 @@ class ShopOrderController
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
$response = curl_exec( $ch );
$order = new \shop\Order( 0, '', \Shared\Helpers\Helpers::get( 'p24_session_id' ) );
$order = $this->repository->findRawByPrzelewy24Hash( \Shared\Helpers\Helpers::get( 'p24_session_id' ) );
if ( $order['status'] == 0 && $order['summary'] * 100 == \Shared\Helpers\Helpers::get( 'p24_amount' ) )
if ( $order && $order['status'] == 0 && $order['summary'] * 100 == \Shared\Helpers\Helpers::get( 'p24_amount' ) )
{
if ( $order['id'] )
{
$order->set_as_paid( true );
$order->update_status( 4, true );
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
}
}
@@ -88,9 +89,9 @@ class ShopOrderController
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
{
$order = new \shop\Order( $_POST['ID_ZAMOWIENIA'] );
$order = $this->repository->orderDetailsFrontend( (int)$_POST['ID_ZAMOWIENIA'] );
if ( $order['id'] )
if ( $order && $order['id'] )
{
if ( is_array( $order['products'] ) && count( $order['products'] ) ):
$summary_tmp = 0;
@@ -105,21 +106,20 @@ class ShopOrderController
{
if ( $_POST["STATUS"] == "SUCCESS" )
{
$order->set_as_paid( true );
$order->update_status( 4, true );
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone' );
}
else if ( $_POST["STATUS"] == "FAILURE" )
{
$order->update_status( 2, true );
$this->adminService->changeStatus( (int)$order['id'], 2, true );
echo \Shared\Helpers\Helpers::lang( 'platnosc-zostala-odrzucona' );
}
}
else
{
$order->update_status( 3, true );
$this->adminService->changeStatus( (int)$order['id'], 3, true );
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone-reczne' );
}
@@ -136,7 +136,7 @@ class ShopOrderController
$order = $this->repository->orderDetailsFrontend(
$this->repository->findIdByHash( \Shared\Helpers\Helpers::get( 'order_hash' ) )
);
$coupon = (int)$order['coupon_id'] ? new \shop\Coupon( (int)$order['coupon_id'] ) : null;
$coupon = (int)$order['coupon_id'] ? ( new \Domain\Coupon\CouponRepository( $GLOBALS['mdb'] ) )->find( (int)$order['coupon_id'] ) : null;
return \Shared\Tpl\Tpl::view( 'shop-order/order-details', [
'order' => $order,

View File

@@ -24,9 +24,10 @@ class ShopProductController
(int)\Shared\Helpers\Helpers::get( 'offset' )
);
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
$output .= \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => \shop\Product::getFromCache( $product_id, $lang_id )
'product' => $productRepo->findCached( $product_id, $lang_id )
] );
endforeach;
endif;
@@ -48,7 +49,29 @@ class ShopProductController
$attributes[] = $val;
}
$result = \shop\Product::getWarehouseMessage( $values['product-id'], $attributes, $lang_id );
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$permutation = self::getPermutation( $attributes );
$quantity = self::getPermutationQuantity( $values['product-id'], $permutation );
global $settings;
$result = [];
if ( $quantity )
{
$msg = $productRepo->getWarehouseMessageNonzero( (int)$values['product-id'], $lang_id );
if ( $msg )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( isset( $settings[ 'warehouse_message_nonzero_' . $lang_id ] ) && $settings[ 'warehouse_message_nonzero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_nonzero_' . $lang_id ], 'quantity' => $quantity ];
}
else
{
$msg = $productRepo->getWarehouseMessageZero( (int)$values['product-id'], $lang_id );
if ( $msg )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( isset( $settings[ 'warehouse_message_zero_' . $lang_id ] ) && $settings[ 'warehouse_message_zero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_zero_' . $lang_id ], 'quantity' => $quantity ];
}
echo json_encode( $result );
exit;
}
@@ -68,10 +91,26 @@ class ShopProductController
}
$product_id = \Shared\Helpers\Helpers::get( 'product_id' );
$product = \shop\Product::getFromCache( $product_id, $lang_id );
$product_data = $product->getProductDataBySelectedAttributes( $combination );
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$product = $productRepo->findCached( $product_id, $lang_id );
$product_data = $productRepo->getProductDataBySelectedAttributes( $product, $combination );
echo json_encode( [ 'product_data' => $product_data ] );
exit;
}
private static function getPermutation( $attributes )
{
if ( !is_array( $attributes ) || !count( $attributes ) ) return null;
return implode( '|', $attributes );
}
private static function getPermutationQuantity( $productId, $permutation )
{
global $mdb;
if ( !$permutation ) return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
$qty = $mdb->get( 'pp_shop_products', 'quantity', [ 'AND' => [ 'parent_id' => $productId, 'permutation_hash' => $permutation ] ] );
if ( $qty !== null ) return $qty;
return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
}
}

View File

@@ -1,6 +1,5 @@
<?php
namespace front;
use shop\Product;
class LayoutEngine
{
@@ -194,7 +193,7 @@ class LayoutEngine
//
if ( \Shared\Helpers\Helpers::get( 'product' ) )
{
$product = Product::getFromCache( \Shared\Helpers\Helpers::get( 'product' ), $lang_id, $_GET['permutation_hash'] );
$product = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( \Shared\Helpers\Helpers::get( 'product' ), $lang_id, $_GET['permutation_hash'] );
if ( $product['language']['meta_title'] )
$page['language']['title'] = $product['language']['meta_title'];
@@ -243,7 +242,7 @@ class LayoutEngine
$html = str_replace(
'[PRODUKT:' . $single_product[1] . ']',
\Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => \shop\Product::getFromCache( (int)$single_product[1], $lang_id )
'product' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$single_product[1], $lang_id )
] ),
$html
);
@@ -259,7 +258,7 @@ class LayoutEngine
$products_id = explode( ',', $products_box[1] );
foreach ( $products_id as $product_id )
$products[] = Product::getFromCache( (int)$product_id, $lang_id );
$products[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
$html = str_replace(
@@ -288,7 +287,7 @@ class LayoutEngine
$products_id_arr = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->topProductIds( $limit );
foreach ( $products_id_arr as $product_id ){
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
$top_products_arr[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
}
$html = str_replace( $pattern,
@@ -317,7 +316,7 @@ class LayoutEngine
foreach ( $products_id_arr as $product_id ){
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
$top_products_arr[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
}
$html = str_replace( $pattern,
@@ -334,7 +333,7 @@ class LayoutEngine
$html = str_replace( '[META_DESCRIPTION]', $page['language']['meta_description'], $html );
$html = str_replace( '[JEZYKI]', \front\Views\Languages::render( ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->activeLanguages() ), $html );
$html = str_replace( '[TYTUL_STRONY]', self::title( $page['language']['title'], $page['show_title'], $page['language']['page_title'] ), $html );
$html = str_replace( '[WYSZUKIWARKA]', \shop\Search::simple_form(), $html );
$html = str_replace( '[WYSZUKIWARKA]', \front\Views\ShopSearch::simpleForm(), $html );
/* atrybut noindex */
if ( \Shared\Helpers\Helpers::get( 'article' ) )

View File

@@ -0,0 +1,10 @@
<?php
namespace front\Views;
class ShopSearch
{
public static function simpleForm()
{
return \Shared\Tpl\Tpl::view( 'shop-search/simple-form' );
}
}