Files
shopPRO/autoload/shop/class.ProductAttribute.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

119 lines
3.4 KiB
PHP

<?php
namespace shop;
class ProductAttribute implements \ArrayAccess
{
// sprawdź czy wartość atrybutu jest domyślna
static public function is_value_default( int $value_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::is_value_default:$value_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$is_default = $mdb -> get( 'pp_shop_attributes_values', 'is_default', [ 'id' => $value_id ] );
$cacheHandler -> set( $cacheKey, $is_default );
}
else
{
return unserialize( $objectData );
}
return $is_default;
}
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);
}
public function __construct( int $attribute_id, $lang_id = null )
{
global $mdb;
if ( !$lang_id )
$lang_id = ( new \Domain\Languages\LanguagesRepository( $mdb ) )->defaultLanguage();
$result = $mdb -> get( 'pp_shop_attributes', '*', [ 'id' => $attribute_id ] );
if ( \S::is_array_fix( $result ) ) foreach ( $result as $key => $val )
$this -> $key = $val;
$results = $mdb -> select( 'pp_shop_attributes_langs', '*', [ 'AND' => [ 'attribute_id' => $attribute_id, 'lang_id' => $lang_id ] ] );
if ( \S::is_array_fix( $results ) ) foreach ( $results as $row )
$this -> language = $row;
}
// pobierz kolejność atrybutu
static public function get_attribute_order( int $attribute_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::get_attribute_order:$attribute_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$order = $mdb -> get( 'pp_shop_attributes', 'o', [ 'id' => $attribute_id ] );
$cacheHandler -> set( $cacheKey, $order );
}
else
{
return unserialize($objectData);
}
return $order;
}
// pobierz nazwę atrybutu za pomocą wartości
static public function getAttributeNameByValue( int $value_id, string $lang_id )
{
global $mdb;
return array_pop( $mdb -> query( 'SELECT name FROM pp_shop_attributes_langs AS psal INNER JOIN pp_shop_attributes_values AS psav ON psal.attribute_id = psav.attribute_id WHERE psav.id = ' . $value_id . ' AND lang_id = \'' . $lang_id . '\'' ) -> fetch( \PDO::FETCH_ASSOC ) );
}
// pobierz nazwę wartości
static public function get_value_name( int $value_id, string $lang_id )
{
global $mdb;
$cacheHandler = new \Shared\Cache\CacheHandler();
$cacheKey = "\shop\ProductAttribute::get_value_name:$value_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$value_name = $mdb -> get( 'pp_shop_attributes_values_langs', 'name', [ 'AND' => [ 'value_id' => (int)$value_id, 'lang_id' => $lang_id ] ] );
$cacheHandler -> set( $cacheKey, $value_name );
}
else
{
return unserialize($objectData);
}
return $value_name;
}
// pobierz nazwę atrybutu
static public function getAttributeName( int $attribute_id, string $lang_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_attributes_langs', 'name', [ 'AND' => [ 'attribute_id' => (int)$attribute_id, 'lang_id' => $lang_id ] ] );
}
}