first commit
This commit is contained in:
BIN
autoload/front/.DS_Store
vendored
Normal file
BIN
autoload/front/.DS_Store
vendored
Normal file
Binary file not shown.
38
autoload/front/controls/class.Newsletter.php
Normal file
38
autoload/front/controls/class.Newsletter.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function signin()
|
||||
{
|
||||
$result = [ 'status' => 'bad' ];
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_signin( \S::get( 'email' ) ) )
|
||||
$result = [ 'status' => 'ok' ];
|
||||
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function confirm()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_confirm( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-dodany-do-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function unsubscribe()
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if ( \front\factory\Newsletter::newsletter_unsubscribe( \S::get( 'hash' ) ) )
|
||||
\S::alert( $lang['email-zostal-usuniety-z-listy-newsletter'] );
|
||||
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
412
autoload/front/controls/class.ShopBasket.php
Normal file
412
autoload/front/controls/class.ShopBasket.php
Normal file
@@ -0,0 +1,412 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class ShopBasket
|
||||
{
|
||||
public static $title = [
|
||||
'main_view' => 'Koszyk'
|
||||
];
|
||||
|
||||
public static function basket_message_save()
|
||||
{
|
||||
\S::set_session( 'basket_message', \S::get( 'basket_message' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_remove_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_increase_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
$basket[ $product_hash ][ 'quantity' ]++;
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
]
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_decrease_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
$basket[ $product_hash ][ 'quantity' ]--;
|
||||
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_change_quantity_product()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$product_hash = \S::get( 'product_hash' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
$basket[ $product_hash ][ 'quantity' ] = (int)\S::get( 'quantity' );
|
||||
|
||||
if ( $basket[ $product_hash ][ 'quantity' ] < 1 )
|
||||
unset( $basket[ $product_hash ] );
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\shop\Basket::check_product_quantity_in_stock( $basket, false );
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
|
||||
echo json_encode( [
|
||||
'basket' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon
|
||||
] ),
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'products_count' => count( $basket ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function product_message_change()
|
||||
{
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$basket[ \S::get( 'position_code' ) ]['message'] = \S::get( 'product_message' );
|
||||
\S::set_session( 'basket', $basket );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_add_product()
|
||||
{
|
||||
$basket = \shop\Basket::validate_basket( \S::get_session( 'basket' ) );
|
||||
$values_tmp = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
foreach( $values_tmp as $key => $val )
|
||||
$values[ $val['name'] ] = $val['value'];
|
||||
|
||||
// sprawdzam pola pod kątem wybranych atrybutów
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( $key != 'product-id' and $key != 'quantity' and $key != 'product-message' and strpos( $key, 'custom_field' ) === false )
|
||||
$attributes[] = $val;
|
||||
}
|
||||
|
||||
// stwórz tablicę dodatkowych pól wyszukując na podstawie custom_field[1], custom_field[2] itd.
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( strpos( $key, 'custom_field' ) !== false )
|
||||
{
|
||||
// extract number from custom_field[1], custom_field[2] etc.
|
||||
preg_match( '/\d+/', $key, $matches );
|
||||
$custom_field_id = $matches[0];
|
||||
|
||||
$custom_fields[ $custom_field_id ] = $val;
|
||||
}
|
||||
}
|
||||
|
||||
if ( \S::is_array_fix( $attributes ) )
|
||||
{
|
||||
$values['parent_id'] = $values[ 'product-id' ];
|
||||
$values['product-id'] = \shop\Product::get_product_id_by_attributes( $values[ 'product-id' ], $attributes );
|
||||
$values['attributes'] = $attributes;
|
||||
}
|
||||
|
||||
|
||||
$values['wp'] = \front\factory\ShopProduct::product_wp( $values[ 'product-id' ] );
|
||||
|
||||
// generuj unikalny kod produktu dodanego do koszyka
|
||||
$product_code = md5( $values['product-id'] . implode( '|', $attributes ) . $values['product-message'] . json_encode( $custom_fields ) );
|
||||
|
||||
if ( isset( $basket[ $product_code ] ) )
|
||||
$basket[ $product_code ][ 'quantity' ] += $values[ 'quantity' ];
|
||||
else
|
||||
$basket[ $product_code ] = $values;
|
||||
|
||||
$basket[ $product_code ]['message'] = $values['product-message'];
|
||||
$basket[ $product_code ]['custom_fields'] = $custom_fields;
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
\S::set_session( 'basket', $basket );
|
||||
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
|
||||
echo json_encode( [
|
||||
'result' => 'ok',
|
||||
'basket_mini_count' => \front\factory\ShopBasket::count_products_text( \front\factory\ShopBasket::count_products( $basket ) ),
|
||||
'basket_mini_value' => \front\factory\ShopBasket::summary_price( $basket, $coupon ),
|
||||
'product_sets' => \shop\Product::product_sets_when_add_to_basket( (int)$values['product-id'] )
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sprawdzam czy została wybrana forma wysylki inpost i czy został wybrany paczkomat
|
||||
static public function transport_method_inpost_check()
|
||||
{
|
||||
if ( \S::get_session( 'basket-transport-method-id' ) === '2' or \S::get_session( 'basket-transport-method-id' ) === '1' )
|
||||
{
|
||||
if ( !\S::get_session( 'basket-inpost-info' ) )
|
||||
{
|
||||
echo json_encode( [
|
||||
'result' => 'bad'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sprawdzam czy został wybrany paczkomat
|
||||
static public function inpost_check() {
|
||||
if ( !\S::get_session( 'basket-inpost-info' ) )
|
||||
echo json_encode( [
|
||||
'result' => 'bad'
|
||||
] );
|
||||
else
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function inpost_save()
|
||||
{
|
||||
\S::set_session( 'basket-inpost-info', \S::get( 'paczkomat' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_payment_method_set()
|
||||
{
|
||||
\S::set_session( 'basket-payment-method-id', \S::get( 'payment_method_id' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_transport_method_set()
|
||||
{
|
||||
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
|
||||
echo json_encode( [
|
||||
'result' => 'ok'
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function basket_payments_methods()
|
||||
{
|
||||
\S::set_session( 'basket-transport-method-id', \S::get( 'transport_method_id' ) );
|
||||
|
||||
echo json_encode( [
|
||||
'result' => 'ok',
|
||||
'payment_methods' => \front\view\ShopPaymentMethod::basket_payment_methods(
|
||||
\front\factory\ShopPaymentMethod::payment_methods_by_transport( \S::get( 'transport_method_id' ) ),
|
||||
\S::get( 'payment_method_id' )
|
||||
)
|
||||
] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function summary_view()
|
||||
{
|
||||
global $lang_id, $settings;
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$client = \S::get_session( 'client' );
|
||||
|
||||
return \Tpl::view( 'shop-basket/summary-view', [
|
||||
'lang_id' => $lang_id,
|
||||
'client' => \S::get_session( 'client' ),
|
||||
'basket' => \S::get_session( 'basket' ),
|
||||
'transport' => \front\factory\ShopTransport::transport( \S::get_session( 'basket-transport-method-id' ) ),
|
||||
'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \S::get_session( 'basket-payment-method-id' ) ),
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client[ 'id' ] ),
|
||||
'settings' => $settings,
|
||||
'coupon' => \S::get_session( 'coupon' ),
|
||||
'basket_message' => \S::get_session( 'basket_message' )
|
||||
] );
|
||||
}
|
||||
|
||||
// zapisanie koszyka jako zamówienie
|
||||
static public function basket_save()
|
||||
{
|
||||
$client = \S::get_session( 'client' );
|
||||
$payment_method = \S::get_session( 'basket-payment-method-id' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( \S::get_session( 'basket' ) ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( $order_id = \front\factory\ShopOrder::basket_save(
|
||||
$client[ 'id' ], \S::get_session( 'basket' ), \S::get_session( 'basket-transport-method-id' ), \S::get_session( 'basket-payment-method-id' ),
|
||||
\S::get( 'email', true ), \S::get( 'phone', true ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'firm', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ),
|
||||
\S::get_session( 'basket-inpost-info' ), \S::get_session( 'coupon' ), \S::get_session( 'basket_message' )
|
||||
) )
|
||||
{
|
||||
\S::alert( \S::lang( 'zamowienie-zostalo-zlozone-komunikat' ) );
|
||||
\S::delete_session( 'basket' );
|
||||
\S::delete_session( 'basket-transport-method-id' );
|
||||
\S::delete_session( 'basket-payment-method-id' );
|
||||
\S::delete_session( 'basket-inpost-info' );
|
||||
\S::delete_session( 'coupon' );
|
||||
\S::delete_session( 'basket_message' );
|
||||
|
||||
\S::set_session( 'piksel_purchase', true );
|
||||
\S::set_session( 'google-adwords-purchase', true );
|
||||
\S::set_session( 'google-analytics-purchase', true );
|
||||
\S::set_session( 'ekomi-purchase', true );
|
||||
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
$redis -> flushAll();
|
||||
|
||||
header( 'Location: /zamowienie/' . \front\factory\ShopOrder::order_hash( $order_id ) );
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::error( \S::lang( 'zamowienie-zostalo-zlozone-komunikat-blad' ) );
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public static function main_view()
|
||||
{
|
||||
global $lang_id, $page, $settings;
|
||||
|
||||
$page[ 'language' ][ 'meta_title' ] = 'Koszyk';
|
||||
|
||||
$basket = \S::get_session( 'basket' );
|
||||
$coupon = \S::get_session( 'coupon' );
|
||||
$payment_method_id = \S::get_session( 'payment_method_id' );
|
||||
$basket_transport_method_id = \S::get_session( 'basket-transport-method-id' );
|
||||
|
||||
if ( \shop\Basket::check_product_quantity_in_stock( $basket ) )
|
||||
{
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$basket = \shop\Promotion::find_promotion( $basket );
|
||||
|
||||
return \Tpl::view( 'shop-basket/basket', [
|
||||
'basket' => $basket,
|
||||
'coupon' => $coupon,
|
||||
'transport_id' => \S::get_session( 'basket-transport-method-id' ),
|
||||
'transport_methods' => \Tpl::view( 'shop-basket/basket-transport-methods', [
|
||||
'transports_methods' => \front\factory\ShopTransport::transport_methods( $basket, $coupon ),
|
||||
'transport_id' => $basket_transport_method_id
|
||||
] ),
|
||||
'payment_method_id' => $payment_method_id,
|
||||
'basket_details' => \Tpl::view( 'shop-basket/basket-details', [
|
||||
'basket' => $basket,
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => $coupon,
|
||||
'basket_message' => \S::get_session( 'basket_message' ),
|
||||
'settings' => $settings
|
||||
] )
|
||||
] );
|
||||
}
|
||||
|
||||
}
|
||||
212
autoload/front/controls/class.ShopClient.php
Normal file
212
autoload/front/controls/class.ShopClient.php
Normal file
@@ -0,0 +1,212 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopClient
|
||||
{
|
||||
public static function mark_address_as_current()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
return false;
|
||||
|
||||
\front\factory\ShopClient::mark_address_as_current( $client['id'], \S::get( 'address_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_delete()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
{
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_delete( \S::get( 'id' ) ) )
|
||||
\S::alert( \S::lang( 'adres-usuniety-komunikat' ) );
|
||||
else
|
||||
\S::error( \S::lang( 'adres-usuniety-blad' ) );
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_edit()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-edycja-adresu' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \S::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
unset( $address );
|
||||
|
||||
return \front\view\ShopClient::address_edit( [
|
||||
'address' => \front\factory\ShopClient::address_details( \S::get( 'id' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function address_save()
|
||||
{
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_save( $client['id'], \S::get( 'address_id' ), \S::get( 'name', true ), \S::get( 'surname', true ), \S::get( 'firm', true ), \S::get( 'street' ), \S::get( 'postal_code', true ), \S::get( 'city', true ), \S::get( 'phone', true ) ) )
|
||||
{
|
||||
\S::get( 'address_id' ) ? \S::alert( \S::lang( 'zmiana-adresu-sukces' ) ) : \S::alert( \S::lang( 'dodawanie-nowego-adresu-sukces' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::get( 'address_id' ) ? \S::error( \S::lang( 'zmiana-adresu-blad' ) ) : \S::error( \S::lang( 'dodawanie-nowego-adresu-blad' ) );
|
||||
}
|
||||
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function client_addresses()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-lista-adresow' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_addresses( [
|
||||
'client' => $client,
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client['id'] )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function client_orders()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-historia-zamowien' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_orders( [
|
||||
'client' => $client,
|
||||
'orders' => \front\factory\ShopClient::client_orders( $client['id'] ),
|
||||
'statuses' => \shop\Order::order_statuses()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function new_password()
|
||||
{
|
||||
if ( \front\factory\ShopClient::new_password( \S::get( 'hash' ) ) )
|
||||
\S::alert( \S::lang( 'nowe-haslo-zostalo-wyslane-na-twoj-adres-email' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function send_email_password_recovery()
|
||||
{
|
||||
if ( \front\factory\ShopClient::send_email_password_recovery( \S::get( 'email' ) ) )
|
||||
\S::alert( \S::lang( 'odzyskiwanie-hasla-link-komunikat' ) );
|
||||
else
|
||||
\S::alert( \S::lang( 'odzyskiwanie-hasla-blad' ) );
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function recover_password()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-odzyskiwanie-hasla' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \front\view\ShopClient::recover_password();
|
||||
}
|
||||
|
||||
public static function logout()
|
||||
{
|
||||
\S::delete_session( 'client' );
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login()
|
||||
{
|
||||
if ( !\front\factory\ShopClient::login( \S::get( 'email' ), \S::get( 'password' ) ) )
|
||||
header( 'Location: /logowanie' );
|
||||
else
|
||||
{
|
||||
$client = \S::get_session( 'client' );
|
||||
if ( $redirect = \S::get( 'redirect' ) )
|
||||
header( 'Location: ' . $redirect );
|
||||
else
|
||||
header( 'Location: /panel-klienta' );
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function confirm()
|
||||
{
|
||||
if ( \front\factory\ShopClient::register_confirm( \S::get( 'hash' ) ) )
|
||||
\S::alert( \S::lang( 'rejestracja-potwierdzenie' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function signup()
|
||||
{
|
||||
$result = \front\factory\ShopClient::signup( \S::get( 'email' ), \S::get( 'password' ), \S::get( 'agremment_marketing' ) );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-logowanie' ) . ' | ' . $settings['firm_name'];
|
||||
$page['class'] = 'page-login-form';
|
||||
|
||||
if ( $client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::login_form();
|
||||
}
|
||||
|
||||
public static function register_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-rejestracja' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( $client = \S::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::register_form();
|
||||
}
|
||||
}
|
||||
25
autoload/front/controls/class.ShopCoupon.php
Normal file
25
autoload/front/controls/class.ShopCoupon.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopCoupon
|
||||
{
|
||||
public static function delete_coupon()
|
||||
{
|
||||
\S::delete_session( 'coupon' );
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function use_coupon()
|
||||
{
|
||||
$coupon = new \shop\Coupon( 0 );
|
||||
$coupon -> load_from_db_by_name( (string)\S::get( 'coupon' ) );
|
||||
|
||||
if ( $coupon -> is_available() )
|
||||
\S::set_session( 'coupon', $coupon );
|
||||
else
|
||||
\S::alert( 'Podany kod rabatowy jest nieprawidłowy.' );
|
||||
|
||||
header( 'Location: /koszyk' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
152
autoload/front/controls/class.ShopOrder.php
Normal file
152
autoload/front/controls/class.ShopOrder.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopOrder
|
||||
{
|
||||
public static function payment_confirmation()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$order = \front\factory\ShopOrder::order_details( null, \S::get( 'order_hash' ) );
|
||||
|
||||
return \Tpl::view( 'shop-order/payment-confirmation', [
|
||||
'order' => $order,
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
|
||||
public static function payment_status_tpay()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \S::get( 'tr_status' ) == 'TRUE' and \S::get( 'tr_crc' ) )
|
||||
{
|
||||
$order = new \shop\Order( 0, \S::get( 'tr_crc' ) );
|
||||
|
||||
if ( $order -> id )
|
||||
{
|
||||
$order -> set_as_paid( true );
|
||||
$order -> update_status( 4, true );
|
||||
echo 'TRUE';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
echo 'FALSE';
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function payment_status_przelewy24pl()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$post = [
|
||||
'p24_merchant_id' => \S::get( 'p24_merchant_id' ),
|
||||
'p24_pos_id' => \S::get( 'p24_pos_id' ),
|
||||
'p24_session_id' => \S::get( 'p24_session_id' ),
|
||||
'p24_amount' => \S::get( 'p24_amount' ),
|
||||
'p24_currency' => \S::get( 'p24_currency' ),
|
||||
'p24_order_id' => \S::get( 'p24_order_id' ),
|
||||
'p24_sign' => md5( \S::get( 'p24_session_id' ) . '|' . \S::get( 'p24_order_id' ) . '|' . \S::get( 'p24_amount' ) . '|' . \S::get( 'p24_currency' ) . '|' . $settings['przelewy24_crc_key'] )
|
||||
];
|
||||
|
||||
$ch = curl_init();
|
||||
if ( $settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://sandbox.przelewy24.pl/trnVerify' );
|
||||
if ( !$settings['przelewy24_sandbox'] )
|
||||
curl_setopt( $ch, CURLOPT_URL, 'https://secure.przelewy24.pl/trnVerify' );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $post ) );
|
||||
$response = curl_exec( $ch );
|
||||
|
||||
$order = new \shop\Order( 0, '', \S::get( 'p24_session_id' ) );
|
||||
|
||||
if ( $order['status'] == 0 and $order['summary'] * 100 == \S::get( 'p24_amount' ) )
|
||||
{
|
||||
if ( $order['id'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 4;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Zamówienie opłacone przez przelewy24 | ID: ' . $order['id'] );
|
||||
}
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function payment_status_hotpay()
|
||||
{
|
||||
global $mdb, $lang;
|
||||
|
||||
if ( !empty( $_POST["KWOTA"] ) && !empty( $_POST["ID_PLATNOSCI"] ) && !empty( $_POST["ID_ZAMOWIENIA"] ) && !empty( $_POST["STATUS"] ) && !empty( $_POST["SEKRET"] ) && !empty( $_POST["HASH"] ) )
|
||||
{
|
||||
$order = new \shop\Order( $_POST['ID_ZAMOWIENIA'] );
|
||||
|
||||
if ( $order['id'] )
|
||||
{
|
||||
if ( is_array( $order['products'] ) and count( $order['products'] ) ):
|
||||
foreach ( $order['products'] as $product ):
|
||||
$product_tmp = \front\factory\ShopProduct::product_details( $product['product_id'], $lang['id'] );
|
||||
$summary_tmp += \S::normalize_decimal( $product['price_netto'] + $product['price_netto'] * $product['vat'] / 100 ) * $product['quantity'];
|
||||
endforeach;
|
||||
$summary_tmp += $order['transport_cost'];
|
||||
endif;
|
||||
|
||||
if ( hash( "sha256", "ProjectPro1916;" . round( $summary_tmp, 2 ) . ";" . $_POST["ID_PLATNOSCI"] . ";" . $_POST["ID_ZAMOWIENIA"] . ";" . $_POST["STATUS"] . ";" . $_POST["SEKRET"] ) == $_POST["HASH"] )
|
||||
{
|
||||
if ( $_POST["STATUS"] == "SUCCESS" )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 1, 'paid' => 1 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 1, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 4;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Zamówienie opłacone przez hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'zamowienie-zostalo-oplacone' );
|
||||
}
|
||||
else if ( $_POST["STATUS"] == "FAILURE" )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 2 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 2, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 2;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Płatność odrzucona hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'platnosc-zostala-odrzucona' );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => 3 ], [ 'id' => $order['id'] ] );
|
||||
$mdb -> insert( 'pp_shop_order_statuses', [ 'order_id' => $order['id'], 'status_id' => 3, 'mail' => 1 ] );
|
||||
|
||||
$order -> status = 3;
|
||||
$order -> send_status_change_email();
|
||||
\Log::save_log( 'Płatność sprawdzana ręcznie hotpay | ID: ' . $order['id'] );
|
||||
|
||||
echo \S::lang( 'zamowienie-zostalo-oplacone-reczne' );
|
||||
}
|
||||
}
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function order_details()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \S::lang( 'meta-title-szczegoly-zamowienia' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \Tpl::view( 'shop-order/order-details', [
|
||||
'order' => \front\factory\ShopOrder::order_details(
|
||||
\front\factory\ShopOrder::order_id( \S::get( 'order_hash' ) )
|
||||
),
|
||||
'client' => \S::get_session( 'client' ),
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
}
|
||||
48
autoload/front/controls/class.ShopProducer.php
Normal file
48
autoload/front/controls/class.ShopProducer.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?
|
||||
namespace front\controls;
|
||||
class ShopProducer
|
||||
{
|
||||
static public function products()
|
||||
{
|
||||
global $page, $lang_id;
|
||||
|
||||
$producer = new \shop\Producer( \S::get( 'producer_id' ) );
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = $producer['name'];
|
||||
|
||||
$results = \shop\Producer::producer_products( $producer['id'], $lang_id, (int) \S::get( 'bs' ) );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$pager = \Tpl::view( 'site/pager', [
|
||||
'ls' => $results['ls'],
|
||||
'bs' => (int) \S::get( 'bs' ) ? (int) \S::get( 'bs' ) : 1,
|
||||
'page' => $page,
|
||||
'link' => 'producent/' . \S::seo( $producer['name'] )
|
||||
] );
|
||||
}
|
||||
|
||||
return \Tpl::view( 'shop-producer/products', [
|
||||
'producer' => $producer,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager
|
||||
] );
|
||||
}
|
||||
|
||||
static public function list()
|
||||
{
|
||||
global $mdb, $page;
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['title'] = 'Producenci';
|
||||
|
||||
$rows = $mdb -> select( 'pp_shop_producer', 'id', [ 'status' => 1, 'ORDER' => [ 'name' => 'ASC' ] ] );
|
||||
if ( \S::is_array_fix( $rows ) ) foreach ( $rows as $row )
|
||||
$producers[] = new \shop\Producer( $row );
|
||||
|
||||
return \Tpl::view( 'shop-producer/list', [
|
||||
'producers' => $producers
|
||||
] );
|
||||
}
|
||||
}
|
||||
63
autoload/front/controls/class.ShopProduct.php
Normal file
63
autoload/front/controls/class.ShopProduct.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
use shop\Product;
|
||||
|
||||
class ShopProduct
|
||||
{
|
||||
static public function lazy_loading_products()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$output = '';
|
||||
$products_ids = \front\factory\ShopCategory::products_id( \S::get( 'category_id' ), \front\factory\ShopCategory::get_category_sort( (int)\S::get( 'category_id' ) ), $lang_id, 8, \S::get( 'offset' ) );
|
||||
|
||||
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
|
||||
$output .= \Tpl::view('shop-product/product-mini', [
|
||||
'product' => Product::getFromCache( $product_id, $lang_id )
|
||||
] );
|
||||
endforeach;
|
||||
endif;
|
||||
|
||||
echo json_encode( [ 'html' => $output ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function warehouse_message()
|
||||
{
|
||||
global $lang_id;
|
||||
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
foreach( $values as $key => $val )
|
||||
{
|
||||
if ( $key != 'product-id' and $key != 'quantity' )
|
||||
$attributes[] = $val;
|
||||
}
|
||||
|
||||
$result = \shop\Product::getWarehouseMessage( $values['product-id'], $attributes, $lang_id );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
// wyświetlenie atrybutów w widoku produktu
|
||||
static public function draw_product_attributes()
|
||||
{
|
||||
global $mdb, $lang_id;
|
||||
|
||||
$combination = '';
|
||||
|
||||
$selected_values = \S::get( 'selected_values' );
|
||||
foreach ( $selected_values as $value ) {
|
||||
$combination .= $value;
|
||||
if ( $value != end( $selected_values ) )
|
||||
$combination .= '|';
|
||||
}
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = Product::getFromCache( $product_id, $lang_id );
|
||||
$product_data = $product -> getProductDataBySelectedAttributes( $combination );
|
||||
|
||||
echo json_encode( [ 'product_data' => $product_data ] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
136
autoload/front/controls/class.Site.php
Normal file
136
autoload/front/controls/class.Site.php
Normal file
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
|
||||
class Site
|
||||
{
|
||||
static public function page_title()
|
||||
{
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$property = \S::get( 'action' );
|
||||
if ( class_exists( $class ) and property_exists( new $class, 'page_title' ) )
|
||||
return $class::$title[$property];
|
||||
}
|
||||
|
||||
static public function title()
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$property = \S::get( 'action' );
|
||||
if ( class_exists( $class ) and property_exists( new $class, 'title' ) )
|
||||
return $class::$title[$property] . ' | ' . $settings['firm_name'];
|
||||
}
|
||||
|
||||
public static function route( $product = '', $category = '' )
|
||||
{
|
||||
global $page, $lang_id, $settings;
|
||||
|
||||
if ( \S::get( 'article' ) )
|
||||
return \front\view\Articles::full_article( \S::get( 'article' ), $lang_id );
|
||||
|
||||
// wyświetlenie pojedynczego produktu
|
||||
if ( $product )
|
||||
{
|
||||
\shop\Product::add_visit( $product -> id );
|
||||
return \Tpl::view( 'shop-product/product', [
|
||||
'product' => $product,
|
||||
'settings' => $settings,
|
||||
'lang_id' => $lang_id,
|
||||
'settings' => $settings
|
||||
] );
|
||||
}
|
||||
|
||||
if ( $category )
|
||||
return \front\view\ShopCategory::category_view( $category, $lang_id, \S::get( 'bs' ) );
|
||||
|
||||
// stare klasy
|
||||
$class = '\front\controls\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$action = \S::get( 'action' );
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
|
||||
// klasy sklepowe
|
||||
$class = '\shop\\';
|
||||
|
||||
$results = explode( '_', \S::get( 'module' ) );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$class .= ucfirst( $row );
|
||||
|
||||
$action = \S::get( 'action' );
|
||||
|
||||
if ( class_exists( $class ) and method_exists( new $class, $action ) )
|
||||
return call_user_func_array( array( $class, $action ), array() );
|
||||
|
||||
if ( $page['id'] )
|
||||
{
|
||||
switch ( $page['page_type'] )
|
||||
{
|
||||
/* pełne artykuły */
|
||||
case 0:
|
||||
return \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* wprowadzenia */
|
||||
case 1:
|
||||
return \front\view\Articles::entry_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* miniaturki */
|
||||
case 2:
|
||||
return \front\view\Articles::miniature_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
break;
|
||||
|
||||
/* strona kontaktu */
|
||||
case 4:
|
||||
$out = \front\view\Articles::full_articles_list( $page, $lang_id, \S::get( 'bs' ) );
|
||||
$out .= \front\view\Site::contact();
|
||||
return $out;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function check_url_params()
|
||||
{
|
||||
global $lang, $config;
|
||||
|
||||
$a = \S::get( 'a' );
|
||||
|
||||
switch ( $a )
|
||||
{
|
||||
case 'page':
|
||||
$page = \front\factory\Pages::page_details( \S::get( 'id' ) );
|
||||
\S::set_session( 'page', $page );
|
||||
break;
|
||||
|
||||
case 'change_language':
|
||||
\S::set_session( 'current-lang', \S::get( 'id' ) );
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( \S::get( 'lang' ) )
|
||||
\S::set_session( 'current-lang', \S::get( 'lang' ) );
|
||||
|
||||
if ( file_exists( 'modules/actions.php' ) )
|
||||
include 'modules/actions.php';
|
||||
}
|
||||
}
|
||||
?>
|
||||
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;
|
||||
}
|
||||
}
|
||||
90
autoload/front/view/class.Articles.php
Normal file
90
autoload/front/view/class.Articles.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Articles
|
||||
{
|
||||
public static function news( $page_id, $articles )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> page_id = $page_id;
|
||||
$tpl -> articles = $articles;
|
||||
return $tpl -> render( 'articles/news' );
|
||||
}
|
||||
|
||||
public static function full_article( $article_id, $lang_id )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> article = \front\factory\Articles::article_details( $article_id, $lang_id );
|
||||
return $tpl -> render( 'articles/article' );
|
||||
}
|
||||
|
||||
public static function miniature_articles_list( $page, $lang_id, $bs = 1 )
|
||||
{
|
||||
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
|
||||
|
||||
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> article = \front\factory\Articles::article_details( $article, $lang_id );
|
||||
$out .= $tpl -> render( 'articles/article-miniature' );
|
||||
}
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> page = $page;
|
||||
$out .= $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function entry_articles_list( $page, $lang_id, $bs = 1 )
|
||||
{
|
||||
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
|
||||
|
||||
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
|
||||
$articles[] = \front\factory\Articles::article_details( $article, $lang_id );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> page_id = $page['id'];
|
||||
$tpl -> articles = $articles;
|
||||
$out .= $tpl -> render( 'articles/articles-entries' );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> page = $page;
|
||||
$out .= $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
public static function full_articles_list( $page, $lang_id, $bs = 1 )
|
||||
{
|
||||
$results = \front\factory\Articles::page_articles( $page, $lang_id, $bs );
|
||||
|
||||
if ( is_array( $results['articles'] ) ) foreach ( $results['articles'] as $article )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> article = \front\factory\Articles::article_details( $article, $lang_id );
|
||||
$out .= $tpl -> render( 'articles/article-full' );
|
||||
}
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> page = $page;
|
||||
$out .= $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
}
|
||||
22
autoload/front/view/class.Banners.php
Normal file
22
autoload/front/view/class.Banners.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Banners
|
||||
{
|
||||
public static function banners( $banners )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> banners = $banners;
|
||||
return $tpl -> render( 'banner/banners' );
|
||||
}
|
||||
|
||||
public static function main_banner( $banner )
|
||||
{
|
||||
if ( !\S::get_session( 'banner_close' ) && is_array( $banner ) )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> banner = $banner;
|
||||
return $tpl -> render( 'banner/main-banner' );
|
||||
}
|
||||
}
|
||||
}
|
||||
12
autoload/front/view/class.Languages.php
Normal file
12
autoload/front/view/class.Languages.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Languages
|
||||
{
|
||||
public static function languages()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> languages = \front\factory\Languages::active_languages();
|
||||
return $tpl -> render( 'site/languages' );
|
||||
}
|
||||
}
|
||||
22
autoload/front/view/class.Menu.php
Normal file
22
autoload/front/view/class.Menu.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Menu
|
||||
{
|
||||
public static function pages( $pages, $level = 0, $current_page = 0 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> pages = $pages;
|
||||
$tpl -> level = $level;
|
||||
$tpl -> current_page = $current_page;
|
||||
return $tpl -> render( 'menu/pages' );
|
||||
}
|
||||
|
||||
public static function menu( $menu, $current_page )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> menu = $menu;
|
||||
$tpl -> current_page = $current_page;
|
||||
return $tpl -> render( 'menu/menu' );
|
||||
}
|
||||
}
|
||||
11
autoload/front/view/class.Newsletter.php
Normal file
11
autoload/front/view/class.Newsletter.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Newsletter
|
||||
{
|
||||
public static function newsletter()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'newsletter/newsletter' );
|
||||
}
|
||||
}
|
||||
12
autoload/front/view/class.Scontainers.php
Normal file
12
autoload/front/view/class.Scontainers.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
|
||||
class Scontainers
|
||||
{
|
||||
public static function scontainer( $id )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> scontainer = \front\factory\Scontainers::scontainer_details( $id );
|
||||
return $tpl -> render( 'scontainers/scontainer' );
|
||||
}
|
||||
}
|
||||
56
autoload/front/view/class.ShopCategory.php
Normal file
56
autoload/front/view/class.ShopCategory.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopCategory
|
||||
{
|
||||
static public function category_description( $category )
|
||||
{
|
||||
return \Tpl::view( 'shop-category/category-description', [
|
||||
'category' => $category
|
||||
] );
|
||||
}
|
||||
|
||||
static public function category_view( $category, $lang_id, $bs = 1 )
|
||||
{
|
||||
global $settings, $page;
|
||||
|
||||
if ( !$settings['infinitescroll'] )
|
||||
{
|
||||
$results = \front\factory\ShopCategory::category_products( $category, $lang_id, $bs );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> page = $page;
|
||||
$tpl -> link = $category['language']['seo_link'] ? $url = $category['language']['seo_link'] : $url = 'k-' . $category['id'] . '-' . \S::seo( $category['language']['title'] );
|
||||
$pager = $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return \Tpl::view( 'shop-category/category', [
|
||||
'category' => $category,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager,
|
||||
'category_description' => (int)$bs <= 1 ? true : false,
|
||||
'category_additional_text' => true
|
||||
] );
|
||||
}
|
||||
|
||||
$products_count = \front\factory\ShopCategory::category_products_count( $category, $lang_id );
|
||||
return \Tpl::view( 'shop-category/category-infinitescroll', [
|
||||
'category' => $category,
|
||||
'products_count' => $products_count,
|
||||
'category_description' => (int)$bs <= 1 ? true : false,
|
||||
'category_additional_text' => true
|
||||
] );
|
||||
}
|
||||
|
||||
public static function categories( $categories, $current_category = 0, $level = 0 )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> level = $level;
|
||||
$tpl -> current_category = $current_category;
|
||||
$tpl -> categories = $categories;
|
||||
return $tpl -> render( 'shop-category/categories' );
|
||||
}
|
||||
}
|
||||
65
autoload/front/view/class.ShopClient.php
Normal file
65
autoload/front/view/class.ShopClient.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopClient
|
||||
{
|
||||
public static function address_edit( $values )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/address-edit' );
|
||||
}
|
||||
|
||||
public static function client_addresses( $values )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-addresses' );
|
||||
}
|
||||
|
||||
|
||||
public static function client_menu( $values )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-menu' );
|
||||
}
|
||||
|
||||
public static function client_orders( $values )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-orders' );
|
||||
}
|
||||
|
||||
public static function recover_password()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'shop-client/recover-password' );
|
||||
}
|
||||
|
||||
public static function mini_login()
|
||||
{
|
||||
global $client;
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> client = $client;
|
||||
return $tpl -> render( 'shop-client/mini-login' );
|
||||
}
|
||||
|
||||
public static function login_form( $values = '' )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/login-form' );
|
||||
}
|
||||
|
||||
public static function register_form()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'shop-client/register-form' );
|
||||
}
|
||||
}
|
||||
12
autoload/front/view/class.ShopOrder.php
Normal file
12
autoload/front/view/class.ShopOrder.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopOrder
|
||||
{
|
||||
public static function order_details( $values )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-order/order-details' );
|
||||
}
|
||||
}
|
||||
12
autoload/front/view/class.ShopPaymentMethod.php
Normal file
12
autoload/front/view/class.ShopPaymentMethod.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
public static function basket_payment_methods( $payment_methods, $payment_id )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> payment_methods = $payment_methods;
|
||||
$tpl -> payment_id = $payment_id;
|
||||
return $tpl -> render( 'shop-basket/basket-payments-methods' );
|
||||
}
|
||||
}
|
||||
6
autoload/front/view/class.ShopTransport.php
Normal file
6
autoload/front/view/class.ShopTransport.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopTransport
|
||||
{
|
||||
|
||||
}
|
||||
482
autoload/front/view/class.Site.php
Normal file
482
autoload/front/view/class.Site.php
Normal file
@@ -0,0 +1,482 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
use shop\Product;
|
||||
|
||||
class Site
|
||||
{
|
||||
const menu_pattern = '/MENU:[0-9]*/';
|
||||
const menu_main_pattern = '/MENU_GLOWNE:[0-9]*/';
|
||||
const container_pattern = '/KONTENER:[0-9]*/';
|
||||
const language_pattern = '/LANG:[a-zA-Z0-9_-]*/';
|
||||
const products_promoted = '/PROMOWANE_PRODUKTY((:([0-9]*))?)/';
|
||||
const news_pattern = '/AKTUALNOSCI:([0-9]*)((:([0-9]*))?)/';
|
||||
const article_products_category_pattern = '/PRODUKTY_KATEGORIA:([0-9]*)((:([0-9]*))?)/';
|
||||
const news_list_pattern = '/AKTUALNOSCI_LISTA:([0-9]*)((:([0-9]*))?)/';
|
||||
const top_news_pattern = '/NAJPOULARNIEJSZE_ARTYKULY:([0-9]*)((:([0-9]*))?)/';
|
||||
const single_product_pattern = '/PRODUKT:[0-9]*/';
|
||||
const products_box = '/PRODUKTY_BOX:[0-9,]*/';
|
||||
const produkty_top = '/PRODUKTY_TOP((:([0-9]*))?)/';
|
||||
const produkty_new = '/PRODUKTY_NEW((:([0-9]*))?)/';
|
||||
|
||||
public static function show()
|
||||
{
|
||||
global $page, $settings, $settings, $lang, $lang_id;
|
||||
|
||||
if ( (int) \S::get( 'layout_id' ) )
|
||||
$layout = new \cms\Layout( (int) \S::get( 'layout_id' ) );
|
||||
|
||||
if ( \S::get( 'article' ) )
|
||||
$layout = \front\factory\Layouts::article_layout( \S::get( 'article' ) );
|
||||
|
||||
if ( \S::get( 'product' ) )
|
||||
$layout = \front\factory\Layouts::product_layout( \S::get( 'product' ) );
|
||||
|
||||
if ( \S::get( 'category' ) )
|
||||
$layout = \front\factory\Layouts::category_layout( \S::get( 'category' ) );
|
||||
|
||||
if ( !$layout )
|
||||
$layout = \front\factory\Layouts::active_layout( $page['id'] );
|
||||
|
||||
if ( $settings['devel'] == true and file_exists( 'devel.html' ) )
|
||||
$html = file_get_contents( 'devel.html' );
|
||||
else
|
||||
{
|
||||
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
|
||||
$html = $layout['m_html'];
|
||||
else
|
||||
$html = $layout['html'];
|
||||
}
|
||||
|
||||
if ( $settings['facebook_link'] )
|
||||
$html = str_replace( '</body>', \front\view\Site::facebook( $settings['facebook_link'] ) . '</body>', $html );
|
||||
|
||||
$html = str_replace( '[COPYRIGHT]',
|
||||
\front\view\Site::copyright(),
|
||||
$html );
|
||||
|
||||
$html = str_replace( '[BANER_STRONA_GLOWNA]', \front\view\Banners::main_banner( \front\factory\Banners::main_banner() ), $html );
|
||||
$html = str_replace( '[BANERY]', \front\view\Banners::banners( \front\factory\Banners::banners() ), $html );
|
||||
|
||||
$html = str_replace( '[KATEGORIE]', \Tpl::view( 'shop-category/categories', [
|
||||
'level' => $level,
|
||||
'current_category' => \S::get( 'category' ),
|
||||
'categories' => \front\factory\ShopCategory::categories_details()
|
||||
] ), $html );
|
||||
|
||||
/* BOX - promowane produkty */
|
||||
preg_match_all( self::products_promoted, $html, $products_promoted_list );
|
||||
if ( is_array( $products_promoted_list[0] ) ) foreach( $products_promoted_list[0] as $products_promoted_tmp )
|
||||
{
|
||||
$products_promoted_tmp = explode( ':', $products_promoted_tmp );
|
||||
$products_promoted_tmp[1] ? $limit = $products_promoted_tmp[1] : $limit = 6;
|
||||
|
||||
$products_promoted_tmp[1] ? $pattern = '[PROMOWANE_PRODUKTY:' . $products_promoted_tmp[1] . ']' : $pattern = '[PROMOWANE_PRODUKTY]';
|
||||
|
||||
$html = str_replace( $pattern,
|
||||
\Tpl::view( 'shop-product/promoted-products', [
|
||||
'products' => \front\factory\ShopProduct::promoted_products( $limit )
|
||||
] ),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/* BOX - aktualnsci */
|
||||
preg_match_all( self::news_pattern, $html, $news_list );
|
||||
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
|
||||
{
|
||||
$news_list_tmp = explode( ':', $news_list_tmp );
|
||||
|
||||
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
|
||||
|
||||
$news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI:' . $news_list_tmp[1] . ']';
|
||||
$html = str_replace( $pattern, \front\view\Articles::news(
|
||||
$news_list_tmp[1],
|
||||
\front\factory\Articles::news( $news_list_tmp[1], $news_limit, $lang_id )
|
||||
), $html );
|
||||
}
|
||||
|
||||
$html = str_replace( '[KOSZYK]',
|
||||
\Tpl::view( 'shop-basket/basket-mini', [
|
||||
'basket' => \S::get_session( 'basket' ),
|
||||
'lang_id' => $lang_id,
|
||||
'coupon' => \S::get_session( 'coupon' )
|
||||
] ),
|
||||
$html );
|
||||
$html = str_replace( '[NEWSLETTER]',
|
||||
\front\view\Newsletter::newsletter(),
|
||||
$html );
|
||||
$html = str_replace( '[UZYTKOWNIK_MINI_LOGOWANIE]',
|
||||
\front\view\ShopClient::mini_login(),
|
||||
$html );
|
||||
|
||||
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
|
||||
$html = str_replace( '[CSS]', $layout['m_css'], $html );
|
||||
else
|
||||
$html = str_replace( '[CSS]', $layout['css'], $html );
|
||||
|
||||
if ( \S::is_mobile() and !empty( $layout['m_html'] ) )
|
||||
$html = str_replace( '[JAVA_SCRIPT]', $layout['m_js'], $html );
|
||||
else
|
||||
$html = str_replace( '[JAVA_SCRIPT]', $layout['js'], $html );
|
||||
|
||||
preg_match_all( self::menu_pattern, $html, $menu );
|
||||
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
|
||||
{
|
||||
$menu_tmp = explode( ':', $menu_tmp );
|
||||
$html = str_replace( '[MENU:' . $menu_tmp[1] . ']', \front\view\Menu::menu( \front\factory\Menu::menu_details( $menu_tmp[1] ), $page['id'] ), $html );
|
||||
}
|
||||
|
||||
preg_match_all( self::menu_main_pattern, $html, $menu );
|
||||
if ( is_array( $menu[0] ) ) foreach( $menu[0] as $menu_tmp )
|
||||
{
|
||||
$menu_tmp = explode( ':', $menu_tmp );
|
||||
$html = str_replace(
|
||||
'[MENU_GLOWNE:' . $menu_tmp[1] . ']',
|
||||
\Tpl::view( 'menu/main-menu', [
|
||||
'menu' => \front\factory\Menu::menu_details( $menu_tmp[1] )
|
||||
] ),
|
||||
$html );
|
||||
}
|
||||
|
||||
preg_match_all( self::language_pattern, $html, $language_list );
|
||||
if ( is_array( $language_list[0] ) ) foreach( $language_list[0] as $language_list_tmp )
|
||||
{
|
||||
$language_list_tmp = explode( ':', $language_list_tmp );
|
||||
$html = str_replace( '[LANG:' . $language_list_tmp[1] . ']', $lang[ $language_list_tmp[1] ], $html );
|
||||
}
|
||||
|
||||
//
|
||||
// KATEGORIA SKLEPU
|
||||
//
|
||||
if ( \S::get( 'category' ) )
|
||||
{
|
||||
$category = \front\factory\ShopCategory::category_details( \S::get( 'category' ) );
|
||||
|
||||
if ( $category['language']['meta_title'] )
|
||||
$page['language']['title'] = $category['language']['meta_title'];
|
||||
else
|
||||
$page['language']['title'] = $category['language']['title'];
|
||||
|
||||
$page['show_title'] = true;
|
||||
$page['language']['meta_keywords'] = $category['language']['meta_keywords'];
|
||||
$page['language']['meta_description'] = $category['language']['meta_description'];
|
||||
$page['language']['page_title'] = $category['language']['category_title'] ? $category['language']['category_title'] : $category['language']['title'];
|
||||
|
||||
// CANONICAL
|
||||
$html = str_replace( '[CANONICAL]', '', $html );
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ARTYKUŁ
|
||||
//
|
||||
if ( \S::get( 'article' ) )
|
||||
{
|
||||
$article = \front\factory\Articles::article_details( \S::get( 'article' ), $lang_id );
|
||||
|
||||
if ( $article['language']['meta_title'] )
|
||||
$page['language']['title'] = $article['language']['meta_title'];
|
||||
else
|
||||
$page['language']['title'] = $article['language']['title'];
|
||||
|
||||
$page['show_title'] = false;
|
||||
$page['language']['meta_keywords'] = $article['language']['meta_keywords'];
|
||||
$page['language']['meta_description'] = $article['language']['meta_description'];
|
||||
|
||||
// CANONICAL
|
||||
$html = str_replace( '[CANONICAL]', '', $html );
|
||||
}
|
||||
|
||||
//
|
||||
// PRODUKT
|
||||
//
|
||||
if ( \S::get( 'product' ) )
|
||||
{
|
||||
$product = Product::getFromCache( \S::get( 'product' ), $lang_id, $_GET['permutation_hash'] );
|
||||
|
||||
if ( $product['language']['meta_title'] )
|
||||
$page['language']['title'] = $product['language']['meta_title'];
|
||||
else
|
||||
$page['language']['title'] = $product['language']['name'];
|
||||
|
||||
$page['show_title'] = false;
|
||||
$page['language']['meta_keywords'] = $product['language']['meta_keywords'];
|
||||
$page['language']['meta_description'] = $product['language']['meta_description'];
|
||||
|
||||
// CANONICAL
|
||||
if ( $product['language']['canonical'] )
|
||||
$html = str_replace( '[CANONICAL]', '<link rel="canonical" href="' . $product['language']['canonical'] . '">', $html );
|
||||
else
|
||||
$html = str_replace( '[CANONICAL]', '', $html );
|
||||
}
|
||||
|
||||
//
|
||||
// PRODUCENT
|
||||
//
|
||||
if ( \S::get( 'producer_id' ) )
|
||||
{
|
||||
$producer = new \shop\Producer( \S::get( 'producer_id' ) );
|
||||
|
||||
if ( $producer['languages'][$lang_id]['meta_title'] )
|
||||
$page['language']['meta_title'] = $producer['languages'][$lang_id]['meta_title'];
|
||||
}
|
||||
|
||||
//
|
||||
// STRONA CMS
|
||||
//
|
||||
if ( $page )
|
||||
{
|
||||
// CANONICAL
|
||||
$html = str_replace( '[CANONICAL]', '', $html );
|
||||
}
|
||||
|
||||
$html = str_replace( '[CANONICAL]', '', $html );
|
||||
$html = str_replace( '[ZAWARTOSC]', \front\controls\Site::route( $product, $category ), $html );
|
||||
|
||||
/* pojedynczy produkt */
|
||||
preg_match_all( self::single_product_pattern, $html, $single_product_array );
|
||||
if ( is_array( $single_product_array[0] ) ) foreach( $single_product_array[0] as $single_product )
|
||||
{
|
||||
$single_product = explode( ':', $single_product );
|
||||
$html = str_replace(
|
||||
'[PRODUKT:' . $single_product[1] . ']',
|
||||
\Tpl::view( 'shop-product/product-mini', [
|
||||
'product' => \shop\Product::getFromCache( (int)$single_product[1], $lang_id )
|
||||
] ),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/* lista produktów */
|
||||
preg_match_all( self::products_box, $html, $products_box_array );
|
||||
if ( is_array( $products_box_array[0] ) ) foreach( $products_box_array[0] as $products_box )
|
||||
{
|
||||
unset( $products_id ); unset( $product_id ); unset( $products );
|
||||
|
||||
$products_box = explode( ':', $products_box );
|
||||
$products_id = explode( ',', $products_box[1] );
|
||||
|
||||
foreach ( $products_id as $product_id )
|
||||
$products[] = Product::getFromCache( (int)$product_id, $lang_id );
|
||||
|
||||
|
||||
$html = str_replace(
|
||||
'[PRODUKTY_BOX:' . $products_box[1] . ']',
|
||||
\Tpl::view( 'shop-product/products-box', [
|
||||
'products' => $products
|
||||
] ),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/* lista popularnych produktów */
|
||||
preg_match_all( self::produkty_top, $html, $products_top_array );
|
||||
if ( is_array( $products_top_array[0] ) ) foreach( $products_top_array[0] as $products_top )
|
||||
{
|
||||
unset( $products_id_arr );
|
||||
unset( $limit );
|
||||
unset( $product_id );
|
||||
unset( $top_products_arr );
|
||||
|
||||
$products_top = explode( ':', $products_top );
|
||||
$products_top[1] ? $limit = $products_top[1] : $limit = 6;
|
||||
|
||||
$products_top[1] ? $pattern = '[PRODUKTY_TOP:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_TOP]';
|
||||
|
||||
$products_id_arr = \front\factory\ShopProduct::top_products( $limit );
|
||||
|
||||
foreach ( $products_id_arr as $product_id ){
|
||||
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
|
||||
}
|
||||
|
||||
$html = str_replace( $pattern,
|
||||
\Tpl::view( 'shop-product/products-top', [
|
||||
'products' => $top_products_arr,
|
||||
] ),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
/* lista ostatnio dodanych produktów */
|
||||
preg_match_all( self::produkty_new, $html, $products_top_array );
|
||||
if ( is_array( $products_top_array[0] ) ) foreach( $products_top_array[0] as $products_top )
|
||||
{
|
||||
unset( $products_id_arr );
|
||||
unset( $limit );
|
||||
unset( $product_id );
|
||||
unset( $top_products_arr );
|
||||
|
||||
$products_top = explode( ':', $products_top );
|
||||
$products_top[1] ? $limit = $products_top[1] : $limit = 10;
|
||||
|
||||
$products_top[1] ? $pattern = '[PRODUKTY_NEW:' . $products_top[1] . ']' : $pattern = '[PRODUKTY_NEW]';
|
||||
|
||||
$products_id_arr = \front\factory\ShopProduct::new_products( $limit );
|
||||
|
||||
|
||||
foreach ( $products_id_arr as $product_id ){
|
||||
$top_products_arr[] = Product::getFromCache( (int)$product_id, $lang_id );
|
||||
}
|
||||
|
||||
$html = str_replace( $pattern,
|
||||
\Tpl::view( 'shop-product/products-new', [
|
||||
'products' => $top_products_arr,
|
||||
] ),
|
||||
$html
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
$html = str_replace( '[TITLE]', $page['language']['meta_title'] ? $page['language']['meta_title'] . ' | ' . $settings['firm_name'] : $page['language']['title'] . ' | ' . $settings['firm_name'], $html );
|
||||
$html = str_replace( '[META_KEYWORDS]', $page['language']['meta_keywords'], $html );
|
||||
$html = str_replace( '[META_DESCRIPTION]', $page['language']['meta_description'], $html );
|
||||
$html = str_replace( '[JEZYKI]', \front\view\Languages::languages(), $html );
|
||||
$html = str_replace( '[TYTUL_STRONY]', self::title( $page['language']['title'], $page['show_title'], $page['language']['page_title'] ), $html );
|
||||
$html = str_replace( '[WYSZUKIWARKA]', \shop\Search::simple_form(), $html );
|
||||
|
||||
/* atrybut noindex */
|
||||
if ( \S::get( 'article' ) )
|
||||
{
|
||||
\front\factory\Articles::article_noindex( \S::get( 'article' ) ) ? $noindex = 'noindex' : $noindex = 'all';
|
||||
$html = str_replace( '[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html );
|
||||
}
|
||||
else
|
||||
{
|
||||
$page['language']['noindex'] ? $noindex = 'noindex' : $noindex = 'all';
|
||||
$html = str_replace( '[META_INDEX]', '<meta name="robots" content="' . $noindex . '">', $html );
|
||||
}
|
||||
|
||||
if ( $page['language']['canonical'] )
|
||||
$html = str_replace( '</head>', '<link rel="canonical" href="' . $page['language']['canonical'] . '" /></head>', $html );
|
||||
|
||||
while ( strpos( $html, '[PHP]' ) !== false )
|
||||
{
|
||||
$text = explode( '[PHP]', $html );
|
||||
$before = $text[0];
|
||||
for ( $i = 1; $i < count( $text ); $i++ )
|
||||
{
|
||||
$temp = explode( '[/PHP]' , $text[$i] );
|
||||
$code = $temp[0];
|
||||
|
||||
ob_start();
|
||||
eval( $code );
|
||||
$out .= ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$out .= $temp[1];
|
||||
}
|
||||
$html = $before . $out;
|
||||
}
|
||||
|
||||
/* BOX - blog produkty kategoria */
|
||||
preg_match_all( self::article_products_category_pattern, $html, $category_list );
|
||||
if ( is_array( $category_list[0] ) ) foreach( $category_list[0] as $category_list_tmp )
|
||||
{
|
||||
$category_list_tmp = explode( ':', $category_list_tmp );
|
||||
|
||||
$category_list_tmp[2] != '' ? $products_limit = $category_list_tmp[2] : $products_limit = 4;
|
||||
|
||||
$category_list_tmp[2] != '' ? $pattern = '[PRODUKTY_KATEGORIA:' . $category_list_tmp[1] . ':' . $category_list_tmp[2] . ']' : $pattern = '[PRODUKTY_KATEGORIA:' . $category_list_tmp[1] . ']';
|
||||
|
||||
$html = str_replace(
|
||||
$pattern,
|
||||
\Tpl::view( 'shop-category/blog-category-products', [
|
||||
'products' => \front\factory\ShopCategory::blog_category_products( $category_list_tmp[1], $lang_id, $products_limit )
|
||||
] ),
|
||||
$html );
|
||||
}
|
||||
|
||||
// prosta lista aktualności z wybranej podstrony
|
||||
preg_match_all( self::news_list_pattern, $html, $news_list );
|
||||
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
|
||||
{
|
||||
$news_list_tmp = explode( ':', $news_list_tmp );
|
||||
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
|
||||
$news_list_tmp[2] != '' ? $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[AKTUALNOSCI_LISTA:' . $news_list_tmp[1] . ']';
|
||||
|
||||
$news_list = \Article::getNews( $news_list_tmp[1], $news_limit, $lang_id );
|
||||
$view_news_list = \Article::newsList( $news_list );
|
||||
$html = str_replace( $pattern, $view_news_list, $html );
|
||||
}
|
||||
|
||||
// prosta lista z najpopularniejszymi artykułami
|
||||
preg_match_all( self::top_news_pattern, $html, $news_list );
|
||||
if ( is_array( $news_list[0] ) ) foreach( $news_list[0] as $news_list_tmp )
|
||||
{
|
||||
$news_list_tmp = explode( ':', $news_list_tmp );
|
||||
$news_list_tmp[2] != '' ? $news_limit = $news_list_tmp[2] : $news_limit = $settings['news_limit'];
|
||||
$news_list_tmp[2] != '' ? $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ':' . $news_list_tmp[2] . ']' : $pattern = '[NAJPOULARNIEJSZE_ARTYKULY:' . $news_list_tmp[1] . ']';
|
||||
|
||||
$news_list = \Article::getTopNews( $news_list_tmp[1], $news_limit, $lang_id );
|
||||
$view_news_list = \Article::newsList( $news_list );
|
||||
$html = str_replace( $pattern, $view_news_list, $html );
|
||||
}
|
||||
|
||||
$html = str_replace( '[ALERT]', \front\view\Site::alert(), $html );
|
||||
|
||||
preg_match_all( self::container_pattern, $html, $container_list );
|
||||
if ( is_array( $container_list[0] ) ) foreach( $container_list[0] as $container_list_tmp )
|
||||
{
|
||||
$container_list_tmp = explode( ':', $container_list_tmp );
|
||||
$html = str_replace( '[KONTENER:' . $container_list_tmp[1] . ']', \front\view\Scontainers::scontainer( $container_list_tmp[1] ), $html );
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function facebook( $facebook_link )
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> facebook_link = $facebook_link;
|
||||
return $tpl -> render( 'site/facebook' );
|
||||
}
|
||||
|
||||
static public function title( $title, $show_title, $page_title )
|
||||
{
|
||||
return \Tpl::view( 'site/title', [
|
||||
'title' => $title,
|
||||
'page_title' => $page_title,
|
||||
'show_title' => $show_title
|
||||
] );
|
||||
}
|
||||
|
||||
public static function alert()
|
||||
{
|
||||
if ( $alert = \S::get_session( 'alert' ) )
|
||||
{
|
||||
\S::delete_session( 'alert' );
|
||||
|
||||
return $tpl = \Tpl::view( 'site/alert', [
|
||||
'alert' => $alert
|
||||
] );
|
||||
}
|
||||
|
||||
if ( $error = \S::get_session( 'error' ) )
|
||||
{
|
||||
\S::delete_session( 'error' );
|
||||
|
||||
$tpl = new \Tpl;
|
||||
$tpl -> error = $error;
|
||||
return $tpl -> render( 'site/error' );
|
||||
}
|
||||
}
|
||||
|
||||
public static function copyright()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'site/copyright' );
|
||||
}
|
||||
|
||||
public static function contact()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'site/contact' );
|
||||
}
|
||||
|
||||
public static function cookie_information()
|
||||
{
|
||||
$tpl = new \Tpl;
|
||||
return $tpl -> render( 'site/cookie-information' );
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user