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,39 +0,0 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save( $values ) {
|
||||
global $mdb;
|
||||
|
||||
foreach ( $values as $key => $val ) {
|
||||
$key = explode( '_', $key );
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $val ], [ 'id' => $key[1] ] );
|
||||
}
|
||||
}
|
||||
|
||||
// pobranie produktów z Baselinkera
|
||||
static public function products_list() {
|
||||
global $settings;
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $settings['baselinker_api'],
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
return $response['products'];
|
||||
}
|
||||
}
|
||||
@@ -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 );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,19 +65,6 @@ class ShopProduct
|
||||
return $mdb -> get( 'pp_shop_products_langs', 'name', [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => $default_lang ] ] );
|
||||
}
|
||||
|
||||
// lista produktów do wiązania z baselinkerem
|
||||
static public function products_list_for_baselinker()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_products', [ 'id', 'sku', 'baselinker_product_id' ], [ 'parent_id' => null, 'ORDER' => [ 'baselinker_product_id' => 'ASC', 'sku' => 'ASC' ] ] );
|
||||
foreach ( $results as $row ) {
|
||||
$row['name'] = self::product_default_name( $row['id'] );
|
||||
$products[] = $row;
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
// szybka zmiana google xml label
|
||||
static public function product_change_custom_label( int $product_id, $custom_label, $value )
|
||||
{
|
||||
|
||||
@@ -10,15 +10,13 @@ class ShopStatuses {
|
||||
}
|
||||
|
||||
// status_save
|
||||
public static function status_save( $status_id, $color, $apilo_status_id, $sellasi_status_id, $baselinker_status_id )
|
||||
public static function status_save( $status_id, $color, $apilo_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_statuses', [
|
||||
'color' => $color,
|
||||
'apilo_status_id' => $apilo_status_id ? $apilo_status_id : null,
|
||||
'sellasist_status_id' => $sellasi_status_id ? $sellasi_status_id : null,
|
||||
'baselinker_status_id' => $baselinker_status_id ? $baselinker_status_id : null
|
||||
], [ 'id' => $status_id ] );
|
||||
|
||||
return $status_id;
|
||||
|
||||
@@ -7,7 +7,7 @@ class ShopTransport
|
||||
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8, 9 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $sellasist_shipment_method_id, $delivery_free )
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $delivery_free )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -25,7 +25,6 @@ class ShopTransport
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
@@ -67,7 +66,6 @@ class ShopTransport
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $transport_id
|
||||
|
||||
Reference in New Issue
Block a user