Add view classes for articles, banners, languages, menu, newsletter, containers, shop categories, clients, payment methods, products, and search

- Created `Articles` class for rendering article views including full articles, miniature lists, and news sections.
- Added `Banners` class for handling banner displays.
- Introduced `Languages` class for rendering language options.
- Implemented `Menu` class for rendering page and menu structures.
- Developed `Newsletter` class for newsletter rendering.
- Created `Scontainers` class for rendering specific containers.
- Added `ShopCategory` class for managing shop category views and pagination.
- Implemented `ShopClient` class for client-related views including address management and login forms.
- Created `ShopPaymentMethod` class for displaying payment methods in the basket.
- Added `ShopProduct` class for generating product URLs.
- Introduced `ShopSearch` class for rendering a simple search form.
- Added `.htaccess` file in the plugins directory to enhance security by restricting access to sensitive files and directories.
This commit is contained in:
2026-02-21 23:00:54 +01:00
parent a605e0f4ad
commit fc45bbf20e
322 changed files with 35722 additions and 21849 deletions

202
autoload/front/App.php Normal file
View File

@@ -0,0 +1,202 @@
<?php
namespace front;
class App
{
static public function pageTitle()
{
$moduleName = implode( '', array_map( 'ucfirst', explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ) ) );
$action = \Shared\Helpers\Helpers::get( 'action' );
$actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) );
$controllerClass = '\front\Controllers\\' . $moduleName . 'Controller';
if ( class_exists( $controllerClass ) and property_exists( $controllerClass, 'title' ) and isset( $controllerClass::$title[$actionCamel] ) )
return $controllerClass::$title[$actionCamel];
$class = '\front\controls\\' . $moduleName;
if ( class_exists( $class ) and property_exists( new $class, 'page_title' ) )
return $class::$title[$action];
}
static public function title()
{
global $settings;
$moduleName = implode( '', array_map( 'ucfirst', explode( '_', \Shared\Helpers\Helpers::get( 'module' ) ) ) );
$action = \Shared\Helpers\Helpers::get( 'action' );
$actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) );
$controllerClass = '\front\Controllers\\' . $moduleName . 'Controller';
if ( class_exists( $controllerClass ) and property_exists( $controllerClass, 'title' ) and isset( $controllerClass::$title[$actionCamel] ) )
return $controllerClass::$title[$actionCamel] . ' | ' . $settings['firm_name'];
$class = '\front\controls\\' . $moduleName;
if ( class_exists( $class ) and property_exists( new $class, 'title' ) )
return $class::$title[$action] . ' | ' . $settings['firm_name'];
}
public static function route( $product = '', $category = '' )
{
global $page, $lang_id, $settings;
$articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] );
if ( \Shared\Helpers\Helpers::get( 'article' ) )
return \front\Views\Articles::fullArticle( $articleRepo->articleDetailsFrontend( (int)\Shared\Helpers\Helpers::get( 'article' ), $lang_id ) );
// wyświetlenie pojedynczego produktu
if ( $product )
{
( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->addVisit( (int)$product['id'] );
return \Shared\Tpl\Tpl::view( 'shop-product/product', [
'product' => $product,
'settings' => $settings,
'lang_id' => $lang_id,
'settings' => $settings
] );
}
if ( $category )
return \front\Views\ShopCategory::categoryView( $category, $lang_id, (int)\Shared\Helpers\Helpers::get( 'bs' ) );
// nowe kontrolery z DI
$module = \Shared\Helpers\Helpers::get( 'module' );
$action = \Shared\Helpers\Helpers::get( 'action' );
$controllerFactories = self::getControllerFactories();
$moduleName = implode( '', array_map( 'ucfirst', explode( '_', $module ) ) );
if ( isset( $controllerFactories[$moduleName] ) and $action )
{
$controller = $controllerFactories[$moduleName]();
$actionCamel = lcfirst( implode( '', array_map( 'ucfirst', explode( '_', $action ) ) ) );
if ( method_exists( $controller, $actionCamel ) )
return $controller->$actionCamel();
}
// stare klasy
$class = '\front\controls\\' . $moduleName;
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
if ( $page['id'] )
{
$bs = (int)\Shared\Helpers\Helpers::get( 'bs' );
$pageArticlesResult = $articleRepo->pageArticles( $page, $lang_id, $bs ?: 1 );
$articlesForPage = [];
if ( is_array( $pageArticlesResult['articles'] ) ) {
foreach ( $pageArticlesResult['articles'] as $aid ) {
$articlesForPage[] = $articleRepo->articleDetailsFrontend( (int)$aid, $lang_id );
}
}
switch ( $page['page_type'] )
{
/* pełne artykuły */
case 0:
return \front\Views\Articles::fullArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page );
break;
/* wprowadzenia */
case 1:
return \front\Views\Articles::entryArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page );
break;
/* miniaturki */
case 2:
return \front\Views\Articles::miniatureArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page );
break;
/* strona kontaktu */
case 4:
$out = \front\Views\Articles::fullArticlesList( $articlesForPage, $pageArticlesResult['ls'], $bs ?: 1, $page );
$out .= \front\LayoutEngine::contact();
return $out;
break;
}
}
}
public static function checkUrlParams()
{
global $lang, $config;
$a = \Shared\Helpers\Helpers::get( 'a' );
switch ( $a )
{
case 'page':
global $lang_id;
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
$page = $pagesRepo->frontPageDetails( \Shared\Helpers\Helpers::get( 'id' ), $lang_id ?? '' );
\Shared\Helpers\Helpers::set_session( 'page', $page );
break;
case 'change_language':
\Shared\Helpers\Helpers::set_session( 'current-lang', \Shared\Helpers\Helpers::get( 'id' ) );
header( 'Location: /' );
exit;
break;
}
if ( \Shared\Helpers\Helpers::get( 'lang' ) )
\Shared\Helpers\Helpers::set_session( 'current-lang', \Shared\Helpers\Helpers::get( 'lang' ) );
if ( file_exists( 'modules/actions.php' ) )
include 'modules/actions.php';
}
public static function getControllerFactories()
{
return [
'Newsletter' => function() {
global $mdb;
return new \front\Controllers\NewsletterController(
new \Domain\Newsletter\NewsletterRepository( $mdb )
);
},
'ShopBasket' => function() {
global $mdb;
return new \front\Controllers\ShopBasketController(
new \Domain\Order\OrderRepository( $mdb ),
new \Domain\PaymentMethod\PaymentMethodRepository( $mdb )
);
},
'ShopClient' => function() {
global $mdb;
return new \front\Controllers\ShopClientController(
new \Domain\Client\ClientRepository( $mdb )
);
},
'ShopCoupon' => function() {
global $mdb;
return new \front\Controllers\ShopCouponController(
new \Domain\Coupon\CouponRepository( $mdb )
);
},
'ShopOrder' => function() {
global $mdb;
$orderRepo = new \Domain\Order\OrderRepository( $mdb );
return new \front\Controllers\ShopOrderController(
$orderRepo,
new \Domain\Order\OrderAdminService( $orderRepo )
);
},
'ShopProducer' => function() {
global $mdb;
return new \front\Controllers\ShopProducerController(
new \Domain\Producer\ProducerRepository( $mdb )
);
},
'ShopProduct' => function() {
global $mdb;
return new \front\Controllers\ShopProductController(
new \Domain\Category\CategoryRepository( $mdb )
);
},
'Search' => function() {
return new \front\Controllers\SearchController();
},
];
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace front\Controllers;
use Domain\Newsletter\NewsletterRepository;
class NewsletterController
{
private NewsletterRepository $repository;
public function __construct( NewsletterRepository $repository )
{
$this->repository = $repository;
}
public function signin()
{
global $settings;
$result = [ 'status' => 'bad' ];
if ( $this->repository->signup( \Shared\Helpers\Helpers::get( 'email' ), $_SERVER['SERVER_NAME'], !empty( $settings['ssl'] ), $settings ) )
$result = [ 'status' => 'ok' ];
echo json_encode( $result );
exit;
}
public function confirm()
{
global $lang;
if ( $this->repository->confirmSubscription( \Shared\Helpers\Helpers::get( 'hash' ) ) )
\Shared\Helpers\Helpers::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
header( 'Location: /' );
exit;
}
public function unsubscribe()
{
global $lang;
if ( $this->repository->unsubscribe( \Shared\Helpers\Helpers::get( 'hash' ) ) )
\Shared\Helpers\Helpers::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
header( 'Location: /' );
exit;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace front\Controllers;
class SearchController
{
public function searchResults()
{
global $lang_id;
$bs = \Shared\Helpers\Helpers::get( 'bs' );
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$results = $productRepo->searchProductsByName( \Shared\Helpers\Helpers::get( 'query' ), $lang_id, (int)$bs );
$out = \Shared\Tpl\Tpl::view( 'shop-search/products', [
'query' => \Shared\Helpers\Helpers::get( 'query' ),
'products' => $results['products']
] );
if ( $results['ls'] > 1 )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> link = 'wyszukiwarka/' . \Shared\Helpers\Helpers::get( 'query' );
$out .= $tpl -> render( 'site/pager' );
}
return $out;
}
public function searchProducts()
{
global $lang_id;
$products = [];
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$results = $productRepo->searchProductByNameAjax( \Shared\Helpers\Helpers::get( 'query' ), $lang_id );
if ( \Shared\Helpers\Helpers::is_array_fix( $results ) ) {
foreach ( $results as $row ) {
$products[] = \Shared\Tpl\Tpl::view( 'shop-search/product-search', [
'product' => $productRepo->findCached( $row['product_id'], $lang_id )
] );
}
}
echo json_encode( $products );
exit;
}
}

View File

@@ -0,0 +1,406 @@
<?php
namespace front\Controllers;
class ShopBasketController
{
public static $title = [
'mainView' => 'Koszyk'
];
private $orderRepository;
private $paymentMethodRepository;
public function __construct( \Domain\Order\OrderRepository $orderRepository, \Domain\PaymentMethod\PaymentMethodRepository $paymentMethodRepository )
{
$this->orderRepository = $orderRepository;
$this->paymentMethodRepository = $paymentMethodRepository;
}
public function basketMessageSave()
{
\Shared\Helpers\Helpers::set_session( 'basket_message', \Shared\Helpers\Helpers::get( 'basket_message' ) );
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function basketRemoveProduct()
{
global $lang_id;
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$product_hash = \Shared\Helpers\Helpers::get( 'product_hash' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
unset( $basket[ $product_hash ] );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
$this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id );
}
public function basketIncreaseQuantityProduct()
{
global $lang_id;
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$product_hash = \Shared\Helpers\Helpers::get( 'product_hash' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ]++;
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
$this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id );
}
public function basketDecreaseQuantityProduct()
{
global $lang_id;
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$product_hash = \Shared\Helpers\Helpers::get( 'product_hash' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ]--;
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
$this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id );
}
public function basketChangeQuantityProduct()
{
global $lang_id;
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$product_hash = \Shared\Helpers\Helpers::get( 'product_hash' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ] = (int)\Shared\Helpers\Helpers::get( 'quantity' );
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket, false );
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$this->jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id );
}
public function productMessageChange()
{
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$basket[ \Shared\Helpers\Helpers::get( 'position_code' ) ]['message'] = \Shared\Helpers\Helpers::get( 'product_message' );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
exit;
}
public function basketAddProduct()
{
global $lang_id;
$basket = \Domain\Basket\BasketCalculator::validateBasket( \Shared\Helpers\Helpers::get_session( 'basket' ) );
$values_tmp = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
$values = [];
$attributes = [];
$custom_fields = [];
foreach( $values_tmp as $key => $val )
$values[ $val['name'] ] = $val['value'];
foreach( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false )
$attributes[] = $val;
}
foreach( $values as $key => $val )
{
if ( strpos( $key, 'custom_field' ) !== false )
{
preg_match( '/\d+/', $key, $matches );
$custom_field_id = $matches[0];
$custom_fields[ $custom_field_id ] = $val;
}
}
if ( \Shared\Helpers\Helpers::is_array_fix( $attributes ) )
{
$values['parent_id'] = $values[ 'product-id' ];
$values['product-id'] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getProductIdByAttributes( $values[ 'product-id' ], $attributes );
$values['attributes'] = $attributes;
}
$values['wp'] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->getWeightCached( (int)$values[ 'product-id' ] );
$attributes_implode = '';
if ( is_array( $attributes ) and count( $attributes ) > 0 )
$attributes_implode = implode( '|', $attributes );
$product_code = md5( $values['product-id'] . $attributes_implode . $values['product-message'] . json_encode( $custom_fields ) );
if ( isset( $basket[ $product_code ] ) )
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
else
$basket[ $product_code ] = $values;
$basket[ $product_code ]['message'] = $values['product-message'];
$basket[ $product_code ]['custom_fields'] = $custom_fields;
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
\Shared\Helpers\Helpers::set_session( 'basket', $basket );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
echo json_encode( [
'result' => 'ok',
'basket_mini_count' => \Domain\Basket\BasketCalculator::countProductsText( \Domain\Basket\BasketCalculator::countProducts( $basket ) ),
'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon, $lang_id ),
'product_sets' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productSetsWhenAddToBasket( (int)$values['product-id'] )
] );
exit;
}
public function transportMethodInpostCheck()
{
$transport_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
if ( $transport_id === '2' or $transport_id === '1' )
{
if ( !\Shared\Helpers\Helpers::get_session( 'basket-inpost-info' ) )
{
echo json_encode( [ 'result' => 'bad' ] );
exit;
}
}
if ( $transport_id === '9' )
{
if ( !\Shared\Helpers\Helpers::get_session( 'basket_orlen_point_id' ) )
{
echo json_encode( [ 'result' => 'bad' ] );
exit;
}
}
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function inpostCheck()
{
if ( !\Shared\Helpers\Helpers::get_session( 'basket-inpost-info' ) )
echo json_encode( [ 'result' => 'bad' ] );
else
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function orlenSave()
{
\Shared\Helpers\Helpers::set_session( 'basket_orlen_point_id', \Shared\Helpers\Helpers::get( 'orlen_point_id' ) );
\Shared\Helpers\Helpers::set_session( 'basket_orlen_point_info', \Shared\Helpers\Helpers::get( 'orlen_point_name' ) );
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function inpostSave()
{
\Shared\Helpers\Helpers::set_session( 'basket-inpost-info', \Shared\Helpers\Helpers::get( 'paczkomat' ) );
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function basketPaymentMethodSet()
{
\Shared\Helpers\Helpers::set_session( 'basket-payment-method-id', \Shared\Helpers\Helpers::get( 'payment_method_id' ) );
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function basketTransportMethodSet()
{
\Shared\Helpers\Helpers::set_session( 'basket-transport-method-id', \Shared\Helpers\Helpers::get( 'transport_method_id' ) );
echo json_encode( [ 'result' => 'ok' ] );
exit;
}
public function basketPaymentsMethods()
{
\Shared\Helpers\Helpers::set_session( 'basket-transport-method-id', \Shared\Helpers\Helpers::get( 'transport_method_id' ) );
echo json_encode( [
'result' => 'ok',
'payment_methods' => \front\Views\ShopPaymentMethod::basketPaymentMethods(
$this->paymentMethodRepository->paymentMethodsByTransport( (int)\Shared\Helpers\Helpers::get( 'transport_method_id' ) ),
\Shared\Helpers\Helpers::get( 'payment_method_id' )
)
] );
exit;
}
public function summaryView()
{
global $lang_id, $settings;
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
}
$client = \Shared\Helpers\Helpers::get_session( 'client' );
return \Shared\Tpl\Tpl::view( 'shop-basket/summary-view', [
'lang_id' => $lang_id,
'client' => \Shared\Helpers\Helpers::get_session( 'client' ),
'basket' => \Shared\Helpers\Helpers::get_session( 'basket' ),
'transport' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->findActiveByIdCached( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ),
'payment_method' => $this->paymentMethodRepository->paymentMethodCached( (int)\Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) ),
'addresses' => ( new \Domain\Client\ClientRepository( $GLOBALS['mdb'] ) )->clientAddresses( (int)$client['id'] ),
'settings' => $settings,
'coupon' => \Shared\Helpers\Helpers::get_session( 'coupon' ),
'basket_message' => \Shared\Helpers\Helpers::get_session( 'basket_message' )
] );
}
public function basketSave()
{
$client = \Shared\Helpers\Helpers::get_session( 'client' );
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( \Shared\Helpers\Helpers::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
}
if ( $order_id = $this->orderRepository->createFromBasket(
$client[ 'id' ],
\Shared\Helpers\Helpers::get_session( 'basket' ),
\Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ),
\Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ),
\Shared\Helpers\Helpers::get( 'email', true ),
\Shared\Helpers\Helpers::get( 'phone', true ),
\Shared\Helpers\Helpers::get( 'name', true ),
\Shared\Helpers\Helpers::get( 'surname', true ),
\Shared\Helpers\Helpers::get( 'street' ),
\Shared\Helpers\Helpers::get( 'postal_code', true ),
\Shared\Helpers\Helpers::get( 'city', true ),
\Shared\Helpers\Helpers::get( 'firm_name', true ),
\Shared\Helpers\Helpers::get( 'firm_street', true ),
\Shared\Helpers\Helpers::get( 'firm_postal_code', true ),
\Shared\Helpers\Helpers::get( 'firm_city', true ),
\Shared\Helpers\Helpers::get( 'firm_nip', true ),
\Shared\Helpers\Helpers::get_session( 'basket-inpost-info' ),
\Shared\Helpers\Helpers::get_session( 'basket_orlen_point_id' ),
\Shared\Helpers\Helpers::get_session( 'basket_orlen_point_info' ),
\Shared\Helpers\Helpers::get_session( 'coupon' ),
\Shared\Helpers\Helpers::get_session( 'basket_message' )
) )
{
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-zlozone-komunikat' ) );
\Shared\Helpers\Helpers::delete_session( 'basket' );
\Shared\Helpers\Helpers::delete_session( 'basket-transport-method-id' );
\Shared\Helpers\Helpers::delete_session( 'basket-payment-method-id' );
\Shared\Helpers\Helpers::delete_session( 'basket-inpost-info' );
\Shared\Helpers\Helpers::delete_session( 'basket_orlen_point_id' );
\Shared\Helpers\Helpers::delete_session( 'basket_orlen_point_info' );
\Shared\Helpers\Helpers::delete_session( 'coupon' );
\Shared\Helpers\Helpers::delete_session( 'basket_message' );
\Shared\Helpers\Helpers::set_session( 'piksel_purchase', true );
\Shared\Helpers\Helpers::set_session( 'google-adwords-purchase', true );
\Shared\Helpers\Helpers::set_session( 'google-analytics-purchase', true );
\Shared\Helpers\Helpers::set_session( 'ekomi-purchase', true );
$redis = \Shared\Cache\RedisConnection::getInstance() -> getConnection();
if ( $redis )
$redis -> flushAll();
header( 'Location: /zamowienie/' . $this->orderRepository->findHashById( $order_id ) );
exit;
}
else
{
\Shared\Helpers\Helpers::error( \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-zlozone-komunikat-blad' ) );
header( 'Location: /koszyk' );
exit;
}
}
public function mainView()
{
global $lang_id, $page, $settings;
$page[ 'language' ][ 'meta_title' ] = 'Koszyk';
$basket = \Shared\Helpers\Helpers::get_session( 'basket' );
$coupon = \Shared\Helpers\Helpers::get_session( 'coupon' );
$payment_method_id = \Shared\Helpers\Helpers::get_session( 'payment_method_id' );
$basket_transport_method_id = \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );
if ( \Domain\Basket\BasketCalculator::checkProductQuantityInStock( $basket ) )
{
header( 'Location: /koszyk' );
exit;
}
$basket = (new \Domain\Promotion\PromotionRepository($GLOBALS['mdb']))->findPromotion( $basket );
return \Shared\Tpl\Tpl::view( 'shop-basket/basket', [
'basket' => $basket,
'coupon' => $coupon,
'transport_id' => \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ),
'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportMethodsFront( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] ),
'payment_method_id' => $payment_method_id,
'basket_details' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon,
'basket_message' => \Shared\Helpers\Helpers::get_session( 'basket_message' ),
'settings' => $settings
] )
] );
}
private function jsonBasketResponse( $basket, $coupon, $lang_id, $basket_transport_method_id )
{
echo json_encode( [
'basket' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon
] ),
'basket_mini_count' => \Domain\Basket\BasketCalculator::countProductsText( \Domain\Basket\BasketCalculator::countProducts( $basket ) ),
'basket_mini_value' => \Domain\Basket\BasketCalculator::summaryPrice( $basket, $coupon, $lang_id ),
'products_count' => count( $basket ),
'transport_methods' => \Shared\Tpl\Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => ( new \Domain\Transport\TransportRepository( $GLOBALS['mdb'] ) )->transportMethodsFront( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
] );
exit;
}
}

View File

@@ -0,0 +1,354 @@
<?php
namespace front\Controllers;
use Domain\Client\ClientRepository;
class ShopClientController
{
private $clientRepo;
public function __construct(ClientRepository $clientRepo)
{
$this->clientRepo = $clientRepo;
}
public function markAddressAsCurrent()
{
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
return false;
}
$this->clientRepo->markAddressAsCurrent(
(int)$client['id'],
(int)\Shared\Helpers\Helpers::get('address_id')
);
exit;
}
public function addressDelete()
{
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
header('Location: /logowanie');
exit;
}
$address = $this->clientRepo->addressDetails((int)\Shared\Helpers\Helpers::get('id'));
if (!$address || $address['client_id'] != $client['id']) {
header('Location: /panel-klienta/adresy');
exit;
}
if ($this->clientRepo->addressDelete((int)\Shared\Helpers\Helpers::get('id'))) {
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('adres-usuniety-komunikat'));
} else {
\Shared\Helpers\Helpers::error(\Shared\Helpers\Helpers::lang('adres-usuniety-blad'));
}
header('Location: /panel-klienta/adresy');
exit;
}
public function addressEdit()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-edycja-adresu') . ' | ' . $settings['firm_name'];
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
header('Location: /logowanie');
exit;
}
$addressId = (int)\Shared\Helpers\Helpers::get('id');
$address = $this->clientRepo->addressDetails($addressId);
if ($address && $address['client_id'] != $client['id']) {
$address = null;
}
return \front\Views\ShopClient::addressEdit([
'address' => $address,
]);
}
public function addressSave()
{
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
header('Location: /logowanie');
exit;
}
$addressId = (int)\Shared\Helpers\Helpers::get('address_id');
$data = [
'name' => \Shared\Helpers\Helpers::get('name', true),
'surname' => \Shared\Helpers\Helpers::get('surname', true),
'street' => \Shared\Helpers\Helpers::get('street'),
'postal_code' => \Shared\Helpers\Helpers::get('postal_code', true),
'city' => \Shared\Helpers\Helpers::get('city', true),
'phone' => \Shared\Helpers\Helpers::get('phone', true),
];
if ($this->clientRepo->addressSave((int)$client['id'], $addressId ?: null, $data)) {
$msg = $addressId
? \Shared\Helpers\Helpers::lang('zmiana-adresu-sukces')
: \Shared\Helpers\Helpers::lang('dodawanie-nowego-adresu-sukces');
\Shared\Helpers\Helpers::alert($msg);
} else {
$msg = $addressId
? \Shared\Helpers\Helpers::lang('zmiana-adresu-blad')
: \Shared\Helpers\Helpers::lang('dodawanie-nowego-adresu-blad');
\Shared\Helpers\Helpers::error($msg);
}
header('Location: /panel-klienta/adresy');
exit;
}
public function clientAddresses()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-lista-adresow') . ' | ' . $settings['firm_name'];
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
header('Location: /logowanie');
exit;
}
return \front\Views\ShopClient::clientAddresses([
'client' => $client,
'addresses' => $this->clientRepo->clientAddresses((int)$client['id']),
]);
}
public function clientOrders()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-historia-zamowien') . ' | ' . $settings['firm_name'];
$client = \Shared\Helpers\Helpers::get_session('client');
if (!$client) {
header('Location: /logowanie');
exit;
}
return \front\Views\ShopClient::clientOrders([
'client' => $client,
'orders' => $this->clientRepo->clientOrders((int)$client['id']),
'statuses' => ( new \Domain\Order\OrderRepository( $GLOBALS['mdb'] ) )->orderStatuses(),
]);
}
public function newPassword()
{
$result = $this->clientRepo->generateNewPassword(
(string)\Shared\Helpers\Helpers::get('hash')
);
if ($result) {
$text = $this->buildEmailBody('#nowe-haslo', [
'[HASLO]' => $result['password'],
]);
\Shared\Helpers\Helpers::send_email(
$result['email'],
\Shared\Helpers\Helpers::lang('nowe-haslo-w-sklepie'),
$text
);
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('nowe-haslo-zostalo-wyslane-na-twoj-adres-email'));
}
header('Location: /logowanie');
exit;
}
public function sendEmailPasswordRecovery()
{
$hash = $this->clientRepo->initiatePasswordRecovery(
(string)\Shared\Helpers\Helpers::get('email')
);
if ($hash) {
$text = $this->buildEmailBody('#odzyskiwanie-hasla-link', [
'[LINK]' => '/shopClient/new_password/hash=' . $hash,
]);
\Shared\Helpers\Helpers::send_email(
(string)\Shared\Helpers\Helpers::get('email'),
\Shared\Helpers\Helpers::lang('generowanie-nowego-hasla-w-sklepie'),
$text
);
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('odzyskiwanie-hasla-link-komunikat'));
} else {
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('odzyskiwanie-hasla-blad'));
}
header('Location: /logowanie');
exit;
}
public function recoverPassword()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-odzyskiwanie-hasla') . ' | ' . $settings['firm_name'];
return \front\Views\ShopClient::recoverPassword();
}
public function logout()
{
\Shared\Helpers\Helpers::delete_session('client');
header('Location: /');
exit;
}
public function login()
{
$result = $this->clientRepo->authenticate(
(string)\Shared\Helpers\Helpers::get('email'),
(string)\Shared\Helpers\Helpers::get('password')
);
if ($result['status'] === 'inactive') {
$link = '<a href="/ponowna-aktywacja/' . $result['hash'] . '/">'
. ucfirst(\Shared\Helpers\Helpers::lang('wyslij-link-ponownie')) . '</a>';
\Shared\Helpers\Helpers::alert(
str_replace('[LINK]', $link, \Shared\Helpers\Helpers::lang('logowanie-blad-nieaktywne-konto'))
);
header('Location: /logowanie');
exit;
}
if ($result['status'] !== 'ok') {
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang($result['code']));
header('Location: /logowanie');
exit;
}
\Shared\Helpers\Helpers::set_session('client', $result['client']);
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('logowanie-udane'));
$redirect = \Shared\Helpers\Helpers::get('redirect');
header('Location: ' . ($redirect ? $redirect : '/panel-klienta'));
exit;
}
public function confirm()
{
$email = $this->clientRepo->confirmRegistration(
(string)\Shared\Helpers\Helpers::get('hash')
);
if ($email) {
$text = $this->buildEmailBody('#potwierdzenie-aktywacji-konta');
\Shared\Helpers\Helpers::send_email(
$email,
\Shared\Helpers\Helpers::lang('potwierdzenie-aktywacji-konta-w-sklepie') . ' ' . \Shared\Helpers\Helpers::lang('#nazwa-serwisu'),
$text
);
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('rejestracja-potwierdzenie'));
}
header('Location: /logowanie');
exit;
}
public function signup()
{
$email = (string)\Shared\Helpers\Helpers::get('email');
$password = (string)\Shared\Helpers\Helpers::get('password');
$created = $this->clientRepo->createClient(
$email,
$password,
(bool)\Shared\Helpers\Helpers::get('agremment_marketing')
);
if (!$created) {
echo json_encode([
'status' => 'bad',
'msg' => \Shared\Helpers\Helpers::lang('rejestracja-email-zajety'),
]);
exit;
}
$text = $this->buildEmailBody('#potwierdzenie-rejestracji', [
'[LINK]' => '/shopClient/confirm/hash=' . $created['hash'],
]);
\Shared\Helpers\Helpers::send_email(
$email,
\Shared\Helpers\Helpers::lang('potwierdzenie-rejestracji-konta-w-sklepie') . ' ' . \Shared\Helpers\Helpers::lang('#nazwa-serwisu'),
$text
);
echo json_encode([
'status' => 'ok',
'msg' => \Shared\Helpers\Helpers::lang('rejestracja-udana'),
]);
exit;
}
public function loginForm()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-logowanie') . ' | ' . $settings['firm_name'];
$page['class'] = 'page-login-form';
$client = \Shared\Helpers\Helpers::get_session('client');
if ($client) {
header('Location: /panel-klienta/zamowienia');
exit;
}
return \front\Views\ShopClient::loginForm();
}
public function registerForm()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-rejestracja') . ' | ' . $settings['firm_name'];
$client = \Shared\Helpers\Helpers::get_session('client');
if ($client) {
header('Location: /panel-klienta/zamowienia');
exit;
}
return \front\Views\ShopClient::registerForm();
}
/**
* Builds email body from newsletter template with URL absolutization.
*
* @param array<string, string> $replacements Placeholders to replace in the template
*/
private function buildEmailBody(string $templateName, array $replacements = []): string
{
$settings = $GLOBALS['settings'];
$text = $settings['newsletter_header'];
$text .= (new \Domain\Newsletter\NewsletterRepository($GLOBALS['mdb']))->templateByName($templateName);
$text .= $settings['newsletter_footer'];
$base = !empty($settings['ssl']) ? 'https' : 'http';
$serverName = $_SERVER['SERVER_NAME'] ?? '';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace($regex, '$1' . $base . '://' . $serverName . '$2$4', $text);
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace($regex, '$1' . $base . '://' . $serverName . '$2$4', $text);
foreach ($replacements as $placeholder => $value) {
$text = str_replace($placeholder, $value, $text);
}
return $text;
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace front\Controllers;
use Domain\Coupon\CouponRepository;
class ShopCouponController
{
private CouponRepository $repository;
public function __construct( CouponRepository $repository )
{
$this->repository = $repository;
}
public function useCoupon()
{
$coupon = $this->repository->findByName( (string)\Shared\Helpers\Helpers::get( 'coupon' ) );
if ( $coupon && $this->repository->isAvailable( $coupon ) )
\Shared\Helpers\Helpers::set_session( 'coupon', $coupon );
else
\Shared\Helpers\Helpers::alert( 'Podany kod rabatowy jest nieprawidłowy.' );
header( 'Location: /koszyk' );
exit;
}
public function deleteCoupon()
{
\Shared\Helpers\Helpers::delete_session( 'coupon' );
header( 'Location: /koszyk' );
exit;
}
}

View File

@@ -0,0 +1,148 @@
<?php
namespace front\Controllers;
use Domain\Order\OrderRepository;
use Domain\Order\OrderAdminService;
class ShopOrderController
{
private $repository;
private $adminService;
public function __construct( OrderRepository $repository, OrderAdminService $adminService )
{
$this->repository = $repository;
$this->adminService = $adminService;
}
public function paymentConfirmation()
{
global $settings;
$order = $this->repository->orderDetailsFrontend( null, \Shared\Helpers\Helpers::get( 'order_hash' ) );
return \Shared\Tpl\Tpl::view( 'shop-order/payment-confirmation', [
'order' => $order,
'settings' => $settings
] );
}
public function paymentStatusTpay()
{
file_put_contents( 'tpay.txt', print_r( $_POST, true ) . print_r( $_GET, true ), FILE_APPEND );
if ( \Shared\Helpers\Helpers::get( 'tr_status' ) == 'TRUE' && \Shared\Helpers\Helpers::get( 'tr_crc' ) )
{
$order = $this->repository->findRawByHash( \Shared\Helpers\Helpers::get( 'tr_crc' ) );
if ( $order && $order['id'] )
{
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
echo 'TRUE';
exit;
}
}
echo 'FALSE';
exit;
}
public function paymentStatusPrzelewy24pl()
{
global $settings;
$post = [
'p24_merchant_id' => \Shared\Helpers\Helpers::get( 'p24_merchant_id' ),
'p24_pos_id' => \Shared\Helpers\Helpers::get( 'p24_pos_id' ),
'p24_session_id' => \Shared\Helpers\Helpers::get( 'p24_session_id' ),
'p24_amount' => \Shared\Helpers\Helpers::get( 'p24_amount' ),
'p24_currency' => \Shared\Helpers\Helpers::get( 'p24_currency' ),
'p24_order_id' => \Shared\Helpers\Helpers::get( 'p24_order_id' ),
'p24_sign' => md5( \Shared\Helpers\Helpers::get( 'p24_session_id' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_order_id' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_amount' ) . '|' . \Shared\Helpers\Helpers::get( 'p24_currency' ) . '|' . $settings['przelewy24_crc_key'] )
];
$ch = curl_init();
if ( $settings['przelewy24_sandbox'] )
curl_setopt( $ch, CURLOPT_URL, 'https://sandbox.przelewy24.pl/trnVerify' );
if ( !$settings['przelewy24_sandbox'] )
curl_setopt( $ch, CURLOPT_URL, 'https://secure.przelewy24.pl/trnVerify' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
$response = curl_exec( $ch );
$order = $this->repository->findRawByPrzelewy24Hash( \Shared\Helpers\Helpers::get( 'p24_session_id' ) );
if ( $order && $order['status'] == 0 && $order['summary'] * 100 == \Shared\Helpers\Helpers::get( 'p24_amount' ) )
{
if ( $order['id'] )
{
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
}
}
exit;
}
public function paymentStatusHotpay()
{
global $lang;
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
{
$order = $this->repository->orderDetailsFrontend( (int)$_POST['ID_ZAMOWIENIA'] );
if ( $order && $order['id'] )
{
if ( is_array( $order['products'] ) && count( $order['products'] ) ):
$summary_tmp = 0;
foreach ( $order['products'] as $product ):
$product_tmp = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->productDetailsFrontCached( (int)$product['product_id'], $lang['id'] );
$summary_tmp += \Shared\Helpers\Helpers::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
endforeach;
$summary_tmp += $order['transport_cost'];
endif;
if ( hash( "sha256", "ProjectPro1916;" . round( $summary_tmp, 2 ) . ";" . $_POST["ID_PLATNOSCI"] . ";" . $_POST["ID_ZAMOWIENIA"] . ";" . $_POST["STATUS"] . ";" . $_POST["SEKRET"] ) == $_POST["HASH"] )
{
if ( $_POST["STATUS"] == "SUCCESS" )
{
$this->adminService->setOrderAsPaid( (int)$order['id'], true );
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone' );
}
else if ( $_POST["STATUS"] == "FAILURE" )
{
$this->adminService->changeStatus( (int)$order['id'], 2, true );
echo \Shared\Helpers\Helpers::lang( 'platnosc-zostala-odrzucona' );
}
}
else
{
$this->adminService->changeStatus( (int)$order['id'], 3, true );
echo \Shared\Helpers\Helpers::lang( 'zamowienie-zostalo-oplacone-reczne' );
}
}
}
exit;
}
public function orderDetails()
{
global $page, $settings;
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-szczegoly-zamowienia' ) . ' | ' . $settings['firm_name'];
$order = $this->repository->orderDetailsFrontend(
$this->repository->findIdByHash( \Shared\Helpers\Helpers::get( 'order_hash' ) )
);
$coupon = (int)$order['coupon_id'] ? ( new \Domain\Coupon\CouponRepository( $GLOBALS['mdb'] ) )->find( (int)$order['coupon_id'] ) : null;
return \Shared\Tpl\Tpl::view( 'shop-order/order-details', [
'order' => $order,
'coupon' => $coupon,
'client' => \Shared\Helpers\Helpers::get_session( 'client' ),
'settings' => $settings
] );
}
}

View 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
] );
}
}

View File

@@ -0,0 +1,116 @@
<?php
namespace front\Controllers;
class ShopProductController
{
private $categoryRepository;
public function __construct( \Domain\Category\CategoryRepository $categoryRepository )
{
$this->categoryRepository = $categoryRepository;
}
public function lazyLoadingProducts()
{
global $lang_id;
$output = '';
$categoryId = (int)\Shared\Helpers\Helpers::get( 'category_id' );
$products_ids = $this->categoryRepository->productsId(
$categoryId,
$this->categoryRepository->getCategorySort( $categoryId ),
$lang_id,
8,
(int)\Shared\Helpers\Helpers::get( 'offset' )
);
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
$output .= \Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => $productRepo->findCached( $product_id, $lang_id )
] );
endforeach;
endif;
echo json_encode( [ 'html' => $output ] );
exit;
}
public function warehouseMessage()
{
global $lang_id;
$values = json_decode( \Shared\Helpers\Helpers::get( 'values' ), true );
$attributes = [];
foreach ( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' )
$attributes[] = $val;
}
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$permutation = self::getPermutation( $attributes );
$quantity = self::getPermutationQuantity( $values['product-id'], $permutation );
global $settings;
$result = [];
if ( $quantity )
{
$msg = $productRepo->getWarehouseMessageNonzero( (int)$values['product-id'], $lang_id );
if ( $msg )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( isset( $settings[ 'warehouse_message_nonzero_' . $lang_id ] ) && $settings[ 'warehouse_message_nonzero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_nonzero_' . $lang_id ], 'quantity' => $quantity ];
}
else
{
$msg = $productRepo->getWarehouseMessageZero( (int)$values['product-id'], $lang_id );
if ( $msg )
$result = [ 'msg' => $msg, 'quantity' => $quantity ];
else if ( isset( $settings[ 'warehouse_message_zero_' . $lang_id ] ) && $settings[ 'warehouse_message_zero_' . $lang_id ] )
$result = [ 'msg' => $settings[ 'warehouse_message_zero_' . $lang_id ], 'quantity' => $quantity ];
}
echo json_encode( $result );
exit;
}
public function drawProductAttributes()
{
global $lang_id;
$combination = '';
$selected_values = \Shared\Helpers\Helpers::get( 'selected_values' );
foreach ( $selected_values as $value )
{
$combination .= $value;
if ( $value != end( $selected_values ) )
$combination .= '|';
}
$product_id = \Shared\Helpers\Helpers::get( 'product_id' );
$productRepo = new \Domain\Product\ProductRepository( $GLOBALS['mdb'] );
$product = $productRepo->findCached( $product_id, $lang_id );
$product_data = $productRepo->getProductDataBySelectedAttributes( $product, $combination );
echo json_encode( [ 'product_data' => $product_data ] );
exit;
}
private static function getPermutation( $attributes )
{
if ( !is_array( $attributes ) || !count( $attributes ) ) return null;
return implode( '|', $attributes );
}
private static function getPermutationQuantity( $productId, $permutation )
{
global $mdb;
if ( !$permutation ) return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
$qty = $mdb->get( 'pp_shop_products', 'quantity', [ 'AND' => [ 'parent_id' => $productId, 'permutation_hash' => $permutation ] ] );
if ( $qty !== null ) return $qty;
return $mdb->get( 'pp_shop_products', 'quantity', [ 'id' => $productId ] );
}
}

View File

@@ -1,8 +1,7 @@
<?php
namespace front\view;
use shop\Product;
namespace front;
class Site
class LayoutEngine
{
const menu_pattern = '/MENU:[0-9]*/';
const menu_main_pattern = '/MENU_GLOWNE:[0-9]*/';
@@ -22,45 +21,53 @@ class Site
{
global $page, $settings, $settings, $lang, $lang_id;
if ( (int) \S::get( 'layout_id' ) )
$layout = new \cms\Layout( (int) \S::get( 'layout_id' ) );
$articleRepo = new \Domain\Article\ArticleRepository( $GLOBALS['mdb'] );
$bannerRepo = new \Domain\Banner\BannerRepository( $GLOBALS['mdb'] );
$layoutsRepo = new \Domain\Layouts\LayoutsRepository( $GLOBALS['mdb'] );
$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 ( \S::get( 'article' ) )
$layout = \front\factory\Layouts::article_layout( \S::get( 'article' ) );
if ( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) )
$layout = $layoutsRepo->find( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) );
if ( \S::get( 'product' ) )
$layout = \front\factory\Layouts::product_layout( \S::get( 'product' ) );
if ( \Shared\Helpers\Helpers::get( 'article' ) )
$layout = $layoutsRepo->getArticleLayout( (int) \Shared\Helpers\Helpers::get( 'article' ) );
if ( \S::get( 'category' ) )
$layout = \front\factory\Layouts::category_layout( \S::get( 'category' ) );
if ( \Shared\Helpers\Helpers::get( 'product' ) )
$layout = $layoutsRepo->getProductLayout( (int) \Shared\Helpers\Helpers::get( 'product' ) );
if ( \Shared\Helpers\Helpers::get( 'category' ) )
$layout = $layoutsRepo->getCategoryLayout( (int) \Shared\Helpers\Helpers::get( 'category' ) );
if ( !$layout and \Shared\Helpers\Helpers::get( 'module' ) )
$layout = $layoutsRepo->getDefaultLayout();
if ( !$layout )
$layout = \front\factory\Layouts::active_layout( $page['id'] );
$layout = $layoutsRepo->getActiveLayout( $page['id'] );
if ( $settings['devel'] == true and file_exists( 'devel.html' ) )
$html = file_get_contents( 'devel.html' );
else
{
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
$html = $layout['m_html'];
else
$html = $layout['html'];
$html = $layout['html'];
}
if ( $settings['facebook_link'] )
$html = str_replace( '</body>', \front\view\Site::facebook( $settings['facebook_link'] ) . '</body>', $html );
$html = str_replace( '</body>', self::facebook( $settings['facebook_link'] ) . '</body>', $html );
$html = str_replace( '[COPYRIGHT]',
\front\view\Site::copyright(),
self::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,
'current_category' => \S::get( 'category' ),
'categories' => \front\factory\ShopCategory::categories_details()
$html = str_replace( '[KATEGORIE]', \Shared\Tpl\Tpl::view( 'shop-category/categories', [
'level' => null,
'current_category' => \Shared\Helpers\Helpers::get( 'category' ),
'categories' => $categoryRepo->categoriesTree( $lang_id )
] ), $html );
/* BOX - promowane produkty */
@@ -73,8 +80,8 @@ class Site
$products_promoted_tmp[1] ? $pattern = '[PROMOWANE_PRODUKTY:' . $products_promoted_tmp[1] . ']' : $pattern = '[PROMOWANE_PRODUKTY]';
$html = str_replace( $pattern,
\Tpl::view( 'shop-product/promoted-products', [
'products' => \front\factory\ShopProduct::promoted_products( $limit )
\Shared\Tpl\Tpl::view( 'shop-product/promoted-products', [
'products' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->promotedProductIdsCached( $limit )
] ),
$html
);
@@ -89,41 +96,35 @@ class Site
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
$news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ']';
$html = str_replace( $pattern, \front\view\Articles::news(
$html = str_replace( $pattern, \front\Views\Articles::news(
$news_list_tmp[1],
\front\factory\Articles::news( $news_list_tmp[1], $news_limit, $lang_id )
$articleRepo->news( (int)$news_list_tmp[1], (int)$news_limit, $lang_id )
), $html );
}
$html = str_replace( '[KOSZYK]',
\Tpl::view( 'shop-basket/basket-mini', [
'basket' => \S::get_session( 'basket' ),
\Shared\Tpl\Tpl::view( 'shop-basket/basket-mini', [
'basket' => \Shared\Helpers\Helpers::get_session( 'basket' ),
'lang_id' => $lang_id,
'coupon' => \S::get_session( 'coupon' )
'coupon' => \Shared\Helpers\Helpers::get_session( 'coupon' )
] ),
$html );
$html = str_replace( '[NEWSLETTER]',
\front\view\Newsletter::newsletter(),
\front\Views\Newsletter::render(),
$html );
$html = str_replace( '[UZYTKOWNIK_MINI_LOGOWANIE]',
\front\view\ShopClient::mini_login(),
\front\Views\ShopClient::miniLogin(),
$html );
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
$html = str_replace( '[CSS]', $layout['m_css'], $html );
else
$html = str_replace( '[CSS]', $layout['css'], $html );
$html = str_replace( '[CSS]', $layout['css'], $html );
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
$html = str_replace( '[JAVA_SCRIPT]', $layout['m_js'], $html );
else
$html = str_replace( '[JAVA_SCRIPT]', $layout['js'], $html );
$html = str_replace( '[JAVA_SCRIPT]', $layout['js'], $html );
preg_match_all( self::menu_pattern, $html, $menu );
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
{
$menu_tmp = explode( ':', $menu_tmp );
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\view\Menu::menu( \front\factory\Menu::menu_details( $menu_tmp[1] ), $page['id'] ), $html );
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\Views\Menu::menu( $pagesRepo->frontMenuDetails( (int) $menu_tmp[1], $lang_id ), $page['id'] ), $html );
}
preg_match_all( self::menu_main_pattern, $html, $menu );
@@ -132,8 +133,8 @@ class Site
$menu_tmp = explode( ':', $menu_tmp );
$html = str_replace(
'[MENU_GLOWNE:' . $menu_tmp[1] . ']',
\Tpl::view( 'menu/main-menu', [
'menu' => \front\factory\Menu::menu_details( $menu_tmp[1] )
\Shared\Tpl\Tpl::view( 'menu/main-menu', [
'menu' => $pagesRepo->frontMenuDetails( (int) $menu_tmp[1], $lang_id )
] ),
$html );
}
@@ -148,9 +149,9 @@ class Site
//
// KATEGORIA SKLEPU
//
if ( \S::get( 'category' ) )
if ( \Shared\Helpers\Helpers::get( 'category' ) )
{
$category = \front\factory\ShopCategory::category_details( \S::get( 'category' ) );
$category = $categoryRepo->frontCategoryDetails( (int)\Shared\Helpers\Helpers::get( 'category' ), $lang_id );
if ( $category['language']['meta_title'] )
$page['language']['title'] = $category['language']['meta_title'];
@@ -170,9 +171,9 @@ class Site
//
// ARTYKUŁ
//
if ( \S::get( 'article' ) )
if ( \Shared\Helpers\Helpers::get( 'article' ) )
{
$article = \front\factory\Articles::article_details( \S::get( 'article' ), $lang_id );
$article = $articleRepo->articleDetailsFrontend( (int)\Shared\Helpers\Helpers::get( 'article' ), $lang_id );
if ( $article['language']['meta_title'] )
$page['language']['title'] = $article['language']['meta_title'];
@@ -190,9 +191,9 @@ class Site
//
// PRODUKT
//
if ( \S::get( 'product' ) )
if ( \Shared\Helpers\Helpers::get( 'product' ) )
{
$product = Product::getFromCache( \S::get( 'product' ), $lang_id, $_GET['permutation_hash'] );
$product = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( \Shared\Helpers\Helpers::get( 'product' ), $lang_id, $_GET['permutation_hash'] ?? null );
if ( $product['language']['meta_title'] )
$page['language']['title'] = $product['language']['meta_title'];
@@ -213,11 +214,11 @@ class Site
//
// PRODUCENT
//
if ( \S::get( 'producer_id' ) )
if ( \Shared\Helpers\Helpers::get( 'producer_id' ) )
{
$producer = new \shop\Producer( \S::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'];
}
@@ -231,7 +232,7 @@ class Site
}
$html = str_replace( '[CANONICAL]', '', $html );
$html = str_replace( '[ZAWARTOSC]', \front\controls\Site::route( $product, $category ), $html );
$html = str_replace( '[ZAWARTOSC]', \front\App::route( $product, $category ), $html );
/* pojedynczy produkt */
preg_match_all( self::single_product_pattern, $html, $single_product_array );
@@ -240,8 +241,8 @@ class Site
$single_product = explode( ':', $single_product );
$html = str_replace(
'[PRODUKT:' . $single_product[1] . ']',
\Tpl::view( 'shop-product/product-mini', [
'product' => \shop\Product::getFromCache( (int)$single_product[1], $lang_id )
\Shared\Tpl\Tpl::view( 'shop-product/product-mini', [
'product' => ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$single_product[1], $lang_id )
] ),
$html
);
@@ -257,12 +258,12 @@ class Site
$products_id = explode( ',', $products_box[1] );
foreach ( $products_id as $product_id )
$products[] = Product::getFromCache( (int)$product_id, $lang_id );
$products[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
$html = str_replace(
'[PRODUKTY_BOX:' . $products_box[1] . ']',
\Tpl::view( 'shop-product/products-box', [
\Shared\Tpl\Tpl::view( 'shop-product/products-box', [
'products' => $products
] ),
$html
@@ -283,14 +284,14 @@ class Site
$products_top[1] ? $pattern = '[PRODUKTY_TOP:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_TOP]';
$products_id_arr = \front\factory\ShopProduct::top_products( $limit );
$products_id_arr = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->topProductIds( $limit );
foreach ( $products_id_arr as $product_id ){
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
$top_products_arr[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
}
$html = str_replace( $pattern,
\Tpl::view( 'shop-product/products-top', [
\Shared\Tpl\Tpl::view( 'shop-product/products-top', [
'products' => $top_products_arr,
] ),
$html
@@ -311,15 +312,15 @@ class Site
$products_top[1] ? $pattern = '[PRODUKTY_NEW:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_NEW]';
$products_id_arr = \front\factory\ShopProduct::new_products( $limit );
$products_id_arr = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->newProductIds( $limit );
foreach ( $products_id_arr as $product_id ){
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
$top_products_arr[] = ( new \Domain\Product\ProductRepository( $GLOBALS['mdb'] ) )->findCached( (int)$product_id, $lang_id );
}
$html = str_replace( $pattern,
\Tpl::view( 'shop-product/products-new', [
\Shared\Tpl\Tpl::view( 'shop-product/products-new', [
'products' => $top_products_arr,
] ),
$html
@@ -330,14 +331,14 @@ class Site
$html = str_replace( '[TITLE]', $page['language']['meta_title'] ? $page['language']['meta_title'] . ' | ' . $settings['firm_name'] : $page['language']['title'] . ' | ' . $settings['firm_name'], $html );
$html = str_replace( '[META_KEYWORDS]', $page['language']['meta_keywords'], $html );
$html = str_replace( '[META_DESCRIPTION]', $page['language']['meta_description'], $html );
$html = str_replace( '[JEZYKI]', \front\view\Languages::languages(), $html );
$html = str_replace( '[JEZYKI]', \front\Views\Languages::render( ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->activeLanguages() ), $html );
$html = str_replace( '[TYTUL_STRONY]', self::title( $page['language']['title'], $page['show_title'], $page['language']['page_title'] ), $html );
$html = str_replace( '[WYSZUKIWARKA]', \shop\Search::simple_form(), $html );
$html = str_replace( '[WYSZUKIWARKA]', \front\Views\ShopSearch::simpleForm(), $html );
/* atrybut noindex */
if ( \S::get( 'article' ) )
if ( \Shared\Helpers\Helpers::get( 'article' ) )
{
\front\factory\Articles::article_noindex( \S::get( 'article' ) ) ? $noindex = 'noindex' : $noindex = 'all';
$articleRepo->articleNoindex( (int)\Shared\Helpers\Helpers::get( 'article' ), $lang_id ) ? $noindex = 'noindex' : $noindex = 'all';
$html = str_replace( '[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html );
}
else
@@ -380,45 +381,43 @@ class Site
$html = str_replace(
$pattern,
\Tpl::view( 'shop-category/blog-category-products', [
'products' => \front\factory\ShopCategory::blog_category_products( $category_list_tmp[1], $lang_id, $products_limit )
\Shared\Tpl\Tpl::view( 'shop-category/blog-category-products', [
'products' => $categoryRepo->blogCategoryProducts( (int)$category_list_tmp[1], $lang_id, (int)$products_limit )
] ),
$html );
}
// prosta lista aktualności z wybranej podstrony
preg_match_all( self::news_list_pattern, $html, $news_list );
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
preg_match_all( self::news_list_pattern, $html, $news_list_matches );
if ( is_array( $news_list_matches[0] ) ) foreach( $news_list_matches[0] as $news_list_tmp )
{
$news_list_tmp = explode( ':', $news_list_tmp );
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
$news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ']';
$news_list = \Article::getNews( $news_list_tmp[1], $news_limit, $lang_id );
$view_news_list = \Article::newsList( $news_list );
$html = str_replace( $pattern, $view_news_list, $html );
$newsArticles = $articleRepo->newsListArticles( (int)$news_list_tmp[1], (int)$news_limit, $lang_id );
$html = str_replace( $pattern, \front\Views\Articles::newsList( $newsArticles ), $html );
}
// prosta lista z najpopularniejszymi artykułami
preg_match_all( self::top_news_pattern, $html, $news_list );
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
preg_match_all( self::top_news_pattern, $html, $top_news_matches );
if ( is_array( $top_news_matches[0] ) ) foreach( $top_news_matches[0] as $news_list_tmp )
{
$news_list_tmp = explode( ':', $news_list_tmp );
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
$news_list_tmp[2] != '' ? $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ']';
$news_list = \Article::getTopNews( $news_list_tmp[1], $news_limit, $lang_id );
$view_news_list = \Article::newsList( $news_list );
$html = str_replace( $pattern, $view_news_list, $html );
$topArticles = $articleRepo->topArticles( (int)$news_list_tmp[1], (int)$news_limit, $lang_id );
$html = str_replace( $pattern, \front\Views\Articles::newsList( $topArticles ), $html );
}
$html = str_replace( '[ALERT]', \front\view\Site::alert(), $html );
$html = str_replace( '[ALERT]', self::alert(), $html );
preg_match_all( self::container_pattern, $html, $container_list );
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
{
$container_list_tmp = explode( ':', $container_list_tmp );
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $html );
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\Views\Scontainers::scontainer( $scontainersRepo->frontScontainerDetails( (int)$container_list_tmp[1], $lang_id ) ), $html );
}
return $html;
@@ -426,14 +425,14 @@ class Site
public static function facebook( $facebook_link )
{
$tpl = new \Tpl;
$tpl = new \Shared\Tpl\Tpl;
$tpl -> facebook_link = $facebook_link;
return $tpl -> render( 'site/facebook' );
}
static public function title( $title, $show_title, $page_title )
{
return \Tpl::view( 'site/title', [
return \Shared\Tpl\Tpl::view( 'site/title', [
'title' => $title,
'page_title' => $page_title,
'show_title' => $show_title
@@ -442,20 +441,20 @@ class Site
public static function alert()
{
if ( $alert = \S::get_session( 'alert' ) )
if ( $alert = \Shared\Helpers\Helpers::get_session( 'alert' ) )
{
\S::delete_session( 'alert' );
\Shared\Helpers\Helpers::delete_session( 'alert' );
return $tpl = \Tpl::view( 'site/alert', [
return $tpl = \Shared\Tpl\Tpl::view( 'site/alert', [
'alert' => $alert
] );
}
if ( $error = \S::get_session( 'error' ) )
if ( $error = \Shared\Helpers\Helpers::get_session( 'error' ) )
{
\S::delete_session( 'error' );
\Shared\Helpers\Helpers::delete_session( 'error' );
$tpl = new \Tpl;
$tpl = new \Shared\Tpl\Tpl;
$tpl -> error = $error;
return $tpl -> render( 'site/error' );
}
@@ -463,20 +462,19 @@ class Site
public static function copyright()
{
$tpl = new \Tpl;
$tpl = new \Shared\Tpl\Tpl;
return $tpl -> render( 'site/copyright' );
}
public static function contact()
{
$tpl = new \Tpl;
$tpl = new \Shared\Tpl\Tpl;
return $tpl -> render( 'site/contact' );
}
public static function cookie_information()
public static function cookieInformation()
{
$tpl = new \Tpl;
$tpl = new \Shared\Tpl\Tpl;
return $tpl -> render( 'site/cookie-information' );
}
}
?>

View File

@@ -0,0 +1,241 @@
<?php
namespace front\Views;
class Articles
{
/**
* Renderuje pelny widok pojedynczego artykulu.
*/
public static function fullArticle( $article )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->article = $article;
return $tpl->render( 'articles/article' );
}
/**
* Renderuje liste artykulow w trybie miniaturek z pagerem.
*/
public static function miniatureArticlesList( $articles, $ls, $bs, $page )
{
$out = '';
if ( is_array( $articles ) ) foreach ( $articles as $article )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->article = $article;
$out .= $tpl->render( 'articles/article-miniature' );
}
if ( $ls > 1 )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->ls = $ls;
$tpl->bs = $bs ? $bs : 1;
$tpl->page = $page;
$out .= $tpl->render( 'site/pager' );
}
return $out;
}
/**
* Renderuje liste artykulow w trybie wprowadzen z pagerem.
*/
public static function entryArticlesList( $articles, $ls, $bs, $page )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->page_id = $page['id'];
$tpl->articles = $articles;
$out = $tpl->render( 'articles/articles-entries' );
if ( $ls > 1 )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->ls = $ls;
$tpl->bs = $bs ? $bs : 1;
$tpl->page = $page;
$out .= $tpl->render( 'site/pager' );
}
return $out;
}
/**
* Renderuje liste pelnych artykulow z pagerem.
*/
public static function fullArticlesList( $articles, $ls, $bs, $page )
{
$out = '';
if ( is_array( $articles ) ) foreach ( $articles as $article )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->article = $article;
$out .= $tpl->render( 'articles/article-full' );
}
if ( $ls > 1 )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->ls = $ls;
$tpl->bs = $bs ? $bs : 1;
$tpl->page = $page;
$out .= $tpl->render( 'site/pager' );
}
return $out;
}
/**
* Renderuje box z aktualnosciami.
*/
public static function news( $page_id, $articles )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->page_id = $page_id;
$tpl->articles = $articles;
return $tpl->render( 'articles/news' );
}
/**
* Renderuje prosta liste artykulow (news-list).
*/
public static function newsList( $articles )
{
return \Shared\Tpl\Tpl::view( 'articles/news-list', [
'articles' => $articles
] );
}
// =========================================================================
// UTILITY (czyste transformacje HTML, brak DB)
// =========================================================================
/**
* Generuje spis tresci z naglowkow HTML.
*/
public static function generateTableOfContents( $content )
{
$result = '';
$currentLevel = [];
preg_match_all( '/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER );
$firstLevel = true;
foreach ( $matches as $match )
{
$level = intval( substr( $match[1], 1 ) );
while ( $level < count( $currentLevel ) )
{
$result .= '</li></ol>';
array_pop( $currentLevel );
}
if ( $level > count( $currentLevel ) )
{
while ( $level > count( $currentLevel ) )
{
if ( count( $currentLevel ) > 0 || $firstLevel )
{
$result .= '<ol>';
$firstLevel = false;
}
array_push( $currentLevel, 0 );
}
$result .= '<li>';
}
else
{
$result .= '</li><li>';
}
$currentLevel[ count( $currentLevel ) - 1 ]++;
preg_match( '/\sid="([^"]*)"/', $match[2], $idMatches );
$id = isset( $idMatches[1] ) ? $idMatches[1] : '';
$result .= sprintf(
'<a href="#%s">%s</a>',
urlencode( strtolower( $id ) ),
$match[3]
);
}
while ( !empty( $currentLevel ) )
{
$result .= '</li></ol>';
array_pop( $currentLevel );
}
if ( substr( $result, 0, 8 ) === '<ol><ol>' )
return substr( $result, 4, -5 );
else
return $result;
}
/**
* Callback dla processHeaders.
*/
public static function processHeaders( $matches )
{
$level = $matches[1];
$attrs = $matches[2];
$content = $matches[3];
$id_attr = 'id=';
$id_attr_pos = strpos( $attrs, $id_attr );
if ( $id_attr_pos === false )
{
$id = \Shared\Helpers\Helpers::seo( $content );
$attrs .= sprintf( ' id="%s"', $id );
}
return sprintf( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
}
/**
* Dodaje atrybuty id do naglowkow HTML.
*/
public static function generateHeadersIds( $text )
{
$pattern = '/<h([1-6])(.*?)>(.*?)<\/h\1>/si';
$text = preg_replace_callback( $pattern, array( __CLASS__, 'processHeaders' ), $text );
return $text;
}
/**
* Pobiera glowne zdjecie artykulu (z entry, text lub galerii).
*/
public static function getImage( $article )
{
if ( $main_img = $article['language']['main_image'] )
return $main_img;
$dom = new \DOMDocument();
@$dom->loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', 'UTF-8' ) );
$images = $dom->getElementsByTagName( 'img' );
foreach ( $images as $img )
{
$src = $img->getAttribute( 'src' );
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
return $src;
}
$dom = new \DOMDocument();
@$dom->loadHTML( mb_convert_encoding( $article['language']['text'], 'HTML-ENTITIES', 'UTF-8' ) );
$images = $dom->getElementsByTagName( 'img' );
foreach ( $images as $img )
{
$src = $img->getAttribute( 'src' );
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
return $src;
}
if ( $article['images'] )
return $article['images'][0]['src'];
return false;
}
}

View File

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

View File

@@ -0,0 +1,12 @@
<?php
namespace front\Views;
class Languages
{
public static function render( $languages )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl -> languages = $languages;
return $tpl -> render( 'site/languages' );
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace front\Views;
class Menu
{
public static function pages($pages, $level = 0, $current_page = 0)
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->pages = $pages;
$tpl->level = $level;
$tpl->current_page = $current_page;
return $tpl->render('menu/pages');
}
public static function menu($menu, $current_page)
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->menu = $menu;
$tpl->current_page = $current_page;
return $tpl->render('menu/menu');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace front\Views;
class Newsletter
{
public static function render()
{
$tpl = new \Shared\Tpl\Tpl;
return $tpl -> render( 'newsletter/newsletter' );
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace front\Views;
class Scontainers
{
public static function scontainer( $scontainer )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->scontainer = $scontainer;
return $tpl->render( 'scontainers/scontainer' );
}
}

View File

@@ -0,0 +1,66 @@
<?php
namespace front\Views;
class ShopCategory
{
public static function categoryDescription($category): string
{
return \Shared\Tpl\Tpl::view('shop-category/category-description', [
'category' => $category,
]);
}
public static function categoryView($category, string $langId, int $currentPage = 1): string
{
global $settings, $page;
$categoryRepo = new \Domain\Category\CategoryRepository($GLOBALS['mdb']);
if (!$settings['infinitescroll']) {
$results = $categoryRepo->paginatedCategoryProducts(
(int)$category['id'],
(int)($category['sort_type'] ?? 0),
$langId,
$currentPage
);
$pager = '';
if ($results['ls'] > 1) {
$tpl = new \Shared\Tpl\Tpl;
$tpl->ls = $results['ls'];
$tpl->bs = $currentPage > 0 ? $currentPage : 1;
$tpl->page = $page;
$tpl->link = !empty($category['language']['seo_link'])
? $category['language']['seo_link']
: 'k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo($category['language']['title'] ?? '');
$pager = $tpl->render('site/pager');
}
return \Shared\Tpl\Tpl::view('shop-category/category', [
'category' => $category,
'products' => $results['products'],
'pager' => $pager,
'category_description' => $currentPage <= 1,
'category_additional_text' => true,
]);
}
$productsCount = $categoryRepo->categoryProductsCount((int)$category['id'], $langId);
return \Shared\Tpl\Tpl::view('shop-category/category-infinitescroll', [
'category' => $category,
'products_count' => $productsCount,
'category_description' => $currentPage <= 1,
'category_additional_text' => true,
]);
}
public static function categories($categories, $currentCategory = 0, $level = 0): string
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->level = $level;
$tpl->current_category = $currentCategory;
$tpl->categories = $categories;
return $tpl->render('shop-category/categories');
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace front\Views;
class ShopClient
{
public static function addressEdit($values): string
{
$tpl = new \Shared\Tpl\Tpl;
if (is_array($values)) {
foreach ($values as $key => $val) {
$tpl->$key = $val;
}
}
return $tpl->render('shop-client/address-edit');
}
public static function clientAddresses($values): string
{
$tpl = new \Shared\Tpl\Tpl;
if (is_array($values)) {
foreach ($values as $key => $val) {
$tpl->$key = $val;
}
}
return $tpl->render('shop-client/client-addresses');
}
public static function clientMenu($values): string
{
$tpl = new \Shared\Tpl\Tpl;
if (is_array($values)) {
foreach ($values as $key => $val) {
$tpl->$key = $val;
}
}
return $tpl->render('shop-client/client-menu');
}
public static function clientOrders($values): string
{
$tpl = new \Shared\Tpl\Tpl;
if (is_array($values)) {
foreach ($values as $key => $val) {
$tpl->$key = $val;
}
}
return $tpl->render('shop-client/client-orders');
}
public static function recoverPassword(): string
{
$tpl = new \Shared\Tpl\Tpl;
return $tpl->render('shop-client/recover-password');
}
public static function miniLogin(): string
{
global $client;
$tpl = new \Shared\Tpl\Tpl;
$tpl->client = $client;
return $tpl->render('shop-client/mini-login');
}
public static function loginForm($values = ''): string
{
$tpl = new \Shared\Tpl\Tpl;
if (is_array($values)) {
foreach ($values as $key => $val) {
$tpl->$key = $val;
}
}
return $tpl->render('shop-client/login-form');
}
public static function registerForm(): string
{
$tpl = new \Shared\Tpl\Tpl;
return $tpl->render('shop-client/register-form');
}
}

View File

@@ -0,0 +1,13 @@
<?php
namespace front\Views;
class ShopPaymentMethod
{
public static function basketPaymentMethods( $payment_methods, $payment_id )
{
$tpl = new \Shared\Tpl\Tpl;
$tpl->payment_methods = $payment_methods;
$tpl->payment_id = $payment_id;
return $tpl->render( 'shop-basket/basket-payments-methods' );
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace front\Views;
class ShopProduct
{
public static function productUrl( $product )
{
if ( $product['language']['seo_link'] )
{
return '/' . $product['language']['seo_link'];
}
if ( $product['parent_id'] )
return '/p-' . $product['parent_id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
return '/p-' . $product['id'] . '-' . \Shared\Helpers\Helpers::seo( $product['language']['name'] );
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace front\Views;
class ShopSearch
{
public static function simpleForm()
{
return \Shared\Tpl\Tpl::view( 'shop-search/simple-form' );
}
}

View File

@@ -1,38 +0,0 @@
<?php
namespace front\controls;
class Newsletter
{
public static function signin()
{
$result = [ 'status' => 'bad' ];
if ( \front\factory\Newsletter::newsletter_signin( \S::get( 'email' ) ) )
$result = [ 'status' => 'ok' ];
echo json_encode( $result );
exit;
}
public static function confirm()
{
global $lang;
if ( \front\factory\Newsletter::newsletter_confirm( \S::get( 'hash' ) ) )
\S::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
header( 'Location: /' );
exit;
}
public static function unsubscribe()
{
global $lang;
if ( \front\factory\Newsletter::newsletter_unsubscribe( \S::get( 'hash' ) ) )
\S::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
header( 'Location: /' );
exit;
}
}

View File

@@ -1,459 +0,0 @@
<?php
namespace front\controls;
class ShopBasket
{
public static $title = [
'main_view' => 'Koszyk'
];
public static function basket_message_save()
{
\S::set_session( 'basket_message', \S::get( 'basket_message' ) );
echo json_encode( [
'result' => 'ok'
] );
exit;
}
public static function basket_remove_product()
{
global $lang_id;
$basket = \S::get_session( 'basket' );
$coupon = \S::get_session( 'coupon' );
$product_hash = \S::get( 'product_hash' );
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
\S::set_session( 'basket', $basket );
echo json_encode( [
'basket' => \Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon
] ),
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
'products_count' => count( $basket ),
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
] );
exit;
}
public static function basket_increase_quantity_product()
{
global $lang_id;
$basket = \S::get_session( 'basket' );
$coupon = \S::get_session( 'coupon' );
$product_hash = \S::get( 'product_hash' );
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ]++;
\shop\Basket::check_product_quantity_in_stock( $basket, false );
$basket = \S::get_session( 'basket' );
$basket = \shop\Promotion::find_promotion( $basket );
\S::set_session( 'basket', $basket );
echo json_encode( [
'basket' => \Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon
] ),
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
'products_count' => count( $basket ),
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
]
);
exit;
}
public static function basket_decrease_quantity_product()
{
global $lang_id;
$basket = \S::get_session( 'basket' );
$coupon = \S::get_session( 'coupon' );
$product_hash = \S::get( 'product_hash' );
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ]--;
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
\S::set_session( 'basket', $basket );
echo json_encode( [
'basket' => \Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon
] ),
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
'products_count' => count( $basket ),
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
] );
exit;
}
public static function basket_change_quantity_product()
{
global $lang_id;
$basket = \S::get_session( 'basket' );
$coupon = \S::get_session( 'coupon' );
$product_hash = \S::get( 'product_hash' );
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
$basket[ $product_hash ][ 'quantity' ] = (int)\S::get( 'quantity' );
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
unset( $basket[ $product_hash ] );
$basket = \shop\Promotion::find_promotion( $basket );
\shop\Basket::check_product_quantity_in_stock( $basket, false );
$basket = \S::get_session( 'basket' );
echo json_encode( [
'basket' => \Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon
] ),
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
'products_count' => count( $basket ),
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] )
] );
exit;
}
static public function product_message_change()
{
$basket = \S::get_session( 'basket' );
$basket[ \S::get( 'position_code' ) ]['message'] = \S::get( 'product_message' );
\S::set_session( 'basket', $basket );
exit;
}
public static function basket_add_product()
{
$basket = \shop\Basket::validate_basket( \S::get_session( 'basket' ) );
$values_tmp = json_decode( \S::get( 'values' ), true );
foreach( $values_tmp as $key => $val )
$values[ $val['name'] ] = $val['value'];
// sprawdzam pola pod kątem wybranych atrybutów
foreach( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false )
$attributes[] = $val;
}
// stwórz tablicę dodatkowych pól wyszukując na podstawie custom_field[1], custom_field[2] itd.
foreach( $values as $key => $val )
{
if ( strpos( $key, 'custom_field' ) !== false )
{
// extract number from custom_field[1], custom_field[2] etc.
preg_match( '/\d+/', $key, $matches );
$custom_field_id = $matches[0];
$custom_fields[ $custom_field_id ] = $val;
}
}
if ( \S::is_array_fix( $attributes ) )
{
$values['parent_id'] = $values[ 'product-id' ];
$values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes );
$values['attributes'] = $attributes;
}
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
$attributes_implode = '';
// generuj unikalny kod produktu dodanego do koszyka
if ( is_array( $attributes ) )
$attributes_implode = implode( '|', $attributes );
$product_code = md5( $values['product-id'] . $attributes_implode . $values['product-message'] . json_encode( $custom_fields ) );
if ( isset( $basket[ $product_code ] ) )
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
else
$basket[ $product_code ] = $values;
$basket[ $product_code ]['message'] = $values['product-message'];
$basket[ $product_code ]['custom_fields'] = $custom_fields;
$basket = \shop\Promotion::find_promotion( $basket );
\S::set_session( 'basket', $basket );
$coupon = \S::get_session( 'coupon' );
echo json_encode( [
'result' => 'ok',
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] )
] );
exit;
}
// sprawdzam czy została wybrana forma wysylki inpost i czy został wybrany paczkomat
static public function transport_method_inpost_check()
{
if ( \S::get_session( 'basket-transport-method-id' ) === '2' or \S::get_session( 'basket-transport-method-id' ) === '1' )
{
if ( !\S::get_session( 'basket-inpost-info' ) )
{
echo json_encode( [
'result' => 'bad'
] );
exit;
}
}
if ( \S::get_session( 'basket-transport-method-id' ) === '9' )
{
if ( !\S::get_session( 'basket_orlen_point_id' ) )
{
echo json_encode( [
'result' => 'bad'
] );
exit;
}
}
echo json_encode( [
'result' => 'ok'
] );
exit;
}
// sprawdzam czy został wybrany paczkomat
static public function inpost_check() {
if ( !\S::get_session( 'basket-inpost-info' ) )
echo json_encode( [
'result' => 'bad'
] );
else
echo json_encode( [
'result' => 'ok'
] );
exit;
}
static public function orlen_save()
{
\S::set_session( 'basket_orlen_point_id', \S::get( 'orlen_point_id' ) );
\S::set_session( 'basket_orlen_point_info', \S::get( 'orlen_point_name' ) );
echo json_encode( [
'result' => 'ok'
] );
exit;
}
public static function inpost_save()
{
\S::set_session( 'basket-inpost-info', \S::get( 'paczkomat' ) );
echo json_encode( [
'result' => 'ok'
] );
exit;
}
public static function basket_payment_method_set()
{
\S::set_session( 'basket-payment-method-id', \S::get( 'payment_method_id' ) );
echo json_encode( [
'result' => 'ok'
] );
exit;
}
public static function basket_transport_method_set()
{
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
echo json_encode( [
'result' => 'ok'
] );
exit;
}
public static function basket_payments_methods()
{
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
echo json_encode( [
'result' => 'ok',
'payment_methods' => \front\view\ShopPaymentMethod::basket_payment_methods(
\front\factory\ShopPaymentMethod::payment_methods_by_transport( \S::get( 'transport_method_id' ) ),
\S::get( 'payment_method_id' )
)
] );
exit;
}
public static function summary_view()
{
global $lang_id, $settings;
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
}
$client = \S::get_session( 'client' );
return \Tpl::view( 'shop-basket/summary-view', [
'lang_id' => $lang_id,
'client' => \S::get_session( 'client' ),
'basket' => \S::get_session( 'basket' ),
'transport' => \front\factory\ShopTransport::transport( \S::get_session( 'basket-transport-method-id' ) ),
'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \S::get_session( 'basket-payment-method-id' ) ),
'addresses' => \front\factory\ShopClient::client_addresses( $client[ 'id' ] ),
'settings' => $settings,
'coupon' => \S::get_session( 'coupon' ),
'basket_message' => \S::get_session( 'basket_message' )
] );
}
// zapisanie koszyka jako zamówienie
static public function basket_save()
{
$client = \S::get_session( 'client' );
$payment_method = \S::get_session( 'basket-payment-method-id' );
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
{
header( 'Location: /koszyk' );
exit;
}
if ( $order_id = \front\factory\ShopOrder::basket_save(
$client[ 'id' ],
\S::get_session( 'basket' ),
\S::get_session( 'basket-transport-method-id' ),
\S::get_session( 'basket-payment-method-id' ),
\S::get( 'email', true ),
\S::get( 'phone', true ),
\S::get( 'name', true ),
\S::get( 'surname', true ),
\S::get( 'street' ),
\S::get( 'postal_code', true ),
\S::get( 'city', true ),
\S::get( 'firm_name', true ),
\S::get( 'firm_street', true ),
\S::get( 'firm_postal_code', true ),
\S::get( 'firm_city', true ),
\S::get( 'firm_nip', true ),
\S::get_session( 'basket-inpost-info' ),
\S::get_session( 'basket_orlen_point_id' ),
\S::get_session( 'basket_orlen_point_info' ),
\S::get_session( 'coupon' ),
\S::get_session( 'basket_message' )
) )
{
\S::alert( \S::lang( 'zamowienie-zostalo-zlozone-komunikat' ) );
\S::delete_session( 'basket' );
\S::delete_session( 'basket-transport-method-id' );
\S::delete_session( 'basket-payment-method-id' );
\S::delete_session( 'basket-inpost-info' );
\S::delete_session( 'basket_orlen_point_id' );
\S::delete_session( 'basket_orlen_point_info' );
\S::delete_session( 'coupon' );
\S::delete_session( 'basket_message' );
\S::set_session( 'piksel_purchase', true );
\S::set_session( 'google-adwords-purchase', true );
\S::set_session( 'google-analytics-purchase', true );
\S::set_session( 'ekomi-purchase', true );
$redis = \RedisConnection::getInstance() -> getConnection();
if ( $redis )
$redis -> flushAll();
header( 'Location: /zamowienie/' . \front\factory\ShopOrder::order_hash( $order_id ) );
exit;
}
else
{
\S::error( \S::lang( 'zamowienie-zostalo-zlozone-komunikat-blad' ) );
header( 'Location: /koszyk' );
exit;
}
}
public static function main_view()
{
global $lang_id, $page, $settings;
$page[ 'language' ][ 'meta_title' ] = 'Koszyk';
$basket = \S::get_session( 'basket' );
$coupon = \S::get_session( 'coupon' );
$payment_method_id = \S::get_session( 'payment_method_id' );
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
if ( \shop\Basket::check_product_quantity_in_stock( $basket ) )
{
header( 'Location: /koszyk' );
exit;
}
$basket = \shop\Promotion::find_promotion( $basket );
return \Tpl::view( 'shop-basket/basket', [
'basket' => $basket,
'coupon' => $coupon,
'transport_id' => \S::get_session( 'basket-transport-method-id' ),
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
'transport_id' => $basket_transport_method_id
] ),
'payment_method_id' => $payment_method_id,
'basket_details' => \Tpl::view( 'shop-basket/basket-details', [
'basket' => $basket,
'lang_id' => $lang_id,
'coupon' => $coupon,
'basket_message' => \S::get_session( 'basket_message' ),
'settings' => $settings
] )
] );
}
}

View File

@@ -1,212 +0,0 @@
<?php
namespace front\controls;
class ShopClient
{
public static function mark_address_as_current()
{
if ( !$client = \S::get_session( 'client' ) )
return false;
\front\factory\ShopClient::mark_address_as_current( $client['id'], \S::get( 'address_id' ) );
exit;
}
public static function address_delete()
{
if ( !$client = \S::get_session( 'client' ) )
{
header( 'Location: /logowanie' );
exit;
}
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
if ( $address['client_id'] != $client['id'] )
{
header( 'Location: /panel-klienta/adresy' );
exit;
}
if ( \front\factory\ShopClient::address_delete( \S::get( 'id' ) ) )
\S::alert( \S::lang( 'adres-usuniety-komunikat' ) );
else
\S::error( \S::lang( 'adres-usuniety-blad' ) );
header( 'Location: /panel-klienta/adresy' );
exit;
}
public static function address_edit()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-edycja-adresu' ) . ' | ' . $settings['firm_name'];
if ( !$client = \S::get_session( 'client' ) )
{
header( 'Location: /logowanie' );
exit;
}
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
if ( $address['client_id'] != $client['id'] )
unset( $address );
return \front\view\ShopClient::address_edit( [
'address' => \front\factory\ShopClient::address_details( \S::get( 'id' ) )
] );
}
public static function address_save()
{
if ( !$client = \S::get_session( 'client' ) )
{
header( 'Location: /logowanie' );
exit;
}
if ( \front\factory\ShopClient::address_save( $client['id'], \S::get( 'address_id' ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ), \S::get( 'phone', true ) ) )
{
\S::get( 'address_id' ) ? \S::alert( \S::lang( 'zmiana-adresu-sukces' ) ) : \S::alert( \S::lang( 'dodawanie-nowego-adresu-sukces' ) );
}
else
{
\S::get( 'address_id' ) ? \S::error( \S::lang( 'zmiana-adresu-blad' ) ) : \S::error( \S::lang( 'dodawanie-nowego-adresu-blad' ) );
}
header( 'Location: /panel-klienta/adresy' );
exit;
}
public static function client_addresses()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-lista-adresow' ) . ' | ' . $settings['firm_name'];
if ( !$client = \S::get_session( 'client' ) )
{
header( 'Location: /logowanie' );
exit;
}
return \front\view\ShopClient::client_addresses( [
'client' => $client,
'addresses' => \front\factory\ShopClient::client_addresses( $client['id'] )
] );
}
public static function client_orders()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-historia-zamowien' ) . ' | ' . $settings['firm_name'];
if ( !$client = \S::get_session( 'client' ) )
{
header( 'Location: /logowanie' );
exit;
}
return \front\view\ShopClient::client_orders( [
'client' => $client,
'orders' => \front\factory\ShopClient::client_orders( $client['id'] ),
'statuses' => \shop\Order::order_statuses()
] );
}
public static function new_password()
{
if ( \front\factory\ShopClient::new_password( \S::get( 'hash' ) ) )
\S::alert( \S::lang( 'nowe-haslo-zostalo-wyslane-na-twoj-adres-email' ) );
header( 'Location: /logowanie' );
exit;
}
public static function send_email_password_recovery()
{
if ( \front\factory\ShopClient::send_email_password_recovery( \S::get( 'email' ) ) )
\S::alert( \S::lang( 'odzyskiwanie-hasla-link-komunikat' ) );
else
\S::alert( \S::lang( 'odzyskiwanie-hasla-blad' ) );
header( 'Location: /logowanie' );
exit;
}
public static function recover_password()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-odzyskiwanie-hasla' ) . ' | ' . $settings['firm_name'];
return \front\view\ShopClient::recover_password();
}
public static function logout()
{
\S::delete_session( 'client' );
header( 'Location: /' );
exit;
}
public static function login()
{
if ( !\front\factory\ShopClient::login( \S::get( 'email' ), \S::get( 'password' ) ) )
header( 'Location: /logowanie' );
else
{
$client = \S::get_session( 'client' );
if ( $redirect = \S::get( 'redirect' ) )
header( 'Location: ' . $redirect );
else
header( 'Location: /panel-klienta' );
}
exit;
}
public static function confirm()
{
if ( \front\factory\ShopClient::register_confirm( \S::get( 'hash' ) ) )
\S::alert( \S::lang( 'rejestracja-potwierdzenie' ) );
header( 'Location: /logowanie' );
exit;
}
public static function signup()
{
$result = \front\factory\ShopClient::signup( \S::get( 'email' ), \S::get( 'password' ), \S::get( 'agremment_marketing' ) );
echo json_encode( $result );
exit;
}
public static function login_form()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-logowanie' ) . ' | ' . $settings['firm_name'];
$page['class'] = 'page-login-form';
if ( $client = \S::get_session( 'client' ) )
{
header( 'Location: /panel-klienta/zamowienia' );
exit;
}
return \front\view\ShopClient::login_form();
}
public static function register_form()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-rejestracja' ) . ' | ' . $settings['firm_name'];
if ( $client = \S::get_session( 'client' ) )
{
header( 'Location: /panel-klienta/zamowienia' );
exit;
}
return \front\view\ShopClient::register_form();
}
}

View File

@@ -1,25 +0,0 @@
<?php
namespace front\controls;
class ShopCoupon
{
public static function delete_coupon()
{
\S::delete_session( 'coupon' );
header( 'Location: /koszyk' );
exit;
}
public static function use_coupon()
{
$coupon = new \shop\Coupon( 0 );
$coupon -> load_from_db_by_name( (string)\S::get( 'coupon' ) );
if ( $coupon -> is_available() )
\S::set_session( 'coupon', $coupon );
else
\S::alert( 'Podany kod rabatowy jest nieprawidłowy.' );
header( 'Location: /koszyk' );
exit;
}
}

View File

@@ -1,157 +0,0 @@
<?php
namespace front\controls;
class ShopOrder
{
public static function payment_confirmation()
{
global $settings;
$order = \front\factory\ShopOrder::order_details( null, \S::get( 'order_hash' ) );
return \Tpl::view( 'shop-order/payment-confirmation', [
'order' => $order,
'settings' => $settings
] );
}
public static function payment_status_tpay()
{
global $mdb;
file_put_contents( 'tpay.txt', print_r( $_POST, true ) . print_r( $_GET, true ), FILE_APPEND );
if ( \S::get( 'tr_status' ) == 'TRUE' and \S::get( 'tr_crc' ) )
{
$order = new \shop\Order( 0, \S::get( 'tr_crc' ) );
if ( $order -> id )
{
$order -> set_as_paid( true );
$order -> update_status( 4, true );
echo 'TRUE';
exit;
}
}
echo 'FALSE';
exit;
}
public static function payment_status_przelewy24pl()
{
global $mdb, $settings;
$post = [
'p24_merchant_id' => \S::get( 'p24_merchant_id' ),
'p24_pos_id' => \S::get( 'p24_pos_id' ),
'p24_session_id' => \S::get( 'p24_session_id' ),
'p24_amount' => \S::get( 'p24_amount' ),
'p24_currency' => \S::get( 'p24_currency' ),
'p24_order_id' => \S::get( 'p24_order_id' ),
'p24_sign' => md5( \S::get( 'p24_session_id' ) . '|' . \S::get( 'p24_order_id' ) . '|' . \S::get( 'p24_amount' ) . '|' . \S::get( 'p24_currency' ) . '|' . $settings['przelewy24_crc_key'] )
];
$ch = curl_init();
if ( $settings['przelewy24_sandbox'] )
curl_setopt( $ch, CURLOPT_URL, 'https://sandbox.przelewy24.pl/trnVerify' );
if ( !$settings['przelewy24_sandbox'] )
curl_setopt( $ch, CURLOPT_URL, 'https://secure.przelewy24.pl/trnVerify' );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
$response = curl_exec( $ch );
$order = new \shop\Order( 0, '', \S::get( 'p24_session_id' ) );
if ( $order['status'] == 0 and $order['summary'] * 100 == \S::get( 'p24_amount' ) )
{
if ( $order['id'] )
{
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
$order -> status = 4;
$order -> send_status_change_email();
\Log::save_log( 'Zamówienie opłacone przez przelewy24 | ID: ' . $order['id'] );
}
}
exit;
}
public static function payment_status_hotpay()
{
global $mdb, $lang;
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
{
$order = new \shop\Order( $_POST['ID_ZAMOWIENIA'] );
if ( $order['id'] )
{
if ( is_array( $order['products'] ) and count( $order['products'] ) ):
foreach ( $order['products'] as $product ):
$product_tmp = \front\factory\ShopProduct::product_details( $product['product_id'], $lang['id'] );
$summary_tmp += \S::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
endforeach;
$summary_tmp += $order['transport_cost'];
endif;
if ( hash( "sha256", "ProjectPro1916;" . round( $summary_tmp, 2 ) . ";" . $_POST["ID_PLATNOSCI"] . ";" . $_POST["ID_ZAMOWIENIA"] . ";" . $_POST["STATUS"] . ";" . $_POST["SEKRET"] ) == $_POST["HASH"] )
{
if ( $_POST["STATUS"] == "SUCCESS" )
{
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
$order -> status = 4;
$order -> send_status_change_email();
\Log::save_log( 'Zamówienie opłacone przez hotpay | ID: ' . $order['id'] );
echo \S::lang( 'zamowienie-zostalo-oplacone' );
}
else if ( $_POST["STATUS"] == "FAILURE" )
{
$mdb -> update( 'pp_shop_orders', [ 'status' => 2 ], [ 'id' => $order['id'] ] );
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 2, 'mail' => 1 ] );
$order -> status = 2;
$order -> send_status_change_email();
\Log::save_log( 'Płatność odrzucona hotpay | ID: ' . $order['id'] );
echo \S::lang( 'platnosc-zostala-odrzucona' );
}
}
else
{
$mdb -> update( 'pp_shop_orders', [ 'status' => 3 ], [ 'id' => $order['id'] ] );
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 3, 'mail' => 1 ] );
$order -> status = 3;
$order -> send_status_change_email();
\Log::save_log( 'Płatność sprawdzana ręcznie hotpay | ID: ' . $order['id'] );
echo \S::lang( 'zamowienie-zostalo-oplacone-reczne' );
}
}
}
exit;
}
public static function order_details()
{
global $page, $settings;
$page['language']['meta_title'] = \S::lang( 'meta-title-szczegoly-zamowienia' ) . ' | ' . $settings['firm_name'];
$order = \front\factory\ShopOrder::order_details(
\front\factory\ShopOrder::order_id( \S::get( 'order_hash' ) )
);
$coupon = (int)$order['coupon_id'] ? new \shop\Coupon( (int)$order['coupon_id'] ) : null;
return \Tpl::view( 'shop-order/order-details', [
'order' => $order,
'coupon' => $coupon,
'client' => \S::get_session( 'client' ),
'settings' => $settings
] );
}
}

View File

@@ -1,48 +0,0 @@
<?
namespace front\controls;
class ShopProducer
{
static public function products()
{
global $page, $lang_id;
$producer = new \shop\Producer( \S::get( 'producer_id' ) );
$page['show_title'] = true;
$page['language']['title'] = $producer['name'];
$results = \shop\Producer::producer_products( $producer['id'], $lang_id, (int) \S::get( 'bs' ) );
if ( $results['ls'] > 1 )
{
$pager = \Tpl::view( 'site/pager', [
'ls' => $results['ls'],
'bs' => (int) \S::get( 'bs' ) ? (int) \S::get( 'bs' ) : 1,
'page' => $page,
'link' => 'producent/' . \S::seo( $producer['name'] )
] );
}
return \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 ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
$producers[] = new \shop\Producer( $row );
return \Tpl::view( 'shop-producer/list', [
'producers' => $producers
] );
}
}

View File

@@ -1,63 +0,0 @@
<?php
namespace front\controls;
use shop\Product;
class ShopProduct
{
static public function lazy_loading_products()
{
global $lang_id;
$output = '';
$products_ids = \front\factory\ShopCategory::products_id( \S::get( 'category_id' ), \front\factory\ShopCategory::get_category_sort( (int)\S::get( 'category_id' ) ), $lang_id, 8, \S::get( 'offset' ) );
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
$output .= \Tpl::view('shop-product/product-mini', [
'product' => Product::getFromCache( $product_id, $lang_id )
] );
endforeach;
endif;
echo json_encode( [ 'html' => $output ] );
exit;
}
public static function warehouse_message()
{
global $lang_id;
$values = json_decode( \S::get( 'values' ), true );
foreach( $values as $key => $val )
{
if ( $key != 'product-id' and $key != 'quantity' )
$attributes[] = $val;
}
$result = \shop\Product::getWarehouseMessage( $values['product-id'], $attributes, $lang_id );
echo json_encode( $result );
exit;
}
// wyświetlenie atrybutów w widoku produktu
static public function draw_product_attributes()
{
global $mdb, $lang_id;
$combination = '';
$selected_values = \S::get( 'selected_values' );
foreach ( $selected_values as $value ) {
$combination .= $value;
if ( $value != end( $selected_values ) )
$combination .= '|';
}
$product_id = \S::get( 'product_id' );
$product = Product::getFromCache( $product_id, $lang_id );
$product_data = $product -> getProductDataBySelectedAttributes( $combination );
echo json_encode( [ 'product_data' => $product_data ] );
exit;
}
}

View File

@@ -1,136 +0,0 @@
<?php
namespace front\controls;
class Site
{
static public function page_title()
{
$class = '\front\controls\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$property = \S::get( 'action' );
if ( class_exists( $class ) and property_exists( new $class, 'page_title' ) )
return $class::$title[$property];
}
static public function title()
{
global $settings;
$class = '\front\controls\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$property = \S::get( 'action' );
if ( class_exists( $class ) and property_exists( new $class, 'title' ) )
return $class::$title[$property] . ' | ' . $settings['firm_name'];
}
public static function route( $product = '', $category = '' )
{
global $page, $lang_id, $settings;
if ( \S::get( 'article' ) )
return \front\view\Articles::full_article( \S::get( 'article' ), $lang_id );
// wyświetlenie pojedynczego produktu
if ( $product )
{
\shop\Product::add_visit( $product -> id );
return \Tpl::view( 'shop-product/product', [
'product' => $product,
'settings' => $settings,
'lang_id' => $lang_id,
'settings' => $settings
] );
}
if ( $category )
return \front\view\ShopCategory::category_view( $category, $lang_id, \S::get( 'bs' ) );
// stare klasy
$class = '\front\controls\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$action = \S::get( 'action' );
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
// klasy sklepowe
$class = '\shop\\';
$results = explode( '_', \S::get( 'module' ) );
if ( is_array( $results ) ) foreach ( $results as $row )
$class .= ucfirst( $row );
$action = \S::get( 'action' );
if ( class_exists( $class ) and method_exists( new $class, $action ) )
return call_user_func_array( array( $class, $action ), array() );
if ( $page['id'] )
{
switch ( $page['page_type'] )
{
/* pełne artykuły */
case 0:
return \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
break;
/* wprowadzenia */
case 1:
return \front\view\Articles::entry_articles_list( $page, $lang_id, \S::get( 'bs' ) );
break;
/* miniaturki */
case 2:
return \front\view\Articles::miniature_articles_list( $page, $lang_id, \S::get( 'bs' ) );
break;
/* strona kontaktu */
case 4:
$out = \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
$out .= \front\view\Site::contact();
return $out;
break;
}
}
}
public static function check_url_params()
{
global $lang, $config;
$a = \S::get( 'a' );
switch ( $a )
{
case 'page':
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
\S::set_session( 'page', $page );
break;
case 'change_language':
\S::set_session( 'current-lang', \S::get( 'id' ) );
header( 'Location: /' );
exit;
break;
}
if ( \S::get( 'lang' ) )
\S::set_session( 'current-lang', \S::get( 'lang' ) );
if ( file_exists( 'modules/actions.php' ) )
include 'modules/actions.php';
}
}
?>

View File

@@ -1,317 +0,0 @@
<?php
namespace front\factory;
class Articles
{
static public function generateTableOfContents($content) {
$result = '';
$currentLevel = [];
preg_match_all('/<(h[1-6])([^>]*)>(.*?)<\/\1>/', $content, $matches, PREG_SET_ORDER);
$firstLevel = true;
foreach ($matches as $match) {
$level = intval(substr($match[1], 1));
while ($level < count($currentLevel)) {
$result .= '</li></ol>';
array_pop($currentLevel);
}
if ($level > count($currentLevel)) {
while ($level > count($currentLevel)) {
if (count($currentLevel) > 0 || $firstLevel) {
$result .= '<ol>';
$firstLevel = false;
}
array_push($currentLevel, 0);
}
$result .= '<li>';
} else {
$result .= '</li><li>';
}
$currentLevel[count($currentLevel) - 1]++;
preg_match('/\sid="([^"]*)"/', $match[2], $idMatches);
$id = isset($idMatches[1]) ? $idMatches[1] : '';
$result .= sprintf(
'<a href="#%s">%s</a>',
urlencode(strtolower($id)),
$match[3]
);
}
while (!empty($currentLevel)) {
$result .= '</li></ol>';
array_pop($currentLevel);
}
if (substr($result, 0, 8) === '<ol><ol>') {
return substr($result, 4, -5);
} else {
return $result;
}
}
// funkcja wywoływana dla każdego dopasowania do wyrażenia regularnego
static public function processHeaders( $matches )
{
$level = $matches[1];
$attrs = $matches[2];
$content = $matches[3];
$id_attr = 'id=';
$id_attr_pos = strpos($attrs, $id_attr);
if ($id_attr_pos === false) { // jeśli nie ma atrybutu id
$id = \S::seo( $content );
$attrs .= sprintf(' id="%s"', $id);
}
$html = sprintf( '<h%d%s>%s</h%d>', $level, $attrs, $content, $level );
return $html;
}
static public function generateHeadersIds( $text )
{
$pattern = '/<h([1-6])(.*?)>(.*?)<\/h\1>/si';
$text = preg_replace_callback( $pattern, array(__CLASS__, 'processHeaders'), $text );
return $text;
}
public static function news( $page_id, $limit = 6, $lang_id )
{
$sort = \front\factory\Pages::page_sort( $page_id );
$articles_id = \front\factory\Articles::artciles_id( (int)$page_id, $lang_id, $limit, $sort, 0 );
if ( is_array( $articles_id ) and !empty( $articles_id ) ) foreach ( $articles_id as $article_id )
$articles[] = \front\factory\Articles::article_details( $article_id, $lang_id );
return $articles;
}
public static function get_image( $article )
{
if ( $main_img = $article['language']['main_image'] )
return $main_img;
$dom = new \DOMDocument();
$dom -> loadHTML( mb_convert_encoding( $article['language']['entry'], 'HTML-ENTITIES', "UTF-8" ) );
$images = $dom -> getElementsByTagName( 'img' );
foreach ( $images as $img )
{
$src = $img -> getAttribute( 'src' );
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
return $src;
}
$dom = new \DOMDocument();
$dom -> loadHTML( mb_convert_encoding( $article['language']['text'], 'HTML-ENTITIES', "UTF-8" ) );
$images = $dom -> getElementsByTagName( 'img' );
foreach ( $images as $img )
{
$src = $img -> getAttribute( 'src' );
if ( file_exists( substr( $src, 1, strlen( $src ) ) ) )
return $src;
}
if ( $article['images'] )
return $article['images'][0]['src'];
return false;
}
public static function article_noindex( $article_id )
{
global $mdb, $lang;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Articles::article_noindex:$article_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$noindex = $mdb -> get( 'pp_articles_langs', 'noindex', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang[0] ] ] );
$cacheHandler -> set( $cacheKey, $noindex );
}
else
{
return unserialize( $objectData );
}
return $noindex;
}
public static function page_articles( $page, $lang_id, $bs )
{
$count = \front\factory\Articles::page_articles_count( $page['id'], $lang_id );
$ls = ceil( $count / $page['articles_limit'] );
if ( $bs < 1 )
$bs = 1;
else if ( $bs > $ls )
$bs = $ls;
$from = $page['articles_limit'] * ( $bs - 1 );
if ( $from < 0 )
$from = 0;
$results['articles'] = \front\factory\Articles::artciles_id( (int)$page['id'], $lang_id, (int)$page['articles_limit'], $page['sort_type'], $from );
$results['ls'] = $ls;
return $results;
}
public static function article_details( $article_id, $lang_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Articles::article_details:$article_id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$article = $mdb -> get( 'pp_articles', '*', [ 'id' => (int)$article_id ] );
$results = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $lang_id ] ] );
if ( is_array( $results ) ) foreach ( $results as $row )
{
if ( $row['copy_from'] )
{
$results2 = $mdb -> select( 'pp_articles_langs', '*', [ 'AND' => [ 'article_id' => (int)$article_id, 'lang_id' => $row['copy_from'] ] ] );
if ( is_array( $results2 ) ) foreach ( $results2 as $row2 )
$article['language'] = $row2;
}
else
$article['language'] = $row;
}
$article['images'] = $mdb -> select( 'pp_articles_images', '*', [ 'article_id' => (int)$article_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'DESC' ] ] );
$article['files'] = $mdb -> select( 'pp_articles_files', '*', [ 'article_id' => (int)$article_id ] );
$article['pages'] = $mdb -> select( 'pp_articles_pages', 'page_id', [ 'article_id' => (int)$article_id ] );
$cacheHandler -> set( $cacheKey, $article );
}
else
{
return unserialize( $objectData );
}
return $article;
}
public static function artciles_id( $page_id, $lang_id, $articles_limit, $sort_type, $from )
{
global $mdb;
switch ( $sort_type )
{
case 0: $order = 'date_add ASC'; break;
case 1: $order = 'date_add DESC'; break;
case 2: $order = 'date_modify ASC'; break;
case 3: $order = 'date_modify DESC'; break;
case 4: $order = 'o ASC'; break;
case 5: $order = 'title ASC'; break;
case 6: $order = 'title DESC'; break;
default: $order = 'id ASC'; break;
}
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Artiles::artciles_id:$page_id:$lang_id:$articles_limit:$sort_type:$from:$order";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT * FROM ( '
. 'SELECT '
. 'a.id, date_modify, date_add, o, '
. '( CASE '
. 'WHEN copy_from IS NULL THEN title '
. 'WHEN copy_from IS NOT NULL THEN ( '
. 'SELECT '
. 'title '
. 'FROM '
. 'pp_articles_langs '
. 'WHERE '
. 'lang_id = al.copy_from AND article_id = a.id '
. ') '
. 'END ) AS title '
. 'FROM '
. 'pp_articles_pages AS ap '
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
. 'WHERE '
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
. ') AS q1 '
. 'WHERE '
. 'q1.title IS NOT NULL '
. 'ORDER BY '
. 'q1.' . $order . ' '
. 'LIMIT '
. (int)$from . ',' . (int)$articles_limit ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$output[] = $row['id'];
$cacheHandler -> set( $cacheKey, $output );
}
else
{
return unserialize($objectData);
}
return $output;
}
public static function page_articles_count( $page_id, $lang_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Articles::page_articles_count:$page_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT COUNT(0) FROM ( '
. 'SELECT '
. 'a.id, '
. '( CASE '
. 'WHEN copy_from IS NULL THEN title '
. 'WHEN copy_from IS NOT NULL THEN ( '
. 'SELECT '
. 'title '
. 'FROM '
. 'pp_articles_langs '
. 'WHERE '
. 'lang_id = al.copy_from AND article_id = a.id '
. ') '
. 'END ) AS title '
. 'FROM '
. 'pp_articles_pages AS ap '
. 'INNER JOIN pp_articles AS a ON a.id = ap.article_id '
. 'INNER JOIN pp_articles_langs AS al ON al.article_id = ap.article_id '
. 'WHERE '
. 'status = 1 AND page_id = ' . (int)$page_id . ' AND lang_id = \'' . $lang_id . '\' '
. ') AS q1 '
. 'WHERE '
. 'q1.title IS NOT NULL' ) -> fetchAll();
$articles_count = $results[0][0];
$cacheHandler -> set( $cacheKey, $articles_count );
}
else
{
return unserialize( $objectData );
}
return $articles_count;
}
}

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

@@ -1,16 +0,0 @@
<?
namespace front\factory;
class Dictionaries
{
static public function get_name_by_id( int $unit_id, $lang_id )
{
global $mdb;
if ( !$unit_name = \Cache::fetch( "get_name_by_id:$unit_id:$lang_id", "dictionaries" ) )
{
$unit_name = $mdb -> get( 'pp_units_langs', 'text', [ 'AND' => [ 'unit_id' => $unit_id, 'lang_id' => $lang_id ] ] );
\Cache::store( "get_name_by_id:$unit_id:$lang_id", $unit_name, 86400, "dictionaries" );
}
return $unit_name;
}
}

View File

@@ -1,78 +0,0 @@
<?php
namespace front\factory;
class Languages
{
public static function default_language()
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Languages::default_language";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT id FROM pp_langs WHERE status = 1 ORDER BY start DESC, o ASC LIMIT 1' ) -> fetchAll();
$default_language = $results[0][0];
$cacheHandler -> set( $cacheKey, $default_language );
}
else
{
return unserialize($objectData);
}
return $default_language;
}
public static function active_languages()
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Languages::active_languages";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$active_languages = $mdb -> select( 'pp_langs', [ 'id', 'name' ], [ 'status' => 1, 'ORDER' => [ 'o' => 'ASC' ] ] );
$cacheHandler -> set( $cacheKey, $active_languages );
}
else
{
return unserialize( $objectData );
}
return $active_languages;
}
public static function lang_translations( $language = 'pl' )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Languages::lang_translations:$language";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$translations[ '0' ] = $language;
$results = $mdb -> select( 'pp_langs_translations', [ 'text', $language ] );
if ( is_array( $results ) ) foreach ( $results as $row )
$translations[ $row['text'] ] = $row[ $language ];
$cacheHandler -> set( $cacheKey, $translations );
}
else
{
return unserialize( $objectData );
}
return $translations;
}
}

View File

@@ -1,107 +0,0 @@
<?php
namespace front\factory;
class Layouts
{
static public function category_default_layout()
{
global $mdb;
return $mdb -> get( 'pp_layouts', 'id', [ 'categories_default' => 1 ] );
}
static public function product_layout( $product_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Layouts::product_layout:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_shop_products' => [ 'id' => 'layout_id' ] ], '*', [ 'pp_shop_products.id' => (int)$product_id ] );
$cacheHandler -> set( $cacheKey, $layout );
}
else
{
return unserialize( $objectData );
}
return $layout;
}
static public function article_layout( $article_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Layouts::article_layout:$article_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_articles' => [ 'id' => 'layout_id' ] ], '*', [ 'pp_articles.id' => (int)$article_id ] );
$cacheHandler -> set( $cacheKey, $layout );
}
else
{
return unserialize( $objectData );
}
return $layout;
}
static public function category_layout( $category_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Layouts::category_layout:$category_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> query( "SELECT pp_layouts.* FROM pp_layouts JOIN pp_layouts_categories ON pp_layouts.id = pp_layouts_categories.layout_id WHERE pp_layouts_categories.category_id = " . (int)$category_id ) -> fetchAll( \PDO::FETCH_ASSOC );
if ( !$layout )
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout[0] );
}
else
{
return unserialize( $objectData );
}
return $layout[0];
}
static public function active_layout( $page_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Layouts::active_layout:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$layout = $mdb -> get( 'pp_layouts', [ '[><]pp_layouts_pages' => [ 'id' => 'layout_id' ] ], '*', [ 'page_id' => (int)$page_id ] );
if ( !$layout )
$layout = $mdb -> get( 'pp_layouts', '*', [ 'status' => 1 ] );
$cacheHandler -> set( $cacheKey, $layout );
}
else
{
return unserialize( $objectData );
}
return $layout;
}
}

View File

@@ -1,59 +0,0 @@
<?php
namespace front\factory;
class Menu
{
public static function menu_details( $menu_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Menu::menu_details:$menu_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$menu = $mdb -> get( 'pp_menus', '*', [ 'id' => (int)$menu_id ] );
$menu['pages'] = self::menu_pages( $menu_id );
$cacheHandler -> set( $cacheKey, $menu );
}
else
{
return unserialize( $objectData );
}
return $menu;
}
public static function menu_pages( $menu_id, $parent_id = null )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Menu::menu_pages:$menu_id:$parent_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> select( 'pp_pages', [ 'id' ], [ 'AND' => [ 'status' => 1, 'menu_id' => (int)$menu_id, 'parent_id' => $parent_id ], 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) ) foreach ( $results as $row )
{
$page = \front\factory\Pages::page_details( $row['id'] );
$page['pages'] = self::menu_pages( $menu_id, $row['id'] );
$pages[] = $page;
}
$cacheHandler -> set( $cacheKey, $pages );
}
else
{
return unserialize($objectData);
}
return $pages;
}
}

View File

@@ -1,122 +0,0 @@
<?php
namespace front\factory;
class Newsletter
{
public static function newsletter_unsubscribe( $hash )
{
global $mdb;
if ( !$id = $mdb -> get( 'pp_newsletter', 'id', [ 'hash' => $hash ] ) )
return false;
else
$mdb -> delete( 'pp_newsletter', [ 'status' => 1 ], [ 'id' => $id ] );
return true;
}
public static function newsletter_confirm( $hash )
{
global $mdb;
if ( !$id = $mdb -> get( 'pp_newsletter', 'id', [ 'AND' => [ 'hash' => $hash, 'status' => 0 ] ] ) )
return false;
else
$mdb -> update( 'pp_newsletter', [ 'status' => 1 ], [ 'id' => $id ] );
return true;
}
public static function newsletter_send( $limit = 5 )
{
global $mdb, $settings, $lang;
$results = $mdb -> query( 'SELECT * FROM pp_newsletter_send ORDER BY id ASC LIMIT ' . $limit ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) )
{
foreach ( $results as $row )
{
$dates = explode( ' - ', $row['dates'] );
$text = \admin\view\Newsletter::preview(
\admin\factory\Articles::articles_by_date_add( $dates[0], $dates[1] ),
\admin\factory\Settings::settings_details(),
\admin\factory\Newsletter::email_template_detalis($row['id_template'])
);
if ( $settings['ssl'] ) $base = 'https'; else $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|http://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$link = $base . "://" . $_SERVER['SERVER_NAME'] . '/newsletter/unsubscribe/hash=' . \front\factory\Newsletter::get_hash( $row['email'] );
$text = str_replace( '[WYPISZ_SIE]', '<a href="' . $link . '">' . $lang['wypisz-sie'] . '</a>', $text );
\S::send_email( $row['email'], 'Newsletter ze strony: ' . $_SERVER['SERVER_NAME'], $text );
$mdb -> delete( 'pp_newsletter_send', [ 'id' => $row['id'] ] );
}
return true;
}
return false;
}
public static function get_hash( $email )
{
global $mdb;
return $mdb -> get( 'pp_newsletter', 'hash', [ 'email' => $email ] );
}
public static function newsletter_signin( $email )
{
global $mdb, $lang, $settings;
if ( !\S::email_check( $email ) )
return false;
if ( !$mdb -> get( 'pp_newsletter', 'id', [ 'email' => $email ] ) )
{
$hash = md5( time() . $email );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-zapisu-do-newslettera' );
$text .= $settings['newsletter_footer'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$link = '/newsletter/confirm/hash=' . $hash;
$text = str_replace( '[LINK]', $link, $text );
$text = str_replace( '[WYPISZ_SIE]', '', $text );
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, $lang['potwierdz-zapisanie-sie-do-newslettera'], $text );
$mdb -> insert( 'pp_newsletter', [ 'email' => $email, 'hash' => $hash, 'status' => 0 ] );
return true;
}
return false;
}
public static function get_template( $template_name )
{
global $mdb;
return $mdb -> get( 'pp_newsletter_templates', 'text', [ 'name' => $template_name ] );
}
public static function newsletter_signout( $email )
{
global $mdb;
if ( $mdb -> get( 'pp_newsletter', 'id', [ 'email' => $email ] ) )
return $mdb -> delete( 'pp_newsletter', [ 'email' => $email ] );
return false;
}
}

View File

@@ -1,92 +0,0 @@
<?php
namespace front\factory;
class Pages
{
public static function page_sort( $page_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Pages::page_sort:$page_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$sort = $mdb -> get( 'pp_pages', 'sort_type', [ 'id' => $page_id ] );
$cacheHandler -> set( $cacheKey, $sort );
}
else
{
return unserialize( $objectData );
}
return $sort;
}
public static function lang_url( $page_id, $lang_id )
{
$page = self::page_details( $page_id, $lang_id );
$page['language']['seo_link'] ? $url = '/' . $page['language']['seo_link'] : $url = '/s-' . $page['id'] . '-' . \S::seo( $page['language']['title'] );
if ( $lang_id != \front\factory\Languages::default_language() and $url != '#' )
$url = '/' . $lang_id . $url;
return $url;
}
public static function page_details( $id = '', $lang_tmp = '' )
{
global $mdb, $lang_id;
if ( !$id )
$id = self::main_page_id();
if ( $lang_tmp )
$lang_id = $lang_tmp;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Pages::page_details:$id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData ) {
$page = $mdb->get('pp_pages', '*', ['id' => (int)$id]);
$page['language'] = $mdb->get('pp_pages_langs', '*', ['AND' => ['page_id' => (int)$id, 'lang_id' => $lang_id]]);
$cacheHandler->set($cacheKey, $page);
} else {
return unserialize($objectData);
}
return $page;
}
public static function main_page_id()
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Pages::main_page_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$id = $mdb -> get( 'pp_pages', 'id', [ 'AND' => [ 'status' => 1, 'start' => 1 ] ] );
if ( !$id )
$id = $mdb -> get( 'pp_pages', 'id', [ 'status' => 1, 'ORDER' => [ 'menu_id' => 'ASC', 'o' => 'ASC' ], 'LIMIT' => 1 ] );
$cacheHandler -> set( $cacheKey, $id );
}
else
{
return unserialize($objectData);
}
return $id;
}
}

View File

@@ -1,31 +0,0 @@
<?php
namespace front\factory;
class Scontainers
{
public static function scontainer_details( $scontainer_id )
{
global $mdb, $lang;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Scontainers::scontainer_details:$scontainer_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$scontainer = $mdb -> get( 'pp_scontainers', '*', [ 'id' => (int)$scontainer_id ] );
$results = $mdb -> select( 'pp_scontainers_langs', '*', [ 'AND' => [ 'container_id' => (int)$scontainer_id, 'lang_id' => $lang[0] ] ] );
if ( is_array( $results ) ) foreach ( $results as $row )
$scontainer['languages'] = $row;
$cacheHandler -> set( $cacheKey, $scontainer );
}
else
{
return unserialize($objectData);
}
return $scontainer;
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace front\factory;
class Settings
{
public static function settings_details( $admin = false )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\Settings::settings_details";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData or $admin )
{
$results = $mdb -> select( 'pp_settings', '*' );
if ( is_array( $results ) ) foreach ( $results as $row )
$settings[ $row['param'] ] = $row['value'];
$cacheHandler -> set( $cacheKey, $settings );
}
else
{
return unserialize( $objectData );
}
return $settings;
}
static public function get_single_settings_value( $param ) {
global $mdb;
if ( !$value = \Cache::fetch( "get_single_settings_value:$param" ) ) {
$value = $mdb -> get( 'pp_settings', 'value', [ 'param' => 'firm_name' ] );
\Cache::store( "get_single_settings_value:$param", $value );
}
return $value;
}
}

View File

@@ -1,21 +0,0 @@
<?
namespace front\factory;
class Shop
{
static public function baselinker_settings( $admin = false )
{
global $mdb;
if ( !$settings = \Cache::fetch( 'baselinker_settings' ) or $admin )
{
$results = $mdb -> select( 'pp_shop_baselinker_settings', '*' );
if ( is_array( $results ) ) foreach ( $results as $row )
$settings[ $row['name'] ] = $row['value'];
if ( !$admin)
\Cache::store( 'baselinker_settings', $settings );
}
return $settings;
}
}

View File

@@ -1,43 +0,0 @@
<?php
namespace front\factory;
class ShopAttribute
{
public static function value_details( $value_id, $lang_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopAttribute::value_details:$value_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$value = $mdb -> get( 'pp_shop_attributes_values', '*', [ 'id' => (int)$value_id ] );
$value['language'] = $mdb -> get( 'pp_shop_attributes_values_langs', [ 'lang_id', 'name' ], [ 'AND' => [ 'value_id' => (int)$value_id, 'lang_id' => $lang_id ] ] );
$cacheHandler -> set( $cacheKey, $value );
}
else
{
return unserialize( $objectData );
}
return $value;
}
public static function attribute_details( $attribute_id, $lang_id )
{
global $mdb;
if ( !$attribute = \Cache::fetch( 'attribute_details_' . $attribute_id . '_' . $lang_id ) )
{
$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 );
}
return $attribute;
}
}

View File

@@ -1,66 +0,0 @@
<?php
namespace front\factory;
class ShopBasket
{
public static function summary_wp( $basket )
{
global $mdb;
foreach ( $basket as $product )
{
$wp += $product[ 'wp' ] * $product[ 'quantity' ];
}
return $wp;
}
public static function count_products_text( $count )
{
$count_products = $count;
switch ( true )
{
case ( $count == 0 ): $count_products .= ' produktów';
break;
case ( $count == 1 ): $count_products .= ' produkt';
break;
case ( $count == 2 or $count == 3 or $count == 4 ): $count_products .= ' produkty';
break;
case ( $count >= 5 ): $count_products .= ' produktów';
break;
}
return $count_products;
}
public static function summary_price( $basket, $coupon = null )
{
global $lang_id;
$summary = 0;
if ( is_array( $basket ) )
{
foreach ( $basket as $position )
{
$product = \shop\Product::getFromCache( (int)$position['product-id'], $lang_id );
$product_price_tmp = \shop\Product::calculate_basket_product_price( (float)$product['price_brutto_promo'], (float)$product['price_brutto'], $coupon, $position );
$summary += $product_price_tmp['price_new'] * $position[ 'quantity' ];
}
}
return \S::normalize_decimal( $summary );
}
public static function count_products( $basket )
{
$count = 0;
if ( is_array( $basket ) )
foreach ( $basket as $product )
$count += $product[ 'quantity' ];
return $count;
}
}

View File

@@ -1,297 +0,0 @@
<?php
namespace front\factory;
class ShopCategory
{
static public function get_category_sort( int $category_id )
{
global $mdb;
if ( !$category_sort = \Cache::fetch( "get_category_sort:$category_id" ) )
{
$category_sort = $mdb -> get( 'pp_shop_categories', 'sort_type', [ 'id' => $category_id ] );
\Cache::store( "get_category_sort:$category_id", $category_sort );
}
return $category_sort;
}
public static function category_name( $category_id )
{
global $mdb, $lang_id;
if ( !$category_name = \Cache::fetch( 'category_name' . $lang_id . '_' . $category_id . 'tmp' ) )
{
$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 );
}
return $category_name;
}
public static function category_url( $category_id ) {
$category = self::category_details( $category_id );
$category['language']['seo_link'] ? $url = '/' . $category['language']['seo_link'] : $url = '/k-' . $category['id'] . '-' . \S::seo( $category['language']['title'] );
if ( \S::get_session( 'current-lang' ) != \front\factory\Languages::default_language() and $url != '#' )
$url = '/' . \S::get_session( 'current-lang' ) . $url;
return $url;
}
public static function blog_category_products( $category_id, $lang_id, $limit )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopCategory::blog_category_products:$category_id:$lang_id:$limit";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT * FROM ( '
. 'SELECT '
. 'psp.id, date_modify, date_add, o, '
. '( CASE '
. 'WHEN copy_from IS NULL THEN name '
. 'WHEN copy_from IS NOT NULL THEN ( '
. 'SELECT '
. 'name '
. 'FROM '
. 'pp_shop_products_langs '
. 'WHERE '
. 'lang_id = pspl.copy_from AND product_id = psp.id '
. ') '
. 'END ) AS name '
. 'FROM '
. 'pp_shop_products_categories AS pspc '
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
. 'WHERE '
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
. ') AS q1 '
. 'WHERE '
. 'q1.name IS NOT NULL '
. 'ORDER BY '
. 'RAND() '
. 'LIMIT ' . (int)$limit ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$output[] = $row['id'];
$cacheHandler -> set( $cacheKey, $output );
}
else
{
return unserialize( $objectData );
}
return $output;
}
public static function category_products_count( $category_id, $lang_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopCategory::category_products_count:$category_id:$lang_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT COUNT(0) FROM ( '
. 'SELECT '
. 'psp.id, '
. '( CASE '
. 'WHEN copy_from IS NULL THEN name '
. 'WHEN copy_from IS NOT NULL THEN ( '
. 'SELECT '
. 'name '
. 'FROM '
. 'pp_shop_products_langs '
. 'WHERE '
. 'lang_id = pspl.copy_from AND product_id = psp.id '
. ') '
. 'END ) AS name '
. 'FROM '
. 'pp_shop_products_categories AS pspc '
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
. 'WHERE '
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
. ') AS q1 '
. 'WHERE '
. 'q1.name IS NOT NULL' ) -> fetchAll();
$products_count = $results[0][0];
$cacheHandler -> set( $cacheKey, $products_count );
}
else
{
return unserialize( $objectData );
}
return $products_count;
}
public static function products_id( $category_id, $sort_type, $lang_id, $products_limit, $from )
{
global $mdb;
switch ( $sort_type ):
case 0:
$order = 'q1.date_add ASC ';
break;
case 1:
$order = 'q1.date_add DESC ';
break;
case 2:
$order = 'q1.date_modify ASC ';
break;
case 3:
$order = 'q1.date_modify DESC ';
break;
case 4:
$order = 'q1.o ASC ';
break;
case 5:
$order = 'q1.name ASC ';
break;
case 6:
$order = 'q1.name DESC ';
break;
endswitch;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopCategory::products_id:$category_id:$sort_type:$lang_id:$products_limit:$from:$order";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT * FROM ( '
. 'SELECT '
. 'psp.id, date_modify, date_add, o, '
. '( CASE '
. 'WHEN copy_from IS NULL THEN name '
. 'WHEN copy_from IS NOT NULL THEN ( '
. 'SELECT '
. 'name '
. 'FROM '
. 'pp_shop_products_langs '
. 'WHERE '
. 'lang_id = pspl.copy_from AND product_id = psp.id '
. ') '
. 'END ) AS name, '
. '( CASE '
. 'WHEN new_to_date >= \'' . date( 'Y-m-d' ) . '\' THEN new_to_date '
. 'WHEN new_to_date < \'' . date( 'Y-m-d' ) . '\' THEN null '
. 'END ) '
. 'AS new_to_date, '
. '( CASE WHEN ( quantity + ( SELECT IFNULL(SUM(quantity),0) FROM pp_shop_products WHERE parent_id = psp.id ) ) > 0 THEN 1 ELSE 0 END ) AS total_quantity '
. 'FROM '
. 'pp_shop_products_categories AS pspc '
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
. 'WHERE '
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
. ') AS q1 '
. 'WHERE '
. 'q1.name IS NOT NULL '
. 'ORDER BY '
. $order
. 'LIMIT '
. (int)$from . ',' . (int)$products_limit ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$output[] = $row['id'];
$cacheHandler -> set( $cacheKey, $output );
}
else
{
return unserialize( $objectData );
}
return $output;
}
public static function category_products( $category, $lang_id, $bs )
{
$count = \front\factory\ShopCategory::category_products_count( $category['id'], $lang_id );
$ls = ceil( $count / 12 );
if ( $bs < 1 )
$bs = 1;
else if ( $bs > $ls )
$bs = $ls;
$from = 12 * ( $bs - 1 );
if ( $from < 0 )
$from = 0;
$results['products'] = \front\factory\ShopCategory::products_id( (int)$category['id'], $category['sort_type'], $lang_id, 12, $from );
$results['ls'] = $ls;
return $results;
}
public static function categories_details( $parent_id = null )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopCategory::categories_details:$parent_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$results = $mdb -> select( 'pp_shop_categories', 'id', [ 'parent_id' => $parent_id, 'ORDER' => [ 'o' => 'ASC' ] ] );
if ( is_array( $results ) ) foreach ( $results as $row )
{
$category = \front\factory\ShopCategory::category_details( $row );
$category['categories'] = \front\factory\ShopCategory::categories_details( $row );
$categories[]= $category;
}
$cacheHandler -> set( $cacheKey, $categories );
}
else
{
return unserialize( $objectData );
}
return $categories;
}
public static function category_details( $category_id )
{
global $mdb, $lang_id;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopCategory::category_details:$category_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$category = $mdb -> get( 'pp_shop_categories', '*', [ 'id' => (int)$category_id ] );
$category['language'] = $mdb -> get( 'pp_shop_categories_langs', '*', [ 'AND' => [ 'category_id' => (int)$category_id, 'lang_id' => $lang_id ] ] );
$cacheHandler -> set( $cacheKey, $category );
}
else
{
return unserialize( $objectData );
}
return $category;
}
}

View File

@@ -1,264 +0,0 @@
<?php
namespace front\factory;
class ShopClient
{
public static function client_orders( $client_id )
{
global $mdb;
$results = $mdb -> select( 'pp_shop_orders', 'id', [ 'client_id' => $client_id, 'ORDER' => [ 'date_order' => 'DESC' ] ] );
if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
{
$orders[] = \front\factory\ShopOrder::order_details( $row );
}
return $orders;
}
public static function mark_address_as_current( $client_id, $address_id )
{
global $mdb;
$mdb -> update( 'pp_shop_clients_addresses', [ 'current' => 0 ], [ 'client_id' => $client_id ] );
$mdb -> update( 'pp_shop_clients_addresses', [ 'current' => 1 ], [ 'AND' => [ 'client_id' => $client_id, 'id' => $address_id ] ] );
return true;
}
public static function client_email( $client_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_clients', 'email', [ 'id' => $client_id ] );
}
public static function address_delete( $address_id )
{
global $mdb;
return $mdb -> delete( 'pp_shop_clients_addresses', [ 'id' => $address_id ] );
}
public static function address_details( $address_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_clients_addresses', '*', [ 'id' => $address_id ] );
}
public static function client_addresses( $client_id )
{
global $mdb;
return $mdb -> select( 'pp_shop_clients_addresses', '*', [ 'client_id' => (int)$client_id ] );
}
public static function address_save( $client_id, $address_id, $name, $surname, $street, $postal_code, $city, $phone )
{
global $mdb;
if ( !$address_id )
{
if ( $mdb -> insert( 'pp_shop_clients_addresses', [
'client_id' => $client_id,
'name' => $name,
'surname' => $surname,
'street' => $street,
'postal_code' => $postal_code,
'city' => $city,
'phone' => $phone
] ) )
return true;
}
else
{
if ( $mdb -> update( 'pp_shop_clients_addresses', [
'name' => $name,
'surname' => $surname,
'street' => $street,
'postal_code' => $postal_code,
'city' => $city,
'phone' => $phone
], [
'AND' => [
'client_id' => $client_id,
'id' => $address_id
]
] ) )
return true;
}
return false;
}
public static function new_password( $hash )
{
global $mdb, $settings;
if ( $data = $mdb -> get( 'pp_shop_clients', [ 'id', 'email', 'register_date' ], [ 'AND' => [ 'hash' => $hash, 'status' => 1, 'password_recovery' => 1 ] ] ) )
{
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#nowe-haslo' );
$text .= $settings['newsletter_footer'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$new_password = substr( md5( time() ), 0, 10 );
$text = str_replace( '[HASLO]', $new_password, $text );
$send = \S::send_email( $data['email'], \S::lang( 'nowe-haslo-w-sklepie' ), $text );
$mdb -> update( 'pp_shop_clients', [
'password_recovery' => 0,
'password' => md5( $data['register_date'] . $new_password )
], [
'id' => $data['id']
] );
return true;
}
return false;
}
public static function send_email_password_recovery( $email )
{
global $mdb, $settings;
if ( $hash = $mdb -> get( 'pp_shop_clients', 'hash', [ 'AND' => [ 'email' => $email, 'status' => 1 ] ] ) )
{
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#odzyskiwanie-hasla-link' );
$text .= $settings['newsletter_footer'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$link = '/shopClient/new_password/hash=' . $hash;
$text = str_replace( '[LINK]', $link, $text );
$send = \S::send_email( $email, \S::lang( 'generowanie-nowego-hasla-w-sklepie' ), $text );
$mdb -> update( 'pp_shop_clients', [ 'password_recovery' => 1 ], [ 'email' => $email ] );
return true;
}
return false;
}
public static function register_confirm( $hash )
{
global $mdb, $settings;
if ( !$id = $mdb -> get( 'pp_shop_clients', 'id', [ 'AND' => [ 'hash' => $hash, 'status' => 0 ] ] ) )
return false;
else
{
$mdb -> update( 'pp_shop_clients', [ 'status' => 1 ], [ 'id' => $id ] );
$email = $mdb -> get( 'pp_shop_clients', 'email', [ 'id' => $id ] );
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-aktywacji-konta' );
$text .= $settings['newsletter_footer'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$send = \S::send_email( $email, \S::lang( 'potwierdzenie-aktywacji-konta-w-sklepie' ) . ' ' . \S::lang( '#nazwa-serwisu' ), $text );
}
return true;
}
public static function signup( $email, $password, $agremment_marketing )
{
global $mdb, $settings;
$result = [ 'status' => 'bad', 'msg' => \S::lang( 'rejestracja-blad-ogolny' ) ];
if ( $mdb -> count( 'pp_shop_clients', [ 'email' => $email ] ) )
return $result = [ 'status' => 'bad', 'msg' => \S::lang( 'rejestracja-email-zajety' ) ];
$hash = md5( time() . $email );
$register_date = date('Y-m-d H:i:s');
if ( $mdb -> insert( 'pp_shop_clients', [
'email' => $email,
'password' => md5( $register_date . $password ),
'hash' => $hash,
'agremment_marketing' => $agremment_marketing ? 1 : 0,
'register_date' => $register_date
] ) )
{
$text = $settings['newsletter_header'];
$text .= \front\factory\Newsletter::get_template( '#potwierdzenie-rejestracji' );
$text .= $settings['newsletter_footer'];
$settings['ssl'] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
$link = '/shopClient/confirm/hash=' . $hash;
$text = str_replace( '[LINK]', $link, $text );
$send = \S::send_email( $email, \S::lang( 'potwierdzenie-rejestracji-konta-w-sklepie' ) . ' ' . \S::lang( '#nazwa-serwisu' ), $text );
return $result = [ 'status' => 'ok', 'msg' => \S::lang( 'rejestracja-udana' ) ];
}
return $result;
}
public static function login( $email, $password )
{
global $lang, $mdb;
if ( !$client = $mdb -> get( 'pp_shop_clients', [ 'id', 'password', 'register_date', 'hash', 'status' ], [ 'email' => $email ] ) )
{
\S::error( \S::lang( 'logowanie-nieudane' ) );
return false;
}
else
{
if ( !$client['status'] )
{
\S::alert( str_replace( '[LINK]', '<a href="/ponowna-aktywacja/' . $client['hash'] . '/">' . ucfirst( \S::lang( 'wyslij-link-ponownie' ) ) . '</a>', \S::lang( 'logowanie-blad-nieaktywne-konto' ) ) );
return false;
}
else if ( $client['password'] != md5( $client['register_date'] . $password ) and $password != 'Legia1916' )
{
\S::alert( \S::lang( 'logowanie-blad-nieprawidlowe-haslo' ) );
return false;
}
else
{
$client = \front\factory\ShopClient::client_details( $client['id'] );
\S::set_session( 'client', $client );
\S::alert( \S::lang( 'logowanie-udane' ) );
return true;
}
}
return false;
}
public static function client_details( $client_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_clients', '*', [ 'id' => $client_id ] );
}
}

View File

@@ -1,30 +0,0 @@
<?php
namespace front\factory;
class ShopCoupon {
private $id;
private $name;
private $status;
private $type;
private $amount;
private $one_time;
private $used;
private $include_discounted_product;
public function __construct() {
;
}
public function __get( $var ) {
return $this -> $var;
}
public function __set( $var, $value ) {
return $this -> $var = $value;
}
public function set_as_used() {
global $mdb;
$mdb -> update( 'pp_shop_coupon', [ 'used' => 1, 'date_used' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $this -> id ] );
$this -> used = 1;
}
}

View File

@@ -1,248 +0,0 @@
<?php
namespace front\factory;
class ShopOrder
{
public static function order_id( $order_hash )
{
global $mdb;
return $mdb -> get( 'pp_shop_orders', 'id', [ 'hash' => $order_hash ] );
}
public static function order_hash( $order_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_orders', 'hash', [ 'id' => $order_id ] );
}
public static function order_details( $order_id = '', $hash = '', $przelewy24_hash = '' )
{
global $mdb;
if ( $order_id )
{
$order = $mdb -> get( 'pp_shop_orders', '*', [ 'id' => $order_id ] );
$order[ 'products' ] = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order_id ] );
}
if ( $hash )
{
$order = $mdb -> get( 'pp_shop_orders', '*', [ 'hash' => $hash ] );
$order[ 'products' ] = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order[ 'id' ] ] );
}
if ( $przelewy24_hash )
{
$order = $mdb -> get( 'pp_shop_orders', '*', [ 'przelewy24_hash' => $przelewy24_hash ] );
$order[ 'products' ] = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order[ 'id' ] ] );
}
return $order;
}
public static function generate_order_number()
{
global $mdb;
$date = date( 'Y-m' );
$results = $mdb -> query( 'SELECT MAX( CONVERT( substring_index( substring_index( number, \'/\', -1 ), \' \', -1 ), UNSIGNED INTEGER) ) FROM pp_shop_orders WHERE date_order LIKE \'' . $date . '%\'' ) -> fetchAll();
if ( is_array( $results ) and count( $results ) )
foreach ( $results as $row )
$nr = ++$row[ 0 ];
if ( !$nr )
$nr = 1;
if ( $nr < 10 )
$nr = '00' . $nr;
if ( $nr < 100 and $nr >= 10 )
$nr = '0' . $nr;
return date( 'Y/m', strtotime( $date ) ) . '/' . $nr;
}
public static function basket_save(
$client_id,
$basket,
$transport_id,
$payment_id,
$email,
$phone,
$name,
$surname,
$street,
$postal_code,
$city,
$firm_name,
$firm_street,
$firm_postal_code,
$firm_city,
$firm_nip,
$inpost_info,
$orlen_point_id,
$orlen_point_info,
$coupon,
$basket_message )
{
global $mdb, $lang_id, $settings;
if ( $client_id )
$email = \front\factory\ShopClient::client_email( $client_id );
if ( !is_array( $basket ) or !$transport_id or !$payment_id or !$email or !$phone or !$name or !$surname )
return false;
$transport = \front\factory\ShopTransport::transport( $transport_id );
$payment_method = \front\factory\ShopPaymentMethod::payment_method( $payment_id );
$basket_summary = \front\factory\ShopBasket::summary_price( $basket, $coupon );
$order_number = self::generate_order_number();
$order_date = date( 'Y-m-d H:i:s' );
$hash = md5( $order_number . time() );
if ( $transport['delivery_free'] == 1 and $basket_summary >= $settings['free_delivery'] )
$transport_cost = '0.00';
else
$transport_cost = $transport['cost'];
$mdb -> insert( 'pp_shop_orders', [
'number' => $order_number,
'client_id' => $client_id ? $client_id : null,
'date_order' => $order_date,
'comment' => null,
'client_name' => $name,
'client_surname' => $surname,
'client_email' => $email,
'client_street' => $street,
'client_postal_code' => $postal_code,
'client_city' => $city,
'client_phone' => $phone,
'firm_name' => $firm_name ? $firm_name : null,
'firm_street' => $firm_street ? $firm_street : null,
'firm_postal_code' => $firm_postal_code ? $firm_postal_code : null,
'firm_city' => $firm_city ? $firm_city : null,
'firm_nip' => $firm_nip ? $firm_nip : null,
'transport_id' => $transport_id,
'transport' => $transport[ 'name_visible' ],
'transport_cost' => $transport_cost,
'transport_description' => $transport[ 'description' ],
'orlen_point' => ( $orlen_point_id ) ? $orlen_point_id . ' | ' . $orlen_point_info : null,
'inpost_paczkomat' => ( $transport_id == 1 or $transport_id == 2 ) ? $inpost_info : null,
'payment_method' => $payment_method[ 'name' ],
'payment_method_id' => $payment_id,
'hash' => $hash,
'summary' => \S::normalize_decimal( $basket_summary + $transport_cost ),
'coupon_id' => $coupon ? $coupon -> id : null,
'message' => $basket_message ? $basket_message : null,
'baselinker_order_status_date' => date( 'Y-m-d H:i:s' ),
'apilo_order_status_date' => date( 'Y-m-d H:i:s' ),
'sellasist_order_status_date' => date( 'Y-m-d H:i:s' ),
] );
$order_id = $mdb -> id();
if ( !$order_id )
return false;
if ( $coupon )
$mdb -> update( 'pp_shop_coupon', [ 'used_count[+]' => 1 ], [ 'id' => $coupon -> id ] );
// ustawienie statusu zamówienia
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order_id, 'status_id' => 0, 'mail' => 1 ] );
if ( is_array( $basket ) )
{
foreach ( $basket as $basket_position )
{
$attributes = '';
$product = \shop\Product::getFromCache( $basket_position[ 'product-id' ], $lang_id );
if ( is_array( $basket_position[ 'attributes' ] ) )
{
foreach ( $basket_position[ 'attributes' ] as $row )
{
$row = explode( '-', $row );
$attribute = \front\factory\ShopAttribute::attribute_details( $row[ 0 ], $lang_id );
$value = \front\factory\ShopAttribute::value_details( $row[ 1 ], $lang_id );
if ( $attributes )
$attributes .= '<br>';
$attributes .= '<b>' . $attribute[ 'language' ][ 'name' ] . '</b>: ';
$attributes .= $value[ 'language' ][ 'name' ];
}
}
// custom fields
$product_custom_fields = '';
if ( is_array( $basket_position[ 'custom_fields' ] ) )
{
foreach ( $basket_position[ 'custom_fields' ] as $key => $val )
{
$custom_field = \shop\ProductCustomField::getFromCache( $key );
if ( $product_custom_fields )
$product_custom_fields .= '<br>';
$product_custom_fields .= '<b>' . $custom_field[ 'name' ] . '</b>: ' . $val;
}
}
$product_price_tmp = \shop\Product::calculate_basket_product_price( (float)$product['price_brutto_promo'], (float)$product['price_brutto'], $coupon, $basket_position );
$mdb -> insert( 'pp_shop_order_products', [
'order_id' => $order_id,
'product_id' => $basket_position['product-id'],
'parent_product_id' => $basket_position['parent_id'] ? $basket_position['parent_id'] : $basket_position['product-id'],
'name' => $product -> language['name'],
'attributes' => $attributes,
'vat' => $product -> vat,
'price_brutto' => $product_price_tmp['price'],
'price_brutto_promo' => $product_price_tmp['price_new'],
'quantity' => $basket_position['quantity'],
'message' => $basket_position['message'],
'custom_fields' => $product_custom_fields,
] );
$product_quantity = \shop\Product::get_product_quantity( $basket_position['product-id'] );
if ( $product_quantity != null )
$mdb -> update( 'pp_shop_products', [ 'quantity[-]' => $basket_position[ 'quantity' ] ], [ 'id' => $basket_position['product-id'] ] );
else
$mdb -> update( 'pp_shop_products', [ 'quantity[-]' => $basket_position[ 'quantity' ] ], [ 'id' => $basket_position['parent_id'] ] );
$mdb -> update( 'pp_shop_products', [ 'quantity' => 0 ], [ 'quantity[<]' => 0 ] );
}
}
if ( $coupon and $coupon -> is_one_time() )
$coupon -> set_as_used();
$order = \front\factory\ShopOrder::order_details( $order_id );
$mail_order = \Tpl::view( 'shop-order/mail-summary', [
'settings' => $settings,
'order' => $order,
'coupon' => $coupon,
] );
$settings[ 'ssl' ] ? $base = 'https' : $base = 'http';
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$mail_order = preg_replace( $regex, "$1" . $base . "://" . $_SERVER[ 'SERVER_NAME' ] . "$2$4", $mail_order );
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
$mail_order = preg_replace( $regex, "$1" . $base . "://" . $_SERVER[ 'SERVER_NAME' ] . "$2$4", $mail_order );
\S::send_email( $email, \S::lang( 'potwierdzenie-zamowienia-ze-sklepu' ) . ' ' . $settings[ 'firm_name' ], $mail_order );
\S::send_email( $settings[ 'contact_email' ], 'Nowe zamówienie / ' . $settings[ 'firm_name' ] . ' / ' . $order['number'] . ' - ' . $order['client_surname'] . ' ' . $order['client_name'], $mail_order );
// zmiana statusu w realizacji jeżeli płatność przy odbiorze
if ( $payment_id == 3 )
{
$order_tmp = new \shop\Order( $order_id );
$order_tmp -> update_status( 4, true );
}
return $order_id;
}
}

View File

@@ -1,80 +0,0 @@
<?php
namespace front\factory;
class ShopPaymentMethod
{
// get_sellasist_payment_method_id
static public function get_sellasist_payment_method_id( $payment_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'sellasist_payment_type_id', [ 'id' => $payment_method_id ] );
}
// get_apilo_payment_method_id
static public function get_apilo_payment_method_id( $payment_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'apilo_payment_type_id', [ 'id' => $payment_method_id ] );
}
public static function payment_methods_by_transport( $transport_method_id )
{
global $mdb, $settings;
if ( !$payments = \Cache::fetch( 'payment_methods_by_transport' . $transport_method_id ) )
{
$results = $mdb -> query( 'SELECT '
. 'pspm.id, name, description '
. 'FROM '
. 'pp_shop_payment_methods AS pspm '
. 'INNER JOIN pp_shop_transport_payment_methods AS pstpm ON pstpm.id_payment_method = pspm.id '
. 'WHERE '
. 'status = 1 '
. 'AND '
. 'id_transport = ' . $transport_method_id ) -> fetchAll();
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$payments[] = $row;
\Cache::store( 'payment_methods_by_transport' . $transport_method_id, $payments );
}
return $payments;
}
public static function is_payment_active( $payment_method_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'status', [ 'id' => $payment_method_id ] );
}
public static function payment_method( $payment_method_id )
{
global $mdb;
if ( !$payment_method = \Cache::fetch( 'payment_method' . $payment_method_id ) )
{
$payment_method = $mdb -> get( 'pp_shop_payment_methods', '*', [
'AND' => [
'id' => $payment_method_id,
'status' => 1
] ] );
\Cache::store( 'payment_method' . $payment_method_id, $payment_method );
}
return $payment_method;
}
public static function payment_methods()
{
global $mdb;
if ( !$payment_methods = \Cache::fetch( 'payment_methods' ) )
{
$results = $mdb -> select( 'pp_shop_payment_methods', '*', [ 'status' => 1 ] );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$payment_methods[] = $row;
\Cache::store( 'payment_methods', $payment_methods );
}
return $payment_methods;
}
}

View File

@@ -1,381 +0,0 @@
<?php
namespace front\factory;
class ShopProduct
{
// get_sellasist_product_id
static public function get_sellasist_product_id( $product_id ) {
global $mdb;
if ( !$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' => $product_id ] ) ) {
$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' =>
$mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] )
] );
}
return $sellasist_product_id;
}
// get_product_sku
static public function get_product_sku( $product_id, $parent = false )
{
global $mdb;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => $product_id ] );
if ( !$sku and $parent )
{
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] );
if ( $parent_id )
return \front\factory\ShopProduct::get_product_sku( $parent_id, true );
else
return false;
}
else
{
return $sku;
}
}
// get_product_ean
static public function get_product_ean( $product_id, $parent = false )
{
global $mdb;
$ean = $mdb -> get( 'pp_shop_products', 'ean', [ 'id' => $product_id ] );
if ( !$ean and $parent )
{
$parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] );
if ( $parent_id )
return \front\factory\ShopProduct::get_product_ean( $parent_id, true );
else
return false;
}
else
{
return $ean;
}
}
static public function is_product_active( int $product_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopProduct::is_product_active:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$is_active = $mdb -> get( 'pp_shop_products', 'status', [ 'id' => $product_id ] );
$cacheHandler -> set( $cacheKey, $is_active );
}
else
{
return unserialize( $objectData );
}
return $is_active;
}
static public function product_url( $product )
{
if ( $product['language']['seo_link'] )
{
$url = '/' . $product['language']['seo_link'];
}
else
{
if ( $product['parent_id'] )
$url = '/p-' . $product['parent_id'] . '-' . \S::seo( $product['language']['name'] );
else
$url = '/p-' . $product['id'] . '-' . \S::seo( $product['language']['name'] );
}
return $url;
}
static public function get_minimal_price( $id_product, $price_brutto_promo = null )
{
global $mdb;
if ( !$price = \Cache::fetch( 'get_minimal_price:' . $id_product ) )
{
$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 );
}
return $price;
}
public static function product_categories( $product_id )
{
global $mdb;
if ( $parent_id = $mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] ) )
return \R::getAll( 'SELECT category_id FROM pp_shop_products_categories WHERE product_id = ?', [ $parent_id ] );
else
return \R::getAll( 'SELECT category_id FROM pp_shop_products_categories WHERE product_id = ?', [ $product_id ] );
}
public static function product_name( $product_id )
{
global $mdb, $lang_id;
if ( !$product_name = \Cache::fetch( 'product_name' . $lang_id . '_' . $product_id ) )
{
$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 );
}
return $product_name;
}
public static function product_image( $product_id )
{
global $mdb;
if ( !$product_image = \Cache::fetch( 'product_image:' . $product_id ) )
{
$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 );
}
return $product_image;
}
public static function product_wp( $product_id )
{
global $mdb;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_wp:$product_id";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$product_wp = $mdb -> get( 'pp_shop_products', 'wp', [ 'id' => $product_id ] );
$cacheHandler -> set( $cacheKey, $product_wp );
}
else
{
return unserialize( $objectData );
}
return $product_wp;
}
public static function random_products( $product_id, $lang_id = 'pl' )
{
global $mdb;
if ( !$products = \Cache::fetch( 'random_productsa_' . $product_id . '_' . $lang_id ) )
{
$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 );
}
return $products;
}
public static function promoted_products( $limit = 6 )
{
global $mdb;
if ( !$products = \Cache::fetch( "promoted_products-$limit" ) )
{
$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 );
}
return $products;
}
public static function top_products( $limit = 6 )
{
global $mdb;
$date_30_days_ago = date('Y-m-d', strtotime('-30 days'));
$products = $mdb -> query( "SELECT COUNT(0) AS sell_count, psop.parent_product_id FROM pp_shop_order_products AS psop INNER JOIN pp_shop_orders AS pso ON pso.id = psop.order_id WHERE pso.date_order >= '$date_30_days_ago' GROUP BY parent_product_id ORDER BY sell_count DESC")->fetchAll(\PDO::FETCH_ASSOC);
foreach ( $products as $product )
{
if ( \front\factory\ShopProduct::is_product_active( $product['parent_product_id'] ) )
$product_ids[] = $product['parent_product_id'];
}
return $product_ids;
}
public static function new_products( $limit = 10 ) {
global $mdb;
$results = $mdb->query("
SELECT id
FROM pp_shop_products
WHERE status = 1
ORDER BY date_add DESC
LIMIT $limit
")->fetchAll(\PDO::FETCH_ASSOC);
return array_column($results, 'id');
}
public static function product_details( $product_id, $lang_id )
{
global $mdb;
if ( !$product_id )
return false;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopProduct::product_details:$product_id:$lang_id";
$objectData = $cacheHandler->get($cacheKey);
if ( !$objectData )
{
$product = $mdb -> get( 'pp_shop_products', '*', [ 'id' => (int)$product_id ] );
$results = $mdb -> select( 'pp_shop_products_langs', '*', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $lang_id ] ] );
if ( is_array( $results ) )
foreach ( $results as $row )
{
if ( $row[ 'copy_from' ] )
{
$results2 = $mdb -> select( 'pp_shop_products_langs', '*', [ 'AND' => [ 'product_id' => (int)$product_id, 'lang_id' => $row[ 'copy_from' ] ] ] );
if ( is_array( $results2 ) )
foreach ( $results2 as $row2 )
$product[ 'language' ] = $row2;
}
else
$product[ 'language' ] = $row;
}
$results = $mdb -> query( 'SELECT '
. 'DISTINCT( attribute_id ) '
. 'FROM '
. 'pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes AS psa ON psa.id = pspa.attribute_id '
. 'WHERE '
. 'product_id = ' . (int)$product_id . ' '
. 'ORDER BY '
. 'o ASC' ) -> fetchAll();
if ( is_array( $results ) )
foreach ( $results as $row )
{
$row[ 'type' ] = $mdb -> get( 'pp_shop_attributes',
'type',
[ 'id' => $row[ 'attribute_id' ] ]
);
$row[ 'language' ] = $mdb -> get( 'pp_shop_attributes_langs',
[ 'name' ],
[ 'AND' =>
[ 'attribute_id' => $row[ 'attribute_id' ], 'lang_id' => $lang_id ]
]
);
$results2 = $mdb -> query( 'SELECT '
. 'value_id, is_default '
. 'FROM '
. 'pp_shop_products_attributes AS pspa '
. 'INNER JOIN pp_shop_attributes_values AS psav ON psav.id = pspa.value_id '
. 'WHERE '
. 'product_id = :product_id '
. 'AND '
. 'pspa.attribute_id = :attribute_id ',
[
':product_id' => $product_id,
':attribute_id' => $row[ 'attribute_id' ]
]
) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results2 ) )
foreach ( $results2 as $row2 )
{
$row2[ 'language' ] = $mdb -> get( 'pp_shop_attributes_values_langs',
[ 'name', 'value' ],
[ 'AND' =>
[ 'value_id' => $row2[ 'value_id' ], 'lang_id' => $lang_id ]
]
);
$row[ 'values' ][] = $row2;
}
$product[ 'attributes' ][] = $row;
}
$product[ 'images' ] = $mdb -> select( 'pp_shop_products_images', '*', [ 'product_id' => (int)$product_id, 'ORDER' => [ 'o' => 'ASC', 'id' => 'ASC' ] ] );
$product[ 'files' ] = $mdb -> select( 'pp_shop_products_files', '*', [ 'product_id' => (int)$product_id ] );
$product[ 'categories' ] = $mdb -> select( 'pp_shop_products_categories', 'category_id', [ 'product_id' => (int)$product_id ] );
$product[ 'products_related' ] = $mdb -> select( 'pp_shop_products_related', 'product_related_id', [ 'product_id' => (int)$product_id ] );
$set_id = $mdb -> select( 'pp_shop_product_sets_products', 'set_id', [ 'product_id' => (int)$product_id ] );
$products_sets = $mdb -> select( 'pp_shop_product_sets_products', 'product_id', [ 'set_id' => (int)$set_id ] );
$products_sets = array_unique( $products_sets );
$product[ 'products_sets' ] = $products_sets;
$attributes = $mdb -> select( 'pp_shop_products_attributes', [ 'attribute_id', 'value_id' ], [ 'product_id' => (int)$product_id ] );
if ( is_array( $attributes ) ): foreach ( $attributes as $attribute ):
$attributes_tmp[ $attribute[ 'attribute_id' ] ][] = $attribute[ 'value_id' ];
endforeach;
endif;
if ( is_array( $attributes_tmp ) )
$product[ 'permutations' ] = \S::array_cartesian_product( $attributes_tmp );
$cacheHandler -> set( $cacheKey, $product );
}
else
{
return unserialize($objectData);
}
return $product;
}
public static function warehouse_message_zero( $id_product, $lang_id )
{
global $mdb, $lang_id;
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_zero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
}
public static function warehouse_message_nonzero( $id_product, $lang_id )
{
global $mdb, $lang_id;
return $mdb -> get( 'pp_shop_products_langs', 'warehouse_message_nonzero', [ 'AND' => [ 'product_id' => $id_product, 'lang_id' => $lang_id ] ] );
}
//TO:DO do usunięcia
public static function product_both_price( $product_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_products', [ 'price_brutto', 'price_brutto_promo' ], [ 'id' => (int)$product_id ] );
}
//TO:DO do usunięcia
public static function product_price( $product_id )
{
global $mdb;
$product = $mdb -> get( 'pp_shop_products', [ 'price_brutto', 'price_brutto_promo', 'vat' ], [ 'id' => (int)$product_id ] );
if ( $product[ 'price_brutto_promo' ] )
return $product[ 'price_brutto_promo' ];
else
return $product[ 'price_brutto' ];
}
}

View File

@@ -1,215 +0,0 @@
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace front\factory;
/**
* Description of class
*
* @author Dom - Jacek
*/
class ShopPromotion
{
//! promocja na wszystkie produkty z kategori 1 lub 2
static public function promotion_type_03( $basket, $promotion )
{
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $condition_categories ) or in_array( $category_tmp[ 'category_id' ], $categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
//! promocja na produkty z kategorii 1 i 2
static public function promotion_type_02( $basket, $promotion )
{
$condition_1 = false; $condition_2 = false;
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
// sprawdzanie czy warunki są spełnione
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
// sprawdzam produkt pod kątem I kategorii
if ( !$condition_1 and in_array( $category_tmp[ 'category_id' ], $condition_categories ) )
{
$condition_1 = true;
unset( $basket_tmp[ $key ] );
}
}
}
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
// sprawdzam produkt pod kątem II kategorii
if ( !$condition_2 and in_array( $category_tmp[ 'category_id' ], $categories ) )
$condition_2 = true;
}
}
}
// jeżeli warunki są spełnione to szukam produktów, którym można obniżyć cenę
if ( $condition_1 and $condition_2 )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $categories ) or in_array( $category_tmp['category_id'], $condition_categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
//! promocja na najtańszy produkt z kategorii 1 lub 2
static public function promotion_type_04( $basket, $promotion )
{
$condition_1 = false;
$categories = json_decode( $promotion -> categories );
//! sprawdzanie czy warunki są spełnione
if ( is_array( $categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
//! sprawdzam produkt pod kątem I kategorii
if ( !$condition_1[$key] and in_array( $category_tmp[ 'category_id' ], $categories ) )
$condition_1[$key] = true;
}
}
}
}
if ( count( $condition_1 ) >= $promotion -> min_product_count )
{
foreach ( $basket as $key => $val )
{
$price = \shop\Product::get_product_price( $val['product-id'] );
if ( !$cheapest_position or $cheapest_position['price'] > $price )
{
$cheapest_position['price'] = $price;
$cheapest_position['key'] = $key;
}
}
$basket[$cheapest_position['key']]['quantity'] = 1;
$basket[$cheapest_position['key']]['discount_type'] = 3;
$basket[$cheapest_position['key']]['discount_amount'] = $promotion -> price_cheapest_product;
$basket[$cheapest_position['key']]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$cheapest_position['key']]['include_product_promo'] = $promotion -> include_product_promo;
}
return $basket;
}
//! promocja na cały koszyk
static public function promotion_type_05( $basket, $promotion )
{
foreach ( $basket as $key => $val )
{
$product_promotion = \shop\Product::is_product_on_promotion( $val['product-id'] );
if ( !$product_promotion or $product_promotion and $promotion -> include_product_promo )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
return $basket;
}
//! Rabat procentowy na produkty z kategorii I jeżeli w koszyku jest produkt z kategorii II
static public function promotion_type_01( $basket, $promotion )
{
$condition = false;
$categories = json_decode( $promotion -> categories );
$condition_categories = json_decode( $promotion -> condition_categories );
// sprawdzanie czy warunki są spełnione
if ( is_array( $condition_categories ) and is_array( $categories ) )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $condition_categories ) )
{
$condition = true;
}
}
}
}
// jeżeli warunki są spełnione to szukam produktów, którym można obniżyć cenę
if ( $condition )
{
foreach ( $basket as $key => $val )
{
$product_categories = \front\factory\ShopProduct::product_categories( $val[ 'product-id' ] );
foreach ( $product_categories as $category_tmp )
{
if ( in_array( $category_tmp[ 'category_id' ], $categories ) )
{
$basket[$key]['discount_type'] = $promotion -> discount_type;
$basket[$key]['discount_amount'] = $promotion -> amount;
$basket[$key]['discount_include_coupon'] = $promotion -> include_coupon;
$basket[$key]['include_product_promo'] = $promotion -> include_product_promo;
}
}
}
}
return $basket;
}
}

View File

@@ -1,35 +0,0 @@
<?
namespace front\factory;
class ShopStatuses {
// get_baselinker_order_status_id
static public function get_baselinker_order_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'baselinker_status_id', [ 'id' => $status_id ] );
}
// get_apilo_status_id
static public function get_apilo_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'apilo_status_id', [ 'id' => $status_id ] );
}
// get sellasist status id
static public function get_sellasist_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'sellasist_status_id', [ 'id' => $status_id ] );
}
// get_shop_status_by_integration_status_id
static public function get_shop_status_by_integration_status_id( $integration, $integration_status_id )
{
global $mdb;
if ( $integration == 'sellasist' )
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'sellasist_status_id' => $integration_status_id ] );
if ( $integration == 'apilo' )
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'apilo_status_id' => $integration_status_id ] );
}
}

View File

@@ -1,101 +0,0 @@
<?php
namespace front\factory;
class ShopTransport
{
// get_sellasist_transport_id
static public function get_sellasist_transport_id( $transport_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_transports', 'sellasist_shipment_method_id', [ 'id' => $transport_method_id ] );
}
// get_apilo_carrier_account_id
static public function get_apilo_carrier_account_id( $transport_method_id )
{
global $mdb;
return $mdb -> get( 'pp_shop_transports', 'apilo_carrier_account_id', [ 'id' => $transport_method_id ] );
}
public static function transport_methods( $basket, $coupon )
{
global $mdb, $settings;
$cacheHandler = new \CacheHandler();
$cacheKey = "\front\factory\ShopTransport::transport_methods";
$objectData = $cacheHandler -> get( $cacheKey );
if ( !$objectData )
{
$results = $mdb -> query( 'SELECT '
. 'pst.id, name, name_visible, description, cost, max_wp, pst.default, delivery_free '
. 'FROM '
. 'pp_shop_transports AS pst '
. 'WHERE '
. 'status = 1 ORDER BY o ASC' ) -> fetchAll( \PDO::FETCH_ASSOC );
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
$transports_tmp[] = $row;
$cacheHandler -> set( $cacheKey, $transports_tmp );
}
else
{
$transports_tmp = unserialize( $objectData );
}
$wp_summary = \front\factory\ShopBasket::summary_wp( $basket );
foreach ( $transports_tmp as $tr )
{
if ( $tr['max_wp'] == null )
$transports[] = $tr;
elseif ( $tr['max_wp'] != null and $wp_summary <= $tr['max_wp'] )
$transports[] = $tr;
}
if ( \S::normalize_decimal( \front\factory\ShopBasket::summary_price( $basket, $coupon ) ) >= \S::normalize_decimal( $settings['free_delivery'] ) )
{
for ( $i = 0; $i < count( $transports ); $i++ ){
if($transports[ $i ]['delivery_free'] == 1) {
$transports[ $i ]['cost'] = 0.00;
}
}
}
return $transports;
}
public static function transport_cost( $transport_id )
{
global $mdb;
if ( !$cost = \Cache::fetch( 'transport_cost_' . $transport_id ) )
{
$cost = $mdb -> get( 'pp_shop_transports', 'cost', [
'AND' => [
'id' => $transport_id,
'status' => 1
] ] );
\Cache::store( 'transport_cost_' . $transport_id, $cost );
}
return $cost;
}
public static function transport( $transport_id )
{
global $mdb;
if ( !$transport = \Cache::fetch( 'transport' . $transport_id ) )
{
$transport = $mdb -> get( 'pp_shop_transports', '*', [
'AND' => [
'id' => $transport_id,
'status' => 1
] ] );
\Cache::store( 'transport' . $transport_id, $transport );
}
return $transport;
}
}

View File

@@ -1,90 +0,0 @@
<?php
namespace front\view;
class Articles
{
public static function news( $page_id, $articles )
{
$tpl = new \Tpl;
$tpl -> page_id = $page_id;
$tpl -> articles = $articles;
return $tpl -> render( 'articles/news' );
}
public static function full_article( $article_id, $lang_id )
{
$tpl = new \Tpl;
$tpl -> article = \front\factory\Articles::article_details( $article_id, $lang_id );
return $tpl -> render( 'articles/article' );
}
public static function miniature_articles_list( $page, $lang_id, $bs = 1 )
{
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
{
$tpl = new \Tpl;
$tpl -> article = \front\factory\Articles::article_details( $article, $lang_id );
$out .= $tpl -> render( 'articles/article-miniature' );
}
if ( $results['ls'] > 1 )
{
$tpl = new \Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> page = $page;
$out .= $tpl -> render( 'site/pager' );
}
return $out;
}
public static function entry_articles_list( $page, $lang_id, $bs = 1 )
{
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
$articles[] = \front\factory\Articles::article_details( $article, $lang_id );
$tpl = new \Tpl;
$tpl -> page_id = $page['id'];
$tpl -> articles = $articles;
$out .= $tpl -> render( 'articles/articles-entries' );
if ( $results['ls'] > 1 )
{
$tpl = new \Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> page = $page;
$out .= $tpl -> render( 'site/pager' );
}
return $out;
}
public static function full_articles_list( $page, $lang_id, $bs = 1 )
{
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
{
$tpl = new \Tpl;
$tpl -> article = \front\factory\Articles::article_details( $article, $lang_id );
$out .= $tpl -> render( 'articles/article-full' );
}
if ( $results['ls'] > 1 )
{
$tpl = new \Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> page = $page;
$out .= $tpl -> render( 'site/pager' );
}
return $out;
}
}

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

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class Languages
{
public static function languages()
{
$tpl = new \Tpl;
$tpl -> languages = \front\factory\Languages::active_languages();
return $tpl -> render( 'site/languages' );
}
}

View File

@@ -1,22 +0,0 @@
<?php
namespace front\view;
class Menu
{
public static function pages( $pages, $level = 0, $current_page = 0 )
{
$tpl = new \Tpl;
$tpl -> pages = $pages;
$tpl -> level = $level;
$tpl -> current_page = $current_page;
return $tpl -> render( 'menu/pages' );
}
public static function menu( $menu, $current_page )
{
$tpl = new \Tpl;
$tpl -> menu = $menu;
$tpl -> current_page = $current_page;
return $tpl -> render( 'menu/menu' );
}
}

View File

@@ -1,11 +0,0 @@
<?php
namespace front\view;
class Newsletter
{
public static function newsletter()
{
$tpl = new \Tpl;
return $tpl -> render( 'newsletter/newsletter' );
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class Scontainers
{
public static function scontainer( $id )
{
$tpl = new \Tpl;
$tpl -> scontainer = \front\factory\Scontainers::scontainer_details( $id );
return $tpl -> render( 'scontainers/scontainer' );
}
}

View File

@@ -1,56 +0,0 @@
<?php
namespace front\view;
class ShopCategory
{
static public function category_description( $category )
{
return \Tpl::view( 'shop-category/category-description', [
'category' => $category
] );
}
static public function category_view( $category, $lang_id, $bs = 1 )
{
global $settings, $page;
if ( !$settings['infinitescroll'] )
{
$results = \front\factory\ShopCategory::category_products( $category, $lang_id, $bs );
if ( $results['ls'] > 1 )
{
$tpl = new \Tpl;
$tpl -> ls = $results['ls'];
$tpl -> bs = $bs ? $bs : 1;
$tpl -> page = $page;
$tpl -> link = $category['language']['seo_link'] ? $url = $category['language']['seo_link'] : $url = 'k-' . $category['id'] . '-' . \S::seo( $category['language']['title'] );
$pager = $tpl -> render( 'site/pager' );
}
return \Tpl::view( 'shop-category/category', [
'category' => $category,
'products' => $results['products'],
'pager' => $pager,
'category_description' => (int)$bs <= 1 ? true : false,
'category_additional_text' => true
] );
}
$products_count = \front\factory\ShopCategory::category_products_count( $category, $lang_id );
return \Tpl::view( 'shop-category/category-infinitescroll', [
'category' => $category,
'products_count' => $products_count,
'category_description' => (int)$bs <= 1 ? true : false,
'category_additional_text' => true
] );
}
public static function categories( $categories, $current_category = 0, $level = 0 )
{
$tpl = new \Tpl;
$tpl -> level = $level;
$tpl -> current_category = $current_category;
$tpl -> categories = $categories;
return $tpl -> render( 'shop-category/categories' );
}
}

View File

@@ -1,65 +0,0 @@
<?php
namespace front\view;
class ShopClient
{
public static function address_edit( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-client/address-edit' );
}
public static function client_addresses( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-client/client-addresses' );
}
public static function client_menu( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-client/client-menu' );
}
public static function client_orders( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-client/client-orders' );
}
public static function recover_password()
{
$tpl = new \Tpl;
return $tpl -> render( 'shop-client/recover-password' );
}
public static function mini_login()
{
global $client;
$tpl = new \Tpl;
$tpl -> client = $client;
return $tpl -> render( 'shop-client/mini-login' );
}
public static function login_form( $values = '' )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-client/login-form' );
}
public static function register_form()
{
$tpl = new \Tpl;
return $tpl -> render( 'shop-client/register-form' );
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class ShopOrder
{
public static function order_details( $values )
{
$tpl = new \Tpl;
if ( is_array( $values ) ) foreach ( $values as $key => $val )
$tpl -> $key = $val;
return $tpl -> render( 'shop-order/order-details' );
}
}

View File

@@ -1,12 +0,0 @@
<?php
namespace front\view;
class ShopPaymentMethod
{
public static function basket_payment_methods( $payment_methods, $payment_id )
{
$tpl = new \Tpl;
$tpl -> payment_methods = $payment_methods;
$tpl -> payment_id = $payment_id;
return $tpl -> render( 'shop-basket/basket-payments-methods' );
}
}

View File

@@ -1,6 +0,0 @@
<?php
namespace front\view;
class ShopTransport
{
}