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:
@@ -191,6 +191,7 @@ class AttributeRepository
|
||||
$this->saveAttributeTranslations($attributeId, $names);
|
||||
|
||||
$this->clearTempAndCache();
|
||||
$this->clearFrontCache($attributeId, 'frontAttributeDetails');
|
||||
return $attributeId;
|
||||
}
|
||||
|
||||
@@ -203,6 +204,7 @@ class AttributeRepository
|
||||
$deleted = (bool)$this->db->delete('pp_shop_attributes', ['id' => $attributeId]);
|
||||
if ($deleted) {
|
||||
$this->clearTempAndCache();
|
||||
$this->clearFrontCache($attributeId, 'frontAttributeDetails');
|
||||
}
|
||||
|
||||
return $deleted;
|
||||
@@ -302,6 +304,7 @@ class AttributeRepository
|
||||
|
||||
$deleteIds = array_diff($currentIds, $incomingIds);
|
||||
foreach ($deleteIds as $deleteId) {
|
||||
$this->clearFrontCache((int)$deleteId, 'frontValueDetails');
|
||||
$this->db->delete('pp_shop_attributes_values_langs', ['value_id' => (int)$deleteId]);
|
||||
$this->db->delete('pp_shop_attributes_values', ['id' => (int)$deleteId]);
|
||||
}
|
||||
@@ -336,6 +339,7 @@ class AttributeRepository
|
||||
$translations = is_array($row['translations'] ?? null) ? $row['translations'] : [];
|
||||
$this->saveValueTranslations($rowId, $translations);
|
||||
$this->refreshCombinationPricesForValue($rowId, $impactOnPrice);
|
||||
$this->clearFrontCache($rowId, 'frontValueDetails');
|
||||
|
||||
if (!empty($row['is_default'])) {
|
||||
$defaultValueId = $rowId;
|
||||
@@ -834,6 +838,91 @@ class AttributeRepository
|
||||
return $this->defaultLangId;
|
||||
}
|
||||
|
||||
// ── Frontend methods ──────────────────────────────────────────
|
||||
|
||||
public function frontAttributeDetails(int $attributeId, string $langId): array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "AttributeRepository::frontAttributeDetails:$attributeId:$langId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$attribute = $this->db->get('pp_shop_attributes', '*', ['id' => (int)$attributeId]);
|
||||
if (!is_array($attribute)) {
|
||||
$attribute = ['id' => $attributeId, 'status' => 0, 'type' => 0];
|
||||
}
|
||||
|
||||
$attribute['language'] = $this->db->get('pp_shop_attributes_langs', ['lang_id', 'name'], [
|
||||
'AND' => [
|
||||
'attribute_id' => (int)$attributeId,
|
||||
'lang_id' => $langId,
|
||||
],
|
||||
]);
|
||||
if (!is_array($attribute['language'])) {
|
||||
$attribute['language'] = ['lang_id' => $langId, 'name' => ''];
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $attribute);
|
||||
return $attribute;
|
||||
}
|
||||
|
||||
public function frontValueDetails(int $valueId, string $langId): array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "AttributeRepository::frontValueDetails:$valueId:$langId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$value = $this->db->get('pp_shop_attributes_values', '*', ['id' => (int)$valueId]);
|
||||
if (!is_array($value)) {
|
||||
$value = ['id' => $valueId];
|
||||
}
|
||||
|
||||
$value['language'] = $this->db->get('pp_shop_attributes_values_langs', ['lang_id', 'name'], [
|
||||
'AND' => [
|
||||
'value_id' => (int)$valueId,
|
||||
'lang_id' => $langId,
|
||||
],
|
||||
]);
|
||||
if (!is_array($value['language'])) {
|
||||
$value['language'] = ['lang_id' => $langId, 'name' => ''];
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
private function clearFrontCache(int $id, string $type): void
|
||||
{
|
||||
if ($id <= 0 || !class_exists('\Shared\Cache\CacheHandler')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$langs = $this->db->select('pp_langs', 'id', ['status' => 1]);
|
||||
if (!is_array($langs)) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($langs as $langId) {
|
||||
$cacheHandler->delete("AttributeRepository::$type:$id:$langId");
|
||||
}
|
||||
}
|
||||
|
||||
private function clearTempAndCache(): void
|
||||
{
|
||||
if (class_exists('\S')) {
|
||||
|
||||
@@ -213,6 +213,41 @@ class ScontainersRepository
|
||||
";
|
||||
}
|
||||
|
||||
// ── Frontend methods ──────────────────────────────────────────
|
||||
|
||||
public function frontScontainerDetails(int $scontainerId, string $langId): array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "ScontainersRepository::frontScontainerDetails:$scontainerId";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
if ($objectData) {
|
||||
$cached = @unserialize($objectData);
|
||||
if (is_array($cached)) {
|
||||
return $cached;
|
||||
}
|
||||
$cacheHandler->delete($cacheKey);
|
||||
}
|
||||
|
||||
$scontainer = $this->detailsForLanguage($scontainerId, $langId);
|
||||
|
||||
if (!is_array($scontainer)) {
|
||||
$scontainer = [
|
||||
'id' => $scontainerId,
|
||||
'status' => 0,
|
||||
'show_title' => 0,
|
||||
'languages' => [
|
||||
'lang_id' => $langId,
|
||||
'title' => '',
|
||||
'text' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $scontainer);
|
||||
return $scontainer;
|
||||
}
|
||||
|
||||
private function clearFrontCache(int $containerId): void
|
||||
{
|
||||
if ($containerId <= 0 || !class_exists('\Shared\Cache\CacheHandler')) {
|
||||
@@ -220,8 +255,7 @@ class ScontainersRepository
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = '\front\factory\Scontainers::scontainer_details:' . $containerId;
|
||||
$cacheHandler->delete($cacheKey);
|
||||
$cacheHandler->delete('ScontainersRepository::frontScontainerDetails:' . $containerId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
12
autoload/front/Views/Scontainers.php
Normal file
12
autoload/front/Views/Scontainers.php
Normal 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' );
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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>';
|
||||
|
||||
@@ -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' );
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user