ver. 0.276: ShopOrder migration, Integrations cleanup, global admin search

This commit is contained in:
2026-02-15 16:37:57 +01:00
parent c0030c3cf3
commit 7cc0cadd6d
34 changed files with 2196 additions and 1063 deletions

View File

@@ -1,69 +0,0 @@
<?php
namespace admin\factory;
/**
* Fasada kompatybilnosci wstecznej.
* Deleguje do Domain\Integrations\IntegrationsRepository.
* Uzywane przez: cron.php, shop\Order, admin\Controllers\ShopStatusesController, admin\controls\ShopTransport, admin\controls\ShopProduct, admin\Controllers\ShopPaymentMethodController.
*/
class Integrations {
private static function repo(): \Domain\Integrations\IntegrationsRepository
{
global $mdb;
return new \Domain\Integrations\IntegrationsRepository( $mdb );
}
// ── Apilo settings ──────────────────────────────────────────
static public function apilo_settings( $name = '' )
{
$repo = self::repo();
return $name ? $repo->getSetting( 'apilo', $name ) : $repo->getSettings( 'apilo' );
}
static public function apilo_settings_save( $field_id, $value )
{
return self::repo()->saveSetting( 'apilo', $field_id, $value );
}
static public function apilo_get_access_token()
{
return self::repo()->apiloGetAccessToken();
}
static public function apilo_keepalive( int $refresh_lead_seconds = 300 )
{
return self::repo()->apiloKeepalive( $refresh_lead_seconds );
}
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
{
return self::repo()->apiloAuthorize( $client_id, $client_secret, $authorization_code );
}
// ── Apilo product linking ─────────────────────────────────────
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name )
{
return self::repo()->linkProduct( $product_id, $apilo_product_id, $apilo_product_name );
}
static public function apilo_product_select_delete( int $product_id )
{
return self::repo()->unlinkProduct( $product_id );
}
// ── ShopPRO settings ──────────────────────────────────────────
static public function shoppro_settings( $name = '' )
{
$repo = self::repo();
return $name ? $repo->getSetting( 'shoppro', $name ) : $repo->getSettings( 'shoppro' );
}
static public function shoppro_settings_save( $field_id, $value )
{
return self::repo()->saveSetting( 'shoppro', $field_id, $value );
}
}

View File

@@ -1,114 +0,0 @@
<?php
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;
if ( !$order_id )
return false;
return $mdb -> get( 'pp_shop_orders', 'id', [ 'id[>]' => $order_id, 'ORDER' => [ 'id' => 'ASC' ], 'LIMIT' => 1 ] );
}
static public function prev_order_id( int $order_id )
{
global $mdb;
if ( !$order_id )
return false;
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;
}
}