ver. 0.282: Banners frontend migration, Cache cleanup, Shared\Cache namespace

- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods,
  front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners
- Cache cleanup: eliminacja legacy class.Cache.php (file-based cache),
  13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler
- Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\,
  60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych,
  usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php
- Naprawione rozbieżności kluczy cache (random_products, category_name)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-16 21:25:50 +01:00
parent fb81c54e06
commit 285cbe5515
54 changed files with 594 additions and 346 deletions

View File

@@ -874,7 +874,7 @@ class ArticleRepository
*/
public function articleDetailsFrontend(int $articleId, string $langId): ?array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::articleDetailsFrontend:{$articleId}:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
@@ -946,7 +946,7 @@ class ArticleRepository
default: $order = 'id ASC'; break;
}
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::articlesIds:{$pageId}:{$langId}:{$limit}:{$sortType}:{$from}:{$order}";
$objectData = $cacheHandler->get($cacheKey);
@@ -994,7 +994,7 @@ class ArticleRepository
*/
public function pageArticlesCount(int $pageId, string $langId): int
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::pageArticlesCount:{$pageId}:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
@@ -1084,7 +1084,7 @@ class ArticleRepository
*/
public function articleNoindex(int $articleId, string $langId): bool
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::articleNoindex:{$articleId}:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
@@ -1107,7 +1107,7 @@ class ArticleRepository
*/
public function topArticles(int $pageId, int $limit, string $langId): ?array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::topArticles:{$pageId}:{$limit}:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
@@ -1156,7 +1156,7 @@ class ArticleRepository
*/
public function newsListArticles(int $pageId, int $limit, string $langId): ?array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "ArticleRepository::newsListArticles:{$pageId}:{$limit}:{$langId}";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -312,4 +312,84 @@ class BannerRepository
$this->db->insert('pp_banners_langs', $translationData);
}
// ─── Frontend methods ───────────────────────────────────────────
/**
* Pobiera aktywne banery (home_page = 0) z filtrowaniem dat, z Redis cache.
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = płaski wiersz.
*/
public function banners(string $langId): ?array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "BannerRepository::banners:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
if ($objectData) {
return unserialize($objectData);
}
$today = date('Y-m-d');
$results = $this->db->query(
"SELECT id, name FROM pp_banners "
. "WHERE status = 1 "
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
. "AND home_page = 0"
)->fetchAll();
$banners = null;
if (is_array($results) && !empty($results)) {
foreach ($results as $row) {
$row['languages'] = $this->db->get('pp_banners_langs', '*', [
'AND' => ['id_banner' => (int)$row['id'], 'id_lang' => $langId]
]);
$banners[] = $row;
}
}
$cacheHandler->set($cacheKey, $banners);
return $banners;
}
/**
* Pobiera glowny baner (home_page = 1) z filtrowaniem dat, z Redis cache.
* Zwraca dane w formacie zgodnym z szablonami: $banner['languages'] = plaski wiersz.
*/
public function mainBanner(string $langId): ?array
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "BannerRepository::mainBanner:{$langId}";
$objectData = $cacheHandler->get($cacheKey);
if ($objectData) {
return unserialize($objectData);
}
$today = date('Y-m-d');
$results = $this->db->query(
"SELECT * FROM pp_banners "
. "WHERE status = 1 "
. "AND (date_start <= '{$today}' OR date_start IS NULL) "
. "AND (date_end >= '{$today}' OR date_end IS NULL) "
. "AND home_page = 1 "
. "ORDER BY date_end ASC "
. "LIMIT 1"
)->fetchAll();
$banner = null;
if (is_array($results) && !empty($results)) {
$banner = $results[0];
$banner['languages'] = $this->db->get('pp_banners_langs', '*', [
'AND' => ['id_banner' => (int)$banner['id'], 'id_lang' => $langId]
]);
}
$cacheHandler->set($cacheKey, $banner);
return $banner;
}
}

View File

@@ -14,11 +14,11 @@ class CacheRepository
private $basePath;
/**
* @param \RedisConnection $redisConnection Połączenie z Redis (nullable)
* @param \Shared\Cache\RedisConnection $redisConnection Połączenie z Redis (nullable)
* @param string $basePath Ścieżka bazowa do katalogów cache
*/
public function __construct(
?\RedisConnection $redisConnection = null,
?\Shared\Cache\RedisConnection $redisConnection = null,
string $basePath = '../'
) {
$this->redisConnection = $redisConnection;

View File

@@ -13,7 +13,7 @@ class DashboardRepository
public function summaryOrders(): int
{
try {
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
if ( $redis ) {
$cached = $redis->get( 'summary_ordersd' );
if ( $cached !== false ) {
@@ -33,7 +33,7 @@ class DashboardRepository
public function summarySales(): float
{
try {
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
if ( $redis ) {
$cached = $redis->get( 'summary_salesd' );
if ( $cached !== false ) {

View File

@@ -256,19 +256,17 @@ class DictionariesRepository
private function cacheFetch(string $key)
{
if (!class_exists('\Cache') || !method_exists('\Cache', 'fetch')) {
return false;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cached = $cacheHandler->get(self::CACHE_SUBDIR . ':' . $key);
if ($cached) {
return unserialize($cached);
}
return \Cache::fetch($key, self::CACHE_SUBDIR);
return false;
}
private function cacheStore(string $key, string $value): void
{
if (!class_exists('\Cache') || !method_exists('\Cache', 'store')) {
return;
}
\Cache::store($key, $value, self::CACHE_TTL, self::CACHE_SUBDIR);
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheHandler->set(self::CACHE_SUBDIR . ':' . $key, $value, self::CACHE_TTL);
}
}

View File

@@ -337,7 +337,7 @@ class LanguagesRepository
*/
public function defaultLanguage(): string
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'Domain\Languages\LanguagesRepository::defaultLanguage';
$objectData = $cacheHandler->get($cacheKey);
@@ -361,7 +361,7 @@ class LanguagesRepository
*/
public function activeLanguages(): array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'Domain\Languages\LanguagesRepository::activeLanguages';
$objectData = $cacheHandler->get($cacheKey);
@@ -389,7 +389,7 @@ class LanguagesRepository
*/
public function translations(string $language = 'pl'): array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "Domain\Languages\LanguagesRepository::translations:$language";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -297,12 +297,12 @@ class LayoutsRepository
private function clearFrontLayoutsCache(): void
{
if (!class_exists('\CacheHandler')) {
if (!class_exists('\Shared\Cache\CacheHandler')) {
return;
}
try {
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
if (method_exists($cacheHandler, 'deletePattern')) {
$cacheHandler->deletePattern('*Layouts::*');
}

View File

@@ -639,7 +639,7 @@ class ProductRepository
\S::delete_dir( '../thumbs/' );
if ( !$isNew ) {
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
if ( $redis ) {
$redis->flushAll();
}

View File

@@ -406,12 +406,12 @@ class PromotionRepository
private function invalidateActivePromotionsCache(): void
{
if (!class_exists('\CacheHandler')) {
if (!class_exists('\Shared\Cache\CacheHandler')) {
return;
}
try {
$cache = new \CacheHandler();
$cache = new \Shared\Cache\CacheHandler();
if (method_exists($cache, 'delete')) {
$cache->delete('\shop\Promotion::get_active_promotions');
}

View File

@@ -215,11 +215,11 @@ class ScontainersRepository
private function clearFrontCache(int $containerId): void
{
if ($containerId <= 0 || !class_exists('\CacheHandler')) {
if ($containerId <= 0 || !class_exists('\Shared\Cache\CacheHandler')) {
return;
}
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = '\front\factory\Scontainers::scontainer_details:' . $containerId;
$cacheHandler->delete($cacheKey);
}

View File

@@ -148,7 +148,7 @@ class SettingsRepository
*/
public function allSettings(bool $skipCache = false): array
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'Domain\Settings\SettingsRepository::allSettings';
if (!$skipCache) {
@@ -177,7 +177,7 @@ class SettingsRepository
*/
public function getSingleValue(string $param): string
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "Domain\Settings\SettingsRepository::getSingleValue:$param";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -1,4 +1,6 @@
<?
<?php
namespace Shared\Cache;
class CacheHandler
{
protected $redis;
@@ -7,7 +9,7 @@ class CacheHandler
{
if (class_exists('Redis')) {
try {
$this->redis = \RedisConnection::getInstance()->getConnection();
$this->redis = RedisConnection::getInstance()->getConnection();
} catch (\Exception $e) {
$this->redis = null;
}
@@ -22,7 +24,7 @@ class CacheHandler
return null;
}
public function set($key, $value, $ttl = 86400) // 86400 = 60 * 60 * 24 (1 dzień)
public function set($key, $value, $ttl = 86400)
{
if ($this->redis) {
$this->redis->setex($key, $ttl, serialize($value));

View File

@@ -0,0 +1,45 @@
<?php
namespace Shared\Cache;
class RedisConnection
{
private static $instance = null;
private $redis;
private function __construct()
{
global $config;
$this->redis = new \Redis();
try {
if (!$this->redis->connect($config['redis']['host'], $config['redis']['port'])) {
error_log("Nie udalo sie polaczyc z serwerem Redis.");
$this->redis = null;
return;
}
if (!$this->redis->auth($config['redis']['password'])) {
error_log("Autoryzacja do serwera Redis nie powiodla sie.");
$this->redis = null;
return;
}
} catch (\Exception $e) {
error_log("Blad podczas polaczenia z Redis: " . $e->getMessage());
$this->redis = null;
}
}
public static function getInstance()
{
if (self::$instance === null) {
self::$instance = new self();
}
return self::$instance;
}
public function getConnection()
{
return $this->redis;
}
}

View File

@@ -33,7 +33,7 @@ class SettingsController
\S::delete_dir('../temp/');
\S::delete_dir('../thumbs/');
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
if ($redis) {
$redis->flushAll();
}
@@ -54,7 +54,7 @@ class SettingsController
\S::delete_dir('../temp/');
\S::delete_dir('../thumbs/');
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
if ($redis) {
$redis->flushAll();
}

View File

@@ -1,57 +0,0 @@
<?php
class Cache
{
public static function store( $key, $data, $ttl = 86400, $subdir = '' )
{
if ( defined( 'SP_CACHE' ) and constant( "SP_CACHE" ) == false ) {
return false;
}
file_put_contents( self::get_file_name( $key, $subdir ), base64_encode( serialize( array( time() + $ttl, $data ) ) ) );
}
private static function get_file_name( $key, $subdir )
{
$md5 = md5( $key );
if ( $subdir )
$dir = 'temp/' . $subdir . '/' . $md5[0] . '/';
else
$dir = 'temp/' . $md5[0] . '/';
if ( !is_dir( $dir ) )
mkdir( $dir , 0755 , true );
return $dir . 's_cache_' . $md5;
}
static public function fetch( $key, $subdir = '' )
{
global $config;
if ( !$config['cache'] )
return false;
$filename = self::get_file_name( $key );
if ( !file_exists( $filename ) || !is_readable( $filename ) )
return false;
$data = base64_decode( file_get_contents( $filename ) );
$data = @unserialize( $data );
if ( !$data )
{
unlink( $filename );
return false;
}
if ( time() > $data[0] )
{
if ( file_exists( $filename ) )
unlink( $filename );
return false;
}
return $data[1];
}
}
?>

View File

@@ -1,53 +0,0 @@
<?php
class RedisConnection
{
private static $instance = null;
private $redis;
private function __construct()
{
global $config;
$this->redis = new \Redis();
try
{
// Próba połączenia z serwerem Redis
if (!$this->redis->connect($config['redis']['host'], $config['redis']['port']))
{
// Logowanie błędu bez rzucania wyjątku
error_log("Nie udało się połączyć z serwerem Redis.");
$this->redis = null;
return;
}
// Próba autoryzacji
if (!$this->redis->auth($config['redis']['password']))
{
error_log("Autoryzacja do serwera Redis nie powiodła się.");
$this->redis = null;
return;
}
}
catch (\Exception $e)
{
// Obsługa wyjątków, bez rzucania błędu
error_log("Błąd podczas połączenia z Redis: " . $e->getMessage());
$this->redis = null;
}
}
public static function getInstance()
{
if (self::$instance === null)
{
self::$instance = new self();
}
return self::$instance;
}
public function getConnection()
{
return $this->redis;
}
}

View File

@@ -105,7 +105,7 @@ class S
static public function clear_redis_cache()
{
$redis = \RedisConnection::getInstance() -> getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance() -> getConnection();
$redis -> flushAll();
}
@@ -115,7 +115,7 @@ class S
{
try
{
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
// Wyczyść cache produktu dla wszystkich języków i permutacji
$cacheHandler -> deletePattern( "shop\\product:$product_id:*" );
// Wyczyść cache związane z opcjami ilościowymi

View File

@@ -0,0 +1,21 @@
<?php
namespace front\Views;
class Banners
{
public static function banners($banners)
{
$tpl = new \Tpl;
$tpl->banners = $banners;
return $tpl->render('banner/banners');
}
public static function mainBanner($banner)
{
if (!\S::get_session('banner_close') && is_array($banner)) {
$tpl = new \Tpl;
$tpl->banner = $banner;
return $tpl->render('banner/main-banner');
}
}
}

View File

@@ -403,7 +403,7 @@ class ShopBasket
\S::set_session( 'google-analytics-purchase', true );
\S::set_session( 'ekomi-purchase', true );
$redis = \RedisConnection::getInstance() -> getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance() -> getConnection();
if ( $redis )
$redis -> flushAll();

View File

@@ -1,73 +0,0 @@
<?php
namespace front\factory;
class Banners
{
public static function banners()
{
global $mdb, $lang;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Banners::banners";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id, name FROM pp_banners WHERE status = 1 AND ( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) AND ( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) AND home_page = 0' ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
{
$row['languages'] = $mdb -> get( 'pp_banners_langs', '*', [ 'AND' => [ 'id_banner' => (int)$row['id'], 'id_lang' => $lang[0] ] ] );
$banners[] = $row;
}
$cacheHandler -> set( $cacheKey, $banners );
}
else
{
return unserialize($objectData);
}
return $banners;
}
public static function main_banner()
{
global $mdb, $lang_id;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Banners::main_banner:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$banner = $mdb -> query( 'SELECT '
. '* '
. 'FROM '
. 'pp_banners '
. 'WHERE '
. 'status = 1 '
. 'AND '
. '( date_start <= \'' . date( 'Y-m-d' ) . '\' OR date_start IS NULL ) '
. 'AND '
. '( date_end >= \'' . date( 'Y-m-d' ) . '\' OR date_end IS NULL ) '
. 'AND '
. 'home_page = 1 '
. 'ORDER BY '
. 'date_end ASC '
. 'LIMIT 1' ) -> fetchAll();
$banner = $banner[0];
if ( $banner )
$banner['languages'] = $mdb -> get( 'pp_banners_langs', '*', [ 'AND' => [ 'id_banner' => (int)$banner['id'], 'id_lang' => $lang_id ] ] );
$cacheHandler -> set( $cacheKey, $banner );
}
else
{
return unserialize( $objectData );
}
return $banner;
}
}

View File

@@ -12,7 +12,7 @@ class Layouts
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::default_layout";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -35,7 +35,7 @@ class Layouts
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::product_layout:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -87,7 +87,7 @@ class Layouts
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::article_layout:$article_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -110,7 +110,7 @@ class Layouts
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::category_layout:$category_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -148,7 +148,7 @@ class Layouts
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Layouts::active_layout:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );

View File

@@ -7,7 +7,7 @@ class Menu
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Menu::menu_details:$menu_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -31,7 +31,7 @@ class Menu
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Menu::menu_pages:$menu_id:$parent_id";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -7,7 +7,7 @@ class Pages
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::page_sort:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -48,7 +48,7 @@ class Pages
if ( $lang_tmp )
$lang_id = $lang_tmp;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::page_details:$id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
@@ -69,7 +69,7 @@ class Pages
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Pages::main_page_id";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -7,7 +7,7 @@ class Scontainers
{
global $mdb, $lang;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -7,7 +7,7 @@ class ShopAttribute
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopAttribute::value_details:$value_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -31,12 +31,20 @@ class ShopAttribute
{
global $mdb;
if ( !$attribute = \Cache::fetch( 'attribute_details_' . $attribute_id . '_' . $lang_id ) )
$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 ] ] );
\Cache::store( 'attribute_details_' . $attribute_id . '_' . $lang_id, $attribute );
$cacheHandler->set( $cacheKey, $attribute );
}
else
{
return unserialize( $objectData );
}
return $attribute;
}

View File

@@ -6,10 +6,18 @@ class ShopCategory
{
global $mdb;
if ( !$category_sort = \Cache::fetch( "get_category_sort:$category_id" ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "get_category_sort:$category_id";
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$category_sort = $mdb -> get( 'pp_shop_categories', 'sort_type', [ 'id' => $category_id ] );
\Cache::store( "get_category_sort:$category_id", $category_sort );
$cacheHandler->set( $cacheKey, $category_sort );
}
else
{
return unserialize( $objectData );
}
return $category_sort;
@@ -19,11 +27,19 @@ class ShopCategory
{
global $mdb, $lang_id;
if ( !$category_name = \Cache::fetch( 'category_name' . $lang_id . '_' . $category_id . 'tmp' ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'category_name' . $lang_id . '_' . $category_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$category_name = $mdb -> get( 'pp_shop_categories_langs', 'title', [ 'AND' => [ 'category_id' => (int)$category_id, 'lang_id' => $lang_id ] ] );
\Cache::store( 'category_name' . $lang_id . '_' . $category_id, $category_name );
$cacheHandler->set( $cacheKey, $category_name );
}
else
{
return unserialize( $objectData );
}
return $category_name;
@@ -45,7 +61,7 @@ class ShopCategory
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopCategory::blog_category_products:$category_id:$lang_id:$limit";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -95,7 +111,7 @@ class ShopCategory
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopCategory::category_products_count:$category_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -166,7 +182,7 @@ class ShopCategory
break;
endswitch;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopCategory::products_id:$category_id:$sort_type:$lang_id:$products_limit:$from:$order";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -245,7 +261,7 @@ class ShopCategory
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopCategory::categories_details:$parent_id";
$objectData = $cacheHandler->get($cacheKey);
@@ -275,7 +291,7 @@ class ShopCategory
{
global $mdb, $lang_id;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopCategory::category_details:$category_id";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -17,15 +17,16 @@ class ShopPaymentMethod
public static function payment_methods_by_transport( $transport_method_id )
{
$transport_method_id = (int)$transport_method_id;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods_by_transport' . $transport_method_id;
$payments = \Cache::fetch( $cacheKey );
$objectData = $cacheHandler->get( $cacheKey );
if ( $payments !== false && is_array( $payments ) ) {
return $payments;
if ( $objectData ) {
return unserialize( $objectData );
}
$payments = self::repo()->forTransport( $transport_method_id );
\Cache::store( $cacheKey, $payments );
$cacheHandler->set( $cacheKey, $payments );
return $payments;
}
@@ -38,12 +39,18 @@ class ShopPaymentMethod
public static function payment_method( $payment_method_id )
{
$payment_method_id = (int)$payment_method_id;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_method' . $payment_method_id;
$payment_method = \Cache::fetch( $cacheKey );
$objectData = $cacheHandler->get( $cacheKey );
if ( $payment_method === false ) {
if ( !$objectData )
{
$payment_method = self::repo()->findActiveById( $payment_method_id );
\Cache::store( $cacheKey, $payment_method );
$cacheHandler->set( $cacheKey, $payment_method );
}
else
{
return unserialize( $objectData );
}
return $payment_method;
@@ -51,15 +58,16 @@ class ShopPaymentMethod
public static function payment_methods()
{
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'payment_methods';
$payment_methods = \Cache::fetch( $cacheKey );
$objectData = $cacheHandler->get( $cacheKey );
if ( $payment_methods !== false && is_array( $payment_methods ) ) {
return $payment_methods;
if ( $objectData ) {
return unserialize( $objectData );
}
$payment_methods = self::repo()->allActive();
\Cache::store( $cacheKey, $payment_methods );
$cacheHandler->set( $cacheKey, $payment_methods );
return $payment_methods;
}

View File

@@ -47,7 +47,7 @@ class ShopProduct
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::is_product_active:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -85,10 +85,18 @@ class ShopProduct
{
global $mdb;
if ( !$price = \Cache::fetch( 'get_minimal_price:' . $id_product ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'get_minimal_price:' . $id_product;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$price = $mdb -> min( 'pp_shop_product_price_history', 'price', [ 'AND' => [ 'id_product' => $id_product, 'price[!]' => str_replace( ',', '.', $price_brutto_promo ) ] ] );
\Cache::store( 'get_minimal_price:' . $id_product, $price );
$cacheHandler->set( $cacheKey, $price );
}
else
{
return unserialize( $objectData );
}
return $price;
@@ -108,11 +116,19 @@ class ShopProduct
{
global $mdb, $lang_id;
if ( !$product_name = \Cache::fetch( 'product_name' . $lang_id . '_' . $product_id ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_name' . $lang_id . '_' . $product_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$product_name = $mdb -> get( 'pp_shop_products_langs', 'name', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $lang_id ] ] );
\Cache::store( 'product_name' . $lang_id . '_' . $product_id, $product_name );
$cacheHandler->set( $cacheKey, $product_name );
}
else
{
return unserialize( $objectData );
}
return $product_name;
@@ -122,12 +138,20 @@ class ShopProduct
{
global $mdb;
if ( !$product_image = \Cache::fetch( 'product_image:' . $product_id ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'product_image:' . $product_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT src FROM pp_shop_products_images WHERE product_id = :product_id ORDER BY o ASC LIMIT 1', [ ':product_id' => (int)$product_id ] ) -> fetchAll( \PDO::FETCH_ASSOC );
$product_image = $results[ 0 ][ 'src' ];
\Cache::store( 'product_image:' . $product_id, $product_image );
$cacheHandler->set( $cacheKey, $product_image );
}
else
{
return unserialize( $objectData );
}
return $product_image;
@@ -137,7 +161,7 @@ class ShopProduct
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_wp:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -159,14 +183,22 @@ class ShopProduct
{
global $mdb;
if ( !$products = \Cache::fetch( 'random_productsa_' . $product_id . '_' . $lang_id ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'random_products_' . $product_id . '_' . $lang_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id FROM pp_shop_products WHERE status = 1 ORDER BY RAND() LIMIT 6' ) -> fetchAll();
if ( is_array( $results ) and!empty( $results ) )
foreach ( $results as $row )
$products[] = \front\factory\ShopProduct::product_details( $row[ 'id' ], $lang_id );
\Cache::store( 'random_products_' . $product_id . '_' . $lang_id, $products );
$cacheHandler->set( $cacheKey, $products );
}
else
{
return unserialize( $objectData );
}
return $products;
@@ -176,14 +208,22 @@ class ShopProduct
{
global $mdb;
if ( !$products = \Cache::fetch( "promoted_products-$limit" ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "promoted_products-$limit";
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id FROM pp_shop_products WHERE status = 1 AND promoted = 1 ORDER BY RAND() LIMIT ' . $limit ) -> fetchAll();
if ( is_array( $results ) and!empty( $results ) )
foreach ( $results as $row )
$products[] = $row[ 'id' ];
\Cache::store( "promoted_products-$limit", $products );
$cacheHandler->set( $cacheKey, $products );
}
else
{
return unserialize( $objectData );
}
return $products;
@@ -227,7 +267,7 @@ class ShopProduct
if ( !$product_id )
return false;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_details:$product_id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);

View File

@@ -13,7 +13,7 @@ class ShopTransport
{
global $mdb, $settings;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\front\factory\ShopTransport::transport_methods";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -57,12 +57,20 @@ class ShopTransport
{
global $mdb;
if ( !$cost = \Cache::fetch( 'transport_cost_' . $transport_id ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport_cost_' . $transport_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$repo = new \Domain\Transport\TransportRepository($mdb);
$cost = $repo->getTransportCost($transport_id);
\Cache::store( 'transport_cost_' . $transport_id, $cost );
$cacheHandler->set( $cacheKey, $cost );
}
else
{
return unserialize( $objectData );
}
return $cost;
}
@@ -71,12 +79,20 @@ class ShopTransport
{
global $mdb;
if ( !$transport = \Cache::fetch( 'transport' . $transport_id ) )
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = 'transport' . $transport_id;
$objectData = $cacheHandler->get( $cacheKey );
if ( !$objectData )
{
$repo = new \Domain\Transport\TransportRepository($mdb);
$transport = $repo->findActiveById($transport_id);
\Cache::store( 'transport' . $transport_id, $transport );
$cacheHandler->set( $cacheKey, $transport );
}
else
{
return unserialize( $objectData );
}
return $transport;
}

View File

@@ -1,22 +0,0 @@
<?php
namespace front\view;
class Banners
{
public static function banners( $banners )
{
$tpl = new \Tpl;
$tpl -> banners = $banners;
return $tpl -> render( 'banner/banners' );
}
public static function main_banner( $banner )
{
if ( !\S::get_session( 'banner_close' ) && is_array( $banner ) )
{
$tpl = new \Tpl;
$tpl -> banner = $banner;
return $tpl -> render( 'banner/main-banner' );
}
}
}

View File

@@ -23,6 +23,7 @@ class Site
global $page, $settings, $settings, $lang, $lang_id;
$articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] );
$bannerRepo = new \Domain\Banner\BannerRepository( $GLOBALS['mdb'] );
if ( (int) \S::get( 'layout_id' ) )
$layout = new \cms\Layout( (int) \S::get( 'layout_id' ) );
@@ -59,8 +60,8 @@ class Site
\front\view\Site::copyright(),
$html );
$html = str_replace( '[BANER_STRONA_GLOWNA]', \front\view\Banners::main_banner( \front\factory\Banners::main_banner() ), $html );
$html = str_replace( '[BANERY]', \front\view\Banners::banners( \front\factory\Banners::banners() ), $html );
$html = str_replace( '[BANER_STRONA_GLOWNA]', \front\Views\Banners::mainBanner( $bannerRepo->mainBanner( $lang_id ) ), $html );
$html = str_replace( '[BANERY]', \front\Views\Banners::banners( $bannerRepo->banners( $lang_id ) ), $html );
$html = str_replace( '[KATEGORIE]', \Tpl::view( 'shop-category/categories', [
'level' => $level,

View File

@@ -59,7 +59,7 @@ class Category implements \ArrayAccess
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\Category::get_subcategory_by_category:$category_id";
$objectData = $cacheHandler -> get( $cacheKey );

View File

@@ -126,7 +126,7 @@ class Product implements \ArrayAccess
try
{
// Get the Redis connection instance
$redis = \RedisConnection::getInstance()->getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance()->getConnection();
// Check if Redis connection is valid
if ( $redis )
@@ -303,7 +303,7 @@ class Product implements \ArrayAccess
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\Product::product_sets_when_add_to_basket:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -536,7 +536,7 @@ class Product implements \ArrayAccess
{
global $mdb, $settings;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\Product::get_product_permutation_quantity_options:v2:$product_id:$permutation";
$objectData = $cacheHandler -> get( $cacheKey );

View File

@@ -8,7 +8,7 @@ class ProductAttribute implements \ArrayAccess
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::is_value_default:$value_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -63,7 +63,7 @@ class ProductAttribute implements \ArrayAccess
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::get_attribute_order:$attribute_id";
$objectData = $cacheHandler -> get( $cacheKey );
@@ -93,7 +93,7 @@ class ProductAttribute implements \ArrayAccess
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::get_value_name:$value_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );

View File

@@ -19,7 +19,7 @@ class ProductCustomField implements \ArrayAccess
{
try
{
$redis = \RedisConnection::getInstance() -> getConnection();
$redis = \Shared\Cache\RedisConnection::getInstance() -> getConnection();
if ( $redis )
{

View File

@@ -21,7 +21,7 @@ class Promotion extends DbModel
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\Promotion::get_active_promotions";
$objectData = $cacheHandler -> get( $cacheKey );