first commit
This commit is contained in:
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';
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user