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

@@ -53,12 +53,13 @@ $mdb = new medoo( [
] );
$settings = \front\factory\Settings::settings_details();
$apilo_settings = \admin\factory\Integrations::apilo_settings();
$integrationsRepository = new \Domain\Integrations\IntegrationsRepository( $mdb );
$apilo_settings = $integrationsRepository -> getSettings( 'apilo' );
// Keepalive tokenu Apilo: odswiezaj token przed wygasnieciem, zeby integracja byla stale aktywna.
if ( (int)($apilo_settings['enabled'] ?? 0) === 1 ) {
\admin\factory\Integrations::apilo_keepalive( 300 );
$apilo_settings = \admin\factory\Integrations::apilo_settings();
$integrationsRepository -> apiloKeepalive( 300 );
$apilo_settings = $integrationsRepository -> getSettings( 'apilo' );
Order::process_apilo_sync_queue( 10 );
}
@@ -122,7 +123,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_products'] and $apilo_
{
if ( $result = $mdb -> query( 'SELECT id, apilo_product_id, apilo_get_data_date, apilo_product_name FROM pp_shop_products WHERE apilo_product_id IS NOT NULL AND apilo_product_id != 0 AND ( apilo_get_data_date IS NULL OR apilo_get_data_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-10 minutes', time() ) ) . '\' ) ORDER BY apilo_get_data_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC ) )
{
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$access_token = $integrationsRepository -> apiloGetAccessToken();
$url = 'https://projectpro.apilo.com/rest/api/warehouse/product/' . $result['apilo_product_id'] . '/';
$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
@@ -151,7 +152,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_products'] and $apilo_
// synchronizacja cen apilo.com
if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and ( !$apilo_settings['pricelist_update_date'] or $apilo_settings['pricelist_update_date'] <= date( 'Y-m-d H:i:s', strtotime( '-1 hour', time() ) ) ) )
{
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$access_token = $integrationsRepository -> apiloGetAccessToken();
$url = 'https://projectpro.apilo.com/rest/api/warehouse/price-calculated/?price=' . $apilo_settings['pricelist_id'];
@@ -188,7 +189,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and ( !$apil
}
}
}
\admin\factory\Integrations::apilo_settings_save( 'pricelist_update_date', date( 'Y-m-d H:i:s' ) );
$integrationsRepository -> saveSetting( 'apilo', 'pricelist_update_date', date( 'Y-m-d H:i:s' ) );
echo '<p>Zaktualizowałem ceny produktów (APILO)</p>';
}
@@ -253,7 +254,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
'media' => null
];
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$access_token = $integrationsRepository -> apiloGetAccessToken();
$order_date = new DateTime( $order['date_order'] );
@@ -502,7 +503,7 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
{
if ( $order['apilo_order_id'] )
{
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$access_token = $integrationsRepository -> apiloGetAccessToken();
$url = 'https://projectpro.apilo.com/rest/api/orders/' . $order['apilo_order_id'] . '/';
$ch = curl_init( $url );