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 8162df7356
commit 3b50ba7990
22 changed files with 314 additions and 125 deletions

View File

@@ -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')) {