Files
shopPRO/autoload/shop/class.ProductCustomField.php
Jacek Pyziak 285cbe5515 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>
2026-02-16 21:25:50 +01:00

74 lines
1.7 KiB
PHP

<?php
namespace shop;
class ProductCustomField implements \ArrayAccess
{
public function __construct( int $custom_field_id )
{
global $mdb;
$result = $mdb -> get( 'pp_shop_products_custom_fields', '*', [ 'id_additional_field' => $custom_field_id ] );
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
$this -> $key = $val;
}
static public function getFromCache( int $custom_field_id )
{
// Check if Redis extension is loaded
if ( class_exists( 'Redis' ) )
{
try
{
$redis = \Shared\Cache\RedisConnection::getInstance() -> getConnection();
if ( $redis )
{
$objectData = $redis -> get( "shop\ProductCustomField:$custom_field_id" );
if ( !$objectData )
{
$object = new self( $custom_field_id );
$redis -> setex( "shop\ProductCustomField:$custom_field_id", 60 * 60 * 24, serialize( $object ) );
}
else
{
$object = unserialize( $objectData );
}
}
else
{
// Log the error if needed
$object = new self( $custom_field_id );
}
}
catch ( \Exception $e )
{
// Log the exception if needed
$object = new self( $custom_field_id );
}
}
else
{
// Redis extension not loaded, create a new instance
$object = new self( $custom_field_id );
}
return $object;
}
public function offsetExists($offset) {
return isset($this->$offset);
}
public function offsetGet($offset) {
return $this->$offset;
}
public function offsetSet($offset , $value) {
$this->$offset = $value;
}
public function offsetUnset($offset) {
unset($this->$offset);
}
}