ver. 0.291: ShopProducer frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -301,6 +301,34 @@ class ProducerRepository
|
||||
return is_array($rows) ? array_map('intval', $rows) : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktywni producenci z pelnym danymi (frontend lista).
|
||||
*
|
||||
* @return array<int, array{id: int, name: string, img: string|null}>
|
||||
*/
|
||||
public function allActiveProducers(): array
|
||||
{
|
||||
$rows = $this->db->select('pp_shop_producer', ['id', 'name', 'img'], [
|
||||
'status' => 1,
|
||||
'ORDER' => ['name' => 'ASC'],
|
||||
]);
|
||||
|
||||
if (!is_array($rows)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$producers = [];
|
||||
foreach ($rows as $row) {
|
||||
$producers[] = [
|
||||
'id' => (int)($row['id'] ?? 0),
|
||||
'name' => (string)($row['name'] ?? ''),
|
||||
'img' => $row['img'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
return $producers;
|
||||
}
|
||||
|
||||
private function defaultProducer(): array
|
||||
{
|
||||
return [
|
||||
|
||||
62
autoload/front/Controllers/ShopProducerController.php
Normal file
62
autoload/front/Controllers/ShopProducerController.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Producer\ProducerRepository;
|
||||
|
||||
class ShopProducerController
|
||||
{
|
||||
private ProducerRepository $repository;
|
||||
|
||||
public function __construct( ProducerRepository $repository )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function products()
|
||||
{
|
||||
global $page, $lang_id;
|
||||
|
||||
$producerId = (int)\Shared\Helpers\Helpers::get( 'producer_id' );
|
||||
$producer = $this->repository->findForFrontend( $producerId, $lang_id );
|
||||
|
||||
if ( !$producer )
|
||||
return '';
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = $producer['name'];
|
||||
|
||||
$bs = (int)\Shared\Helpers\Helpers::get( 'bs' );
|
||||
$results = $this->repository->producerProducts( $producer['id'], 12, $bs ?: 1 );
|
||||
|
||||
$pager = '';
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$pager = \Shared\Tpl\Tpl::view( 'site/pager', [
|
||||
'ls' => $results['ls'],
|
||||
'bs' => $bs ?: 1,
|
||||
'page' => $page,
|
||||
'link' => 'producent/' . \Shared\Helpers\Helpers::seo( $producer['name'] )
|
||||
] );
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-producer/products', [
|
||||
'producer' => $producer,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager
|
||||
] );
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
global $page;
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = 'Producenci';
|
||||
|
||||
$producers = $this->repository->allActiveProducers();
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-producer/list', [
|
||||
'producers' => $producers
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
<?
|
||||
namespace front\controls;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function products()
|
||||
{
|
||||
global $page, $lang_id;
|
||||
|
||||
$producer = new \shop\Producer( \Shared\Helpers\Helpers::get( 'producer_id' ) );
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = $producer['name'];
|
||||
|
||||
$results = \shop\Producer::producer_products( $producer['id'], $lang_id, (int) \Shared\Helpers\Helpers::get( 'bs' ) );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$pager = \Shared\Tpl\Tpl::view( 'site/pager', [
|
||||
'ls' => $results['ls'],
|
||||
'bs' => (int) \Shared\Helpers\Helpers::get( 'bs' ) ? (int) \Shared\Helpers\Helpers::get( 'bs' ) : 1,
|
||||
'page' => $page,
|
||||
'link' => 'producent/' . \Shared\Helpers\Helpers::seo( $producer['name'] )
|
||||
] );
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-producer/products', [
|
||||
'producer' => $producer,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager
|
||||
] );
|
||||
}
|
||||
|
||||
static public function list()
|
||||
{
|
||||
global $mdb, $page;
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = 'Producenci';
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_producer', 'id', [ 'status' => 1, 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
$producers[] = new \shop\Producer( $row );
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-producer/list', [
|
||||
'producers' => $producers
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -191,6 +191,12 @@ class Site
|
||||
new \Domain\Order\OrderRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'ShopProducer' => function() {
|
||||
global $mdb;
|
||||
return new \front\Controllers\ShopProducerController(
|
||||
new \Domain\Producer\ProducerRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ class Site
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
|
||||
$scontainersRepo = new \Domain\Scontainers\ScontainersRepository( $GLOBALS['mdb'] );
|
||||
$categoryRepo = new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] );
|
||||
$producerRepo = new \Domain\Producer\ProducerRepository( $GLOBALS['mdb'] );
|
||||
|
||||
if ( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) )
|
||||
$layout = $layoutsRepo->find( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) );
|
||||
@@ -216,9 +217,9 @@ class Site
|
||||
//
|
||||
if ( \Shared\Helpers\Helpers::get( 'producer_id' ) )
|
||||
{
|
||||
$producer = new \shop\Producer( \Shared\Helpers\Helpers::get( 'producer_id' ) );
|
||||
$producer = $producerRepo->findForFrontend( (int)\Shared\Helpers\Helpers::get( 'producer_id' ), $lang_id );
|
||||
|
||||
if ( $producer['languages'][$lang_id]['meta_title'] )
|
||||
if ( $producer && !empty( $producer['languages'][$lang_id]['meta_title'] ) )
|
||||
$page['language']['meta_title'] = $producer['languages'][$lang_id]['meta_title'];
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
namespace shop;
|
||||
class Producer implements \ArrayAccess
|
||||
{
|
||||
public function __construct( int $producer_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$repo = new \Domain\Producer\ProducerRepository( $mdb );
|
||||
$data = $repo->find( $producer_id );
|
||||
|
||||
foreach ( $data as $key => $val )
|
||||
$this->$key = $val;
|
||||
}
|
||||
|
||||
static public function producer_products( $producer_id, $lang_id, $bs )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$repo = new \Domain\Producer\ProducerRepository( $mdb );
|
||||
return $repo->producerProducts( (int) $producer_id, 12, (int) $bs );
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> $variable;
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> $variable = $value;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user