first commit
This commit is contained in:
317
autoload/front/factory/class.Articles.php
Normal file
317
autoload/front/factory/class.Articles.php
Normal file
@@ -0,0 +1,317 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
73
autoload/front/factory/class.Banners.php
Normal file
73
autoload/front/factory/class.Banners.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
16
autoload/front/factory/class.Dictionaries.php
Normal file
16
autoload/front/factory/class.Dictionaries.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?
|
||||
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;
|
||||
}
|
||||
}
|
||||
78
autoload/front/factory/class.Languages.php
Normal file
78
autoload/front/factory/class.Languages.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
107
autoload/front/factory/class.Layouts.php
Normal file
107
autoload/front/factory/class.Layouts.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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 -> get( 'pp_layouts', '*', [ '[><]pp_layouts_categories' => [ 'id' => 'layout_id' ] ], [ 'category_id' => (int)$category_id ] );
|
||||
if ( !$layout )
|
||||
$layout = $mdb -> get( 'pp_layouts', '*', [ 'categories_default' => 1 ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $layout );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $layout;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
59
autoload/front/factory/class.Menu.php
Normal file
59
autoload/front/factory/class.Menu.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
122
autoload/front/factory/class.Newsletter.php
Normal file
122
autoload/front/factory/class.Newsletter.php
Normal file
@@ -0,0 +1,122 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
92
autoload/front/factory/class.Pages.php
Normal file
92
autoload/front/factory/class.Pages.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
31
autoload/front/factory/class.Scontainers.php
Normal file
31
autoload/front/factory/class.Scontainers.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
43
autoload/front/factory/class.Settings.php
Normal file
43
autoload/front/factory/class.Settings.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
21
autoload/front/factory/class.Shop.php
Normal file
21
autoload/front/factory/class.Shop.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?
|
||||
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;
|
||||
}
|
||||
}
|
||||
43
autoload/front/factory/class.ShopAttribute.php
Normal file
43
autoload/front/factory/class.ShopAttribute.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
66
autoload/front/factory/class.ShopBasket.php
Normal file
66
autoload/front/factory/class.ShopBasket.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
297
autoload/front/factory/class.ShopCategory.php
Normal file
297
autoload/front/factory/class.ShopCategory.php
Normal file
@@ -0,0 +1,297 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
266
autoload/front/factory/class.ShopClient.php
Normal file
266
autoload/front/factory/class.ShopClient.php
Normal file
@@ -0,0 +1,266 @@
|
||||
<?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, $firm, $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,
|
||||
'firm' => $firm,
|
||||
'street' => $street,
|
||||
'postal_code' => $postal_code,
|
||||
'city' => $city,
|
||||
'phone' => $phone
|
||||
] ) )
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $mdb -> update( 'pp_shop_clients_addresses', [
|
||||
'name' => $name,
|
||||
'surname' => $surname,
|
||||
'firm' => $firm,
|
||||
'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 ] );
|
||||
}
|
||||
}
|
||||
30
autoload/front/factory/class.ShopCoupon.php
Normal file
30
autoload/front/factory/class.ShopCoupon.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
219
autoload/front/factory/class.ShopOrder.php
Normal file
219
autoload/front/factory/class.ShopOrder.php
Normal file
@@ -0,0 +1,219 @@
|
||||
<?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, $firm, $street, $postal_code, $city, $inpost_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_firm' => $firm,
|
||||
'client_email' => $email,
|
||||
'client_street' => $street,
|
||||
'client_postal_code' => $postal_code,
|
||||
'client_city' => $city,
|
||||
'client_phone' => $phone,
|
||||
'transport_id' => $transport_id,
|
||||
'transport' => $transport[ 'name_visible' ],
|
||||
'transport_cost' => $transport_cost,
|
||||
'transport_description' => $transport[ 'description' ],
|
||||
'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;
|
||||
|
||||
\Log::save_log( 'Złożono nowe zamówienie | NR: ' . $order_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
|
||||
] );
|
||||
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
||||
80
autoload/front/factory/class.ShopPaymentMethod.php
Normal file
80
autoload/front/factory/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
382
autoload/front/factory/class.ShopProduct.php
Normal file
382
autoload/front/factory/class.ShopProduct.php
Normal file
@@ -0,0 +1,382 @@
|
||||
<?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 )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// get_product_ean
|
||||
static public function get_product_ean( $product_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_products', 'ean', [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
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[ 'require' ] = $mdb -> get( 'pp_shop_attributes',
|
||||
'required',
|
||||
[ 'id' => $row[ 'attribute_id' ] ]
|
||||
);
|
||||
|
||||
$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 ] );
|
||||
|
||||
$products_sets_1 = $mdb -> select( 'pp_shop_products_sets', 'product_sets_id', [ 'product_id' => (int)$product_id ] );
|
||||
$products_sets_2 = $mdb -> select( 'pp_shop_products_sets', 'product_id', [ 'product_sets_id' => (int)$product_id ] );
|
||||
$products_sets = array_unique( array_merge( $products_sets_1, $products_sets_2 ) );
|
||||
|
||||
$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 ] ] );
|
||||
}
|
||||
|
||||
public static function permutation_quantity( $id_product, $permutation, bool $is_multichoice )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$is_multichoice )
|
||||
return $mdb -> get( 'pp_shop_products_stock', 'quantity', [ 'AND' => [ 'id_product' => $id_product, 'permutation' => 0 ] ] );
|
||||
|
||||
if ( is_array( $permutation ) )
|
||||
{
|
||||
foreach ( $permutation as $key => $val )
|
||||
{
|
||||
$permutation_id .= $val;
|
||||
if ( $val != end( $permutation ) )
|
||||
$permutation_id .= '_';
|
||||
}
|
||||
}
|
||||
else
|
||||
$permutation_id = $permutation;
|
||||
|
||||
return $mdb -> get( 'pp_shop_products_stock', 'quantity', [ 'AND' => [ 'id_product' => $id_product, 'permutation' => $permutation_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' ];
|
||||
}
|
||||
|
||||
}
|
||||
215
autoload/front/factory/class.ShopPromotion.php
Normal file
215
autoload/front/factory/class.ShopPromotion.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
35
autoload/front/factory/class.ShopStatuses.php
Normal file
35
autoload/front/factory/class.ShopStatuses.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?
|
||||
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 ] );
|
||||
}
|
||||
}
|
||||
101
autoload/front/factory/class.ShopTransport.php
Normal file
101
autoload/front/factory/class.ShopTransport.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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' ) -> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user