ver. 0.287: Scontainers + ShopAttribute frontend migration to Domain

- Scontainers: frontScontainerDetails() with Redis cache in ScontainersRepository
- Scontainers: new front\Views\Scontainers VIEW, deleted factory + view legacy
- ShopAttribute: frontAttributeDetails(), frontValueDetails() with Redis cache in AttributeRepository
- ShopAttribute: clearFrontCache() per attribute/value + language
- ShopAttribute: deleted front\factory\ShopAttribute, updated 4 callers
- Tests: 476 OK, 1512 assertions (+6 frontend tests)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-17 08:47:21 +01:00
parent e2a821a10c
commit a7e44f23fa
22 changed files with 314 additions and 125 deletions

View File

@@ -0,0 +1,12 @@
<?php
namespace front\Views;
class Scontainers
{
public static function scontainer( $scontainer )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->scontainer = $scontainer;
return $tpl->render( 'scontainers/scontainer' );
}
}

View File

@@ -1,39 +0,0 @@
<?php
namespace front\factory;
class Scontainers
{
public static function scontainer_details($scontainer_id)
{
global $mdb, $lang;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";
$objectData = $cacheHandler->get($cacheKey);
if ($objectData) {
return unserialize($objectData);
}
$repository = new \Domain\Scontainers\ScontainersRepository($mdb);
$langId = (string)($lang[0] ?? 'pl');
$scontainer = $repository->detailsForLanguage((int)$scontainer_id, $langId);
if (!is_array($scontainer)) {
$scontainer = [
'id' => (int)$scontainer_id,
'status' => 0,
'show_title' => 0,
'languages' => [
'lang_id' => $langId,
'title' => '',
'text' => '',
],
];
}
$cacheHandler->set($cacheKey, $scontainer);
return $scontainer;
}
}

View File

@@ -1,51 +0,0 @@
<?php
namespace front\factory;
class ShopAttribute
{
public static function value_details( $value_id, $lang_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopAttribute::value_details:$value_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$value = $mdb -> get( 'pp_shop_attributes_values', '*', [ 'id' => (int)$value_id ] );
$value['language'] = $mdb -> get( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name' ], [ 'AND' => [ 'value_id' => (int)$value_id, 'lang_id' => $lang_id ] ] );
$cacheHandler -> set( $cacheKey, $value );
}
else
{
return unserialize( $objectData );
}
return $value;
}
public static function attribute_details( $attribute_id, $lang_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'attribute_details_' . $attribute_id . '_' . $lang_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$attribute = $mdb -> get( 'pp_shop_attributes', '*', [ 'id' => (int)$attribute_id ] );
$attribute['language'] = $mdb -> get( 'pp_shop_attributes_langs', [ 'lang_id', 'name' ], [ 'AND' => [ 'attribute_id' => (int)$attribute_id, 'lang_id' => $lang_id ] ] );
$cacheHandler->set( $cacheKey, $attribute );
}
else
{
return unserialize( $objectData );
}
return $attribute;
}
}

View File

@@ -162,8 +162,9 @@ class ShopOrder
foreach ( $basket_position[ 'attributes' ] as $row )
{
$row = explode( '-', $row );
$attribute = \front\factory\ShopAttribute::attribute_details( $row[ 0 ], $lang_id );
$value = \front\factory\ShopAttribute::value_details( $row[ 1 ], $lang_id );
$attributeRepo = new \Domain\Attribute\AttributeRepository( $mdb );
$attribute = $attributeRepo->frontAttributeDetails( (int)$row[ 0 ], $lang_id );
$value = $attributeRepo->frontValueDetails( (int)$row[ 1 ], $lang_id );
if ( $attributes )
$attributes .= '<br>';

View File

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class Scontainers
{
public static function scontainer( $id )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl -> scontainer = \front\factory\Scontainers::scontainer_details( $id );
return $tpl -> render( 'scontainers/scontainer' );
}
}

View File

@@ -26,6 +26,7 @@ class Site
$bannerRepo = new \Domain\Banner\BannerRepository( $GLOBALS['mdb'] );
$layoutsRepo = new \Domain\Layouts\LayoutsRepository( $GLOBALS['mdb'] );
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
$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' ) );
@@ -415,7 +416,7 @@ class Site
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
{
$container_list_tmp = explode( ':', $container_list_tmp );
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $html );
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\Views\Scontainers::scontainer( $scontainersRepo->frontScontainerDetails( (int)$container_list_tmp[1], $lang_id ) ), $html );
}
return $html;