Dodanie funkcji czyszczenia cache oraz przycisku do ponownego wysyłania zamówienia do apilo.com; poprawa sortowania transportów w bazie danych
This commit is contained in:
@@ -206,6 +206,12 @@ if ( $this -> next_order_id )
|
||||
'class' => 'btn btn-success btn-sm mr5 ml5'
|
||||
];
|
||||
}
|
||||
$grid -> buttons[] = [
|
||||
'label' => 'Wyślij ponownie zamówienie do apilo.com',
|
||||
'url' => '/admin/shop_order/send_order_to_apilo/order_id=' . $this -> order['id'],
|
||||
'icon' => 'fa-refresh',
|
||||
'class' => 'btn btn-primary btn-sm mr5 ml5 pull-right btn-send-order-to-apilo'
|
||||
];
|
||||
$grid -> default_buttons = false;
|
||||
$grid -> external_code = $out;
|
||||
echo $grid -> draw();
|
||||
@@ -241,6 +247,38 @@ echo $grid -> draw();
|
||||
});
|
||||
}, 500 );
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.btn-send-order-to-apilo', function(e) {
|
||||
e.preventDefault();
|
||||
var href = $( this ).attr( 'href' );
|
||||
$.alert({
|
||||
title: 'Potwierdź',
|
||||
content: 'Czy na pewno chcesz wysłać zamówienie do apilo.com?',
|
||||
type: 'orange',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-times',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
columnClass: 'col-12 col-lg-10',
|
||||
theme: 'modern',
|
||||
icon: 'fa fa-question',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'Tak',
|
||||
btnClass: 'btn-success',
|
||||
keys: ['enter'],
|
||||
action: function() {
|
||||
document.location.href = href;
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: 'Nie',
|
||||
btnClass: 'btn-dark',
|
||||
action: function() {}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// set_order_as_unpaid
|
||||
|
||||
@@ -168,7 +168,10 @@
|
||||
<div class="site-content">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12 top-user">
|
||||
<div class="col-12 col-md-3 col-lg-2">
|
||||
<a href="/admin/settings/clear_cache/" class="btn btn-danger mt-3">Wyczyść cache</a>
|
||||
</div>
|
||||
<div class="col-12 col-md-9 col-lg-10 top-user">
|
||||
<div class="dropdown">
|
||||
<?
|
||||
if ( $user[ 'name' ] or $user[ 'surname' ] )
|
||||
|
||||
@@ -3,6 +3,19 @@ namespace admin\controls;
|
||||
|
||||
class Settings
|
||||
{
|
||||
static public function clear_cache()
|
||||
{
|
||||
\S::delete_dir( '../temp/' );
|
||||
\S::delete_dir( '../thumbs/' );
|
||||
|
||||
$redis = \RedisConnection::getInstance() -> getConnection();
|
||||
$redis -> flushAll();
|
||||
|
||||
\S::alert( 'Cache został wyczyszczony.' );
|
||||
header( 'Location: /admin/dashboard/main_view/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function settings_save()
|
||||
{
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
@@ -2,6 +2,18 @@
|
||||
namespace admin\controls;
|
||||
class ShopOrder
|
||||
{
|
||||
static public function send_order_to_apilo()
|
||||
{
|
||||
$order_id = \S::get( 'order_id' );
|
||||
if ( \admin\factory\ShopOrder::send_order_to_apilo( $order_id ) ) {
|
||||
\S::alert( 'Zamówienie zostanie wysłane ponownie do apilo.com' );
|
||||
} else {
|
||||
\S::alert( 'Wystąpił błąd podczas wysyłania zamówienia do apilo.com' );
|
||||
}
|
||||
header( 'Location: /admin/shop_order/order_details/order_id=' . $order_id );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function order_resend_confirmation_email()
|
||||
{
|
||||
$order = new \shop\Order( (int)\S::get( 'order_id' ) );
|
||||
|
||||
@@ -2,6 +2,86 @@
|
||||
namespace admin\factory;
|
||||
class ShopOrder
|
||||
{
|
||||
static public function send_order_to_apilo( int $order_id ) {
|
||||
|
||||
global $mdb;
|
||||
|
||||
// początek - anulowanie zamówienia w apilo
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
|
||||
$new_status = 8; // zamówienie anulowwane
|
||||
|
||||
$order = \admin\factory\ShopOrder::order_details( $order_id );
|
||||
|
||||
if ( $order['apilo_order_id'] ) {
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.apilo.com/rest/api/orders/" . $order['apilo_order_id'] . '/status/' );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
|
||||
'id' => $order['apilo_order_id'],
|
||||
'status' => (int)\front\factory\ShopStatuses::get_apilo_status_id( $new_status )
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json",
|
||||
"Content-Type: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$apilo_result = curl_exec( $ch );
|
||||
|
||||
$apilo_result = json_decode( $apilo_result, true );
|
||||
|
||||
if ( $apilo_result['updates'] == 1 ) {
|
||||
|
||||
// zmień ID zamówienia na największe ID zamówienia + 1, oraz usuń ID zamówienia z apilo
|
||||
$new_order_id = $mdb -> max( 'pp_shop_orders', 'id' ) + 1;
|
||||
|
||||
// pobierz listę kolumn zamówienia
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_orders' AND COLUMN_NAME != 'id'";
|
||||
$columns = $mdb -> query( $query ) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
$columns_list = implode( ', ', $columns );
|
||||
|
||||
// kopiuj stare zamówienie do nowego ID
|
||||
$mdb -> query( 'INSERT INTO pp_shop_orders (' . $columns_list . ') SELECT ' . $columns_list . ' FROM pp_shop_orders pso WHERE pso.id = ' . $order_id );
|
||||
$new_order_id = $mdb -> id();
|
||||
|
||||
// pobierz listę kolumn produktów zamówienia
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_order_products' AND COLUMN_NAME != 'id' AND COLUMN_NAME != 'order_id'";
|
||||
$columns = $mdb -> query( $query ) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
$columns_list = implode( ', ', $columns );
|
||||
|
||||
// kopiuj produkty zamówienia do nowego zamówienia
|
||||
$mdb -> query( 'INSERT INTO pp_shop_order_products (order_id, ' . $columns_list . ') SELECT ' . $new_order_id . ',' . $columns_list . ' FROM pp_shop_order_products psop WHERE psop.order_id = ' . $order_id );
|
||||
|
||||
// pobierz listę kolumn z tabeli pp_shop_order_statuses
|
||||
$query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'pp_shop_order_statuses' AND COLUMN_NAME != 'id' AND COLUMN_NAME != 'order_id'";
|
||||
$columns = $mdb -> query( $query ) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
$columns_list = implode( ', ', $columns );
|
||||
|
||||
// kopiuj statusy zamówienia do nowego zamówienia
|
||||
$mdb -> query( 'INSERT INTO pp_shop_order_statuses (order_id, ' . $columns_list . ') SELECT ' . $new_order_id . ',' . $columns_list . ' FROM pp_shop_order_statuses psos WHERE psos.order_id = ' . $order_id );
|
||||
|
||||
// usuń stare zamówienie
|
||||
$mdb -> delete( 'pp_shop_orders', [ 'id' => $order_id ] );
|
||||
$mdb -> delete( 'pp_shop_order_products', [ 'order_id' => $order_id ] );
|
||||
$mdb -> delete( 'pp_shop_order_statuses', [ 'order_id' => $order_id ] );
|
||||
|
||||
// zmień wartość kolumny apilo_order_id na NULL
|
||||
$mdb -> update( 'pp_shop_orders', [ 'apilo_order_id' => NULL ], [ 'id' => $new_order_id ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
curl_close( $ch );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static public function next_order_id( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
@@ -21,4 +101,14 @@ class ShopOrder
|
||||
|
||||
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[<]' => $order_id, 'ORDER' => [ 'id' => 'DESC' ], 'LIMIT' => 1 ] );
|
||||
}
|
||||
|
||||
static public function order_details( int $order_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$order = $mdb -> get( 'pp_shop_orders', '*', [ 'id' => $order_id ] );
|
||||
$order['products'] = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order_id ] );
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ class Update
|
||||
foreach ( $versions as $ver )
|
||||
{
|
||||
$ver = trim( $ver );
|
||||
if ( (float)$ver > (float)\S::get_version() )
|
||||
if ( floatval( $ver ) > (float)\S::get_version() )
|
||||
{
|
||||
if ( strlen( $ver ) == 5 )
|
||||
$dir = substr( $ver, 0, strlen( $ver ) - 2 ) . 0;
|
||||
@@ -34,29 +34,47 @@ class Update
|
||||
else
|
||||
{
|
||||
/* aktualizacja bazy danych */
|
||||
$sql = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt' );
|
||||
$sql = explode( PHP_EOL, $sql );
|
||||
$url = 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_sql.txt';
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HEADER, true );
|
||||
$response = curl_exec( $ch );
|
||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||
|
||||
if ( $response and strpos( $content_type, 'text/plain' ) !== false )
|
||||
$sql = explode( PHP_EOL, $response );
|
||||
|
||||
if ( is_array( $sql ) and !empty( $sql ) ) foreach ( $sql as $query )
|
||||
{
|
||||
if ( $sql )
|
||||
{
|
||||
$result = $mdb -> query( $query );
|
||||
}
|
||||
}
|
||||
|
||||
/* usuwanie zbędnych plików */
|
||||
$lines = file_get_contents( 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt' );
|
||||
$lines = explode( PHP_EOL, $lines );
|
||||
if ( is_array( $lines ) ) foreach ( $lines as $line )
|
||||
$url = 'http://www.shoppro.project-dc.pl/updates/' . $dir . '/ver_' . $ver . '_files.txt';
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HEADER, true );
|
||||
$response = curl_exec( $ch );
|
||||
$content_type = curl_getinfo( $ch, CURLINFO_CONTENT_TYPE );
|
||||
|
||||
if ( $response and strpos( $content_type, 'text/plain' ) !== false )
|
||||
$files = explode( PHP_EOL, $response );
|
||||
|
||||
if ( is_array( $files ) and !empty( $files ) ) foreach ( $files as $file )
|
||||
{
|
||||
if ( strpos( $line, 'F: ' ) !== false )
|
||||
if ( strpos( $file, 'F: ' ) !== false )
|
||||
{
|
||||
$file = substr( $line, 3, strlen( $line ) );
|
||||
$file = substr( $file, 3, strlen( $file ) );
|
||||
if ( file_exists( $file ) )
|
||||
unlink( $file );
|
||||
}
|
||||
|
||||
if ( strpos( $line, 'D: ' ) !== false )
|
||||
if ( strpos( $file, 'D: ' ) !== false )
|
||||
{
|
||||
$dir = substr( $line, 3, strlen( $line ) );
|
||||
$dir = substr( $file, 3, strlen( $file ) );
|
||||
if ( is_dir( $dir ) )
|
||||
\S::delete_dir( $dir );
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class ShopTransport
|
||||
. 'FROM '
|
||||
. 'pp_shop_transports AS pst '
|
||||
. 'WHERE '
|
||||
. 'status = 1' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
. 'status = 1 ORDER BY o ASC' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$transports_tmp[] = $row;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ class Transport implements \ArrayAccess
|
||||
static public function transport_list()
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_transports', '*', [ 'status' => 1 ] );
|
||||
return $mdb -> select( 'pp_shop_transports', '*', [ 'status' => 1 ], [ 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public function offsetExists( $offset )
|
||||
|
||||
BIN
templates/.DS_Store
vendored
BIN
templates/.DS_Store
vendored
Binary file not shown.
Reference in New Issue
Block a user