Zaktualizowano wersję na 0.225, dodano przycisk do czyszczenia cache oraz funkcję ponownego wysyłania zamówienia do apilo.com

This commit is contained in:
2024-12-20 21:30:42 +01:00
parent 9486ad88ba
commit 451a8a491f
8 changed files with 162 additions and 2 deletions

View File

@@ -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

View File

@@ -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' ] )

View File

@@ -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 );

View File

@@ -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' ) );

View File

@@ -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;
}
}

BIN
updates/0.20/ver_0.225.zip Normal file

Binary file not shown.

View File

@@ -1,3 +1,7 @@
<b>ver. 0.225</b><br />
- NEW - przycisk czyszczenia cache<br>
- NEW - ponowne wysyłanie zamówienia do apilo
<hr>
<b>ver. 0.224</b><br />
- NEW - sortowanie form dostawy
<hr>

View File

@@ -1,5 +1,5 @@
<?
$current_ver = 224;
$current_ver = 225;
for ($i = 1; $i <= $current_ver; $i++)
{