Integrations DI refactor, remove Sellasist/Baselinker, fix product-edit encoding (0.263)
- New: Domain\Integrations\IntegrationsRepository + admin\Controllers\IntegrationsController (DI) - Cleanup: removed all Sellasist and Baselinker integrations from entire project - Fix: product-edit.php Polish characters (UTF-8/CP1250 double-encoding) - Update: factory\Integrations as facade (Apilo + ShopPRO only) - Tests: 212 tests, 577 assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,264 +1,64 @@
|
||||
<?
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
/**
|
||||
* Fasada kompatybilnosci wstecznej.
|
||||
* Deleguje do Domain\Integrations\IntegrationsRepository.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\controls\ShopStatuses, admin\controls\ShopTransport, admin\controls\ShopPaymentMethod, admin\controls\ShopProduct.
|
||||
*/
|
||||
class Integrations {
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => null, 'sellasist_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save( int $product_id, $sellasist_product_id, $sellasist_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => $sellasist_product_id, 'sellasist_product_name' => \S::remove_special_chars( $sellasist_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo delete product linking
|
||||
static public function apilo_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => null, 'apilo_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => null, 'baselinker_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => $apilo_product_id, 'apilo_product_name' => \S::remove_special_chars( $apilo_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save( int $product_id, $baselinker_product_id, $baselinker_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $baselinker_product_id, 'baselinker_product_name' => $baselinker_product_name ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// get settings for shoppro integration
|
||||
static public function shoppro_settings( $name = '' )
|
||||
private static function repo(): \Domain\Integrations\IntegrationsRepository
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_shoppro_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_shoppro_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
return new \Domain\Integrations\IntegrationsRepository( $mdb );
|
||||
}
|
||||
|
||||
// get settings for the sellasist integration
|
||||
static public function sellasist_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
// ── Apilo settings ──────────────────────────────────────────
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_sellasist_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_sellasist_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the Baselinker integration
|
||||
static public function baselinker_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_baselinker_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_baselinker_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the APILO plugin
|
||||
static public function apilo_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_apilo_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_apilo_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
$repo = self::repo();
|
||||
return $name ? $repo->getSetting( 'apilo', $name ) : $repo->getSettings( 'apilo' );
|
||||
}
|
||||
|
||||
// save settings for shoppro integration
|
||||
static public function shoppro_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_shoppro_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_shoppro_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_shoppro_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_sellasist_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_sellasist_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_sellasist_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_baselinker_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_baselinker_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_baselinker_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the APILO plugin
|
||||
static public function apilo_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_apilo_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_apilo_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_apilo_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
return self::repo()->saveSetting( 'apilo', $field_id, $value );
|
||||
}
|
||||
|
||||
// authorization in apilo.com
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/auth/token/";
|
||||
|
||||
$postData['grantType'] = 'authorization_code';
|
||||
$postData['token'] = $authorization_code;
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $client_id . ":" . $client_secret ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// get access token or refresh it apilo.com
|
||||
static public function apilo_get_access_token()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$apilo_settings = self::apilo_settings();
|
||||
|
||||
$date1 = new \DateTime( $apilo_settings['access-token-expire-at'] );
|
||||
$date2 = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
if ( $date1 < $date2 )
|
||||
{
|
||||
$post_data = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $apilo_settings['refresh-token']
|
||||
];
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $apilo_settings['client-id'] . ":" . $apilo_settings['client-secret'] ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post_data ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
if ( $access_token == '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
return $apilo_settings['access-token'];
|
||||
return self::repo()->apiloGetAccessToken();
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user