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:
2026-02-13 21:59:26 +01:00
parent b4559a5e74
commit 1303b17de4
51 changed files with 1166 additions and 2663 deletions

View File

@@ -0,0 +1,172 @@
<?php
namespace admin\Controllers;
use Domain\Integrations\IntegrationsRepository;
class IntegrationsController
{
private IntegrationsRepository $repository;
public function __construct( IntegrationsRepository $repository )
{
$this->repository = $repository;
}
// ── Apilo settings ──────────────────────────────────────────
public function apilo_settings(): string
{
return \Tpl::view( 'integrations/apilo-settings', [
'settings' => $this->repository->getSettings( 'apilo' ),
] );
}
public function apilo_settings_save(): void
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$fieldId = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( $this->repository->saveSetting( 'apilo', $fieldId, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
public function apilo_authorization(): void
{
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
$settings = $this->repository->getSettings( 'apilo' );
if ( $this->repository->apiloAuthorize( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
echo json_encode( $response );
exit;
}
// ── Apilo data fetch ────────────────────────────────────────
public function get_platform_list(): void
{
if ( $this->repository->apiloFetchList( 'platform' ) )
\S::alert( 'Lista platform została pobrana.' );
else
\S::alert( 'Brak wyników.' );
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
public function get_status_types_list(): void
{
if ( $this->repository->apiloFetchList( 'status' ) )
\S::alert( 'Lista statusów została pobrana.' );
else
\S::alert( 'Brak wyników.' );
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
public function get_carrier_account_list(): void
{
if ( $this->repository->apiloFetchList( 'carrier' ) )
\S::alert( 'Lista kont przewoźników została pobrana.' );
else
\S::alert( 'Brak wyników.' );
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
public function get_payment_types_list(): void
{
if ( $this->repository->apiloFetchList( 'payment' ) )
\S::alert( 'Lista metod płatności została pobrana.' );
else
\S::alert( 'Brak wyników.' );
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// ── Apilo product operations ────────────────────────────────
public function apilo_create_product(): void
{
$productId = (int) \S::get( 'product_id' );
$result = $this->repository->apiloCreateProduct( $productId );
\S::alert( $result['message'] );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
public function apilo_product_search(): void
{
$productId = (int) \S::get( 'product_id' );
$sku = $this->repository->getProductSku( $productId );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
echo json_encode( $this->repository->apiloProductSearch( $sku ) );
exit;
}
public function apilo_product_select_save(): void
{
if ( $this->repository->linkProduct( (int) \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
public function apilo_product_select_delete(): void
{
if ( $this->repository->unlinkProduct( (int) \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// ── ShopPRO settings ────────────────────────────────────────
public function shoppro_settings(): string
{
return \Tpl::view( 'integrations/shoppro-settings', [
'settings' => $this->repository->getSettings( 'shoppro' ),
] );
}
public function shoppro_settings_save(): void
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$fieldId = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( $this->repository->saveSetting( 'shoppro', $fieldId, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// ── ShopPRO product import ──────────────────────────────────
public function shoppro_product_import(): void
{
$productId = (int) \S::get( 'product_id' );
$result = $this->repository->shopproImportProduct( $productId );
\S::alert( $result['message'] );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
}

View File

@@ -311,6 +311,13 @@ class Site
new \Domain\Layouts\LayoutsRepository( $mdb )
);
},
'Integrations' => function() {
global $mdb;
return new \admin\Controllers\IntegrationsController(
new \Domain\Integrations\IntegrationsRepository( $mdb )
);
},
];
return self::$newControllers;

View File

@@ -1,20 +0,0 @@
<?php
namespace admin\controls;
class Baselinker {
// widok wiązania produktów
static public function bundling_products() {
return \Tpl::view( 'baselinker/bundling-products', [
'products' => \admin\factory\ShopProduct::products_list_for_baselinker(),
'baselinker_products' => \admin\factory\Baselinker::products_list()
] );
}
// zapis wiązania produktów
static public function bundling_products_save() {
\admin\factory\Baselinker::bundling_products_save( $_POST );
header( 'Location: /admin/baselinker/bundling_products/' );
exit;
}
}

View File

@@ -1,846 +0,0 @@
<?
namespace admin\controls;
class Integrations {
// apilo_create_product
static public function apilo_create_product()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$product_id = \S::get( 'product_id' );
$product = new \shop\Product( $product_id );
$methodParams = [
"sku" => $product -> sku,
"ean" => $product -> ean,
"name" => $product -> language['name'],
"tax" => (int) $product -> vat,
'status' => 1,
"quantity" => (int) $product -> quantity,
"priceWithTax" => $product -> price_brutto,
'description' => $product -> language['description'] . '<br>' . $product -> language['short_description'],
'shortDescription' => '',
'images' => []
];
foreach ($product->images as $image) {
$methodParams["images"][] = "https://" . $_SERVER['HTTP_HOST'] . $image['src'];
}
$ch = curl_init( "https://projectpro.apilo.com/rest/api/warehouse/product/" );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [ $methodParams ] ) );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Content-Type: application/json",
"Accept: application/json"
] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData['products'] )
{
$mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => reset( $responseData['products'] ), 'apilo_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
}
\S::alert( 'Produkt został dodany do magazynu APILO.' );
}
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
// baselinker_create_product
static public function baselinker_create_product()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$product_id = \S::get( 'product_id' );
$product = \shop\Product::getFromCache( $product_id, 'pl' );
$methodParams = [
"storage_id" => \admin\factory\Integrations::baselinker_settings('storage_id'),
"ean" => $product->ean,
"sku" => $product->sku,
"name" => $product->language['name'],
"quantity" => "0",
"price_brutto" => $product->price_brutto,
"tax_rate" => $product->vat,
"description" => $product->language['short_description'],
"description_extra1" => $product->language['description'],
"images" => []
];
foreach ($product->images as $image) {
$methodParams["images"][] = "url:https://" . $_SERVER['HTTP_HOST'] . $image['src'];
}
$methodParams = json_encode( $methodParams, JSON_UNESCAPED_SLASHES );
$apiParams = [
"token" => $api_code,
"method" => "addProduct",
"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' )
{
if ( $response['product_id'] )
{
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $response['product_id'], 'baselinker_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
}
\S::alert( 'Produkt został dodany do magazynu Baselinker.' );
}
else
{
\S::alert( 'Podczas dodawania produktu wystąpił błąd.' );
}
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
// baselinker pobierz listę magazynów
static public function baselinker_get_storages_list()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$methodParams = '{
"storage_id": "bl_1"
}';
$apiParams = [
"token" => $api_code,
"method" => "getStoragesList",
"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' )
{
\admin\factory\Integrations::baselinker_settings_save( 'storages_list', $response['storages'] );
\S::alert( 'Lista magazynów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/baselinker_settings/' );
exit;
}
// baselinker_get_order_status_list
static public function baselinker_get_order_status_list()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$apiParams = [
"token" => $api_code,
"method" => "getOrderStatusList",
"parameters" => []
];
$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' )
{
\admin\factory\Integrations::baselinker_settings_save( 'order_status_list', $response['statuses'] );
\S::alert( 'Lista statusów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/baselinker_settings/' );
exit;
}
// get_sellasist_carriers_list
static public function get_sellasist_shipments_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/shipments" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'shipments_methods', $responseData );
\S::alert( 'Lista przewoźników została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
// get_sellasist_payment_types_list
static public function get_sellasist_payment_types_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/payments" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'payment_types_list', $responseData );
\S::alert( 'Lista metod płatności została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
static public function get_sellasist_status_types_list()
{
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/statuses" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
else {
if ( $responseData ) {
\admin\factory\Integrations::sellasist_settings_save( 'status_types_list', $responseData );
\S::alert( 'Lista statusów została pobrana.' );
} else
\S::alert( 'Brak wyników.' );
}
header( 'Location: /admin/integrations/sellasist_settings/' );
exit;
}
// get_platform_list
static public function get_platform_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/platform/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'platform-list', $responseData );
\S::alert( 'Lista platform została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_status_types_list
static public function get_status_types_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/status/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'status-types-list', $responseData );
\S::alert( 'Lista statusów została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_carrier_account_list
static public function get_carrier_account_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/carrier-account/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'carrier-account-list', $responseData );
\S::alert( 'Lista kont przewoźników została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// get_payment_types_list
static public function get_payment_types_list()
{
global $mdb, $settings;
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/orders/payment/map/";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
}
else
{
if ( $responseData )
{
\admin\factory\Integrations::apilo_settings_save( 'payment-types-list', $responseData );
\S::alert( 'Lista metod płatności została pobrana.' );
}
else
{
\S::alert( 'Brak wyników.' );
}
}
header( 'Location: /admin/integrations/apilo_settings/' );
exit;
}
// settings for the sellasist integration
static public function sellasist_settings()
{
return \Tpl::view( 'integrations/sellasist-settings', [
'settings' => \admin\factory\Integrations::sellasist_settings(),
] );
}
// settings for the Baselinker integration
static public function baselinker_settings()
{
return \Tpl::view( 'integrations/baselinker-settings', [
'settings' => \admin\factory\Integrations::baselinker_settings(),
] );
}
// settings for shoppro
static public function shoppro_settings()
{
return \Tpl::view( 'integrations/shoppro-settings', [
'settings' => \admin\factory\Integrations::shoppro_settings(),
] );
}
// Settings for the APILO plugin
static public function apilo_settings()
{
return \Tpl::view( 'integrations/apilo-settings', [
'settings' => \admin\factory\Integrations::apilo_settings(),
] );
}
// save settings for the shoppro integration
static public function shoppro_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::shoppro_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// save settings for the sellasist integration
static public function sellasist_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::sellasist_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// save settings for the Baselinker integration
static public function baselinker_settings_save()
{
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::baselinker_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// Save settings for the APILO plugin
static public function apilo_settings_save() {
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
$field_id = \S::get( 'field_id' );
$value = \S::get( 'value' );
if ( \admin\factory\Integrations::apilo_settings_save( $field_id, $value ) )
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
echo json_encode( $response );
exit;
}
// Authorization in apilo.com
static public function apilo_authorization() {
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
$settings = \admin\factory\Integrations::apilo_settings();
if ( \admin\factory\Integrations::apilo_authorization( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
echo json_encode( $response );
exit;
}
// sellasist product search by sku
static public function sellasist_product_search() {
global $mdb, $settings;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$url = "https://projectpro.sellasist.pl/api/v1/products";
$params['symbol '] = $sku;
$url .= '?' . http_build_query( $params );
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"apiKey: " . $api_code,
"accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) )
{
echo 'Błąd cURL: ' . curl_error( $ch );
}
else
{
if ( $responseData['error'] )
{
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
exit;
}
else
{
$return_data = array();
$return_data['status'] = 'SUCCESS';
$return_data['products'] = $responseData;
echo json_encode( $return_data );
exit;
}
}
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
exit;
}
// apilo product search by sku
static public function apilo_product_search() {
global $mdb, $settings;
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$access_token = \admin\factory\Integrations::apilo_get_access_token();
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/";
$params['sku'] = $sku;
$url .= '?' . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $access_token,
"Accept: application/json"
] );
$response = curl_exec( $ch );
$responseData = json_decode( $response, true );
if ( curl_errno( $ch ) ) {
echo 'Błąd cURL: ' . curl_error( $ch );
} else {
if ( $responseData && isset( $responseData['products'] ) ) {
$responseData['status'] = 'SUCCESS';
echo json_encode( $responseData );
exit;
} else {
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
exit;
}
}
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
exit;
}
// wyszukiwanie produktu w bazie baselinkera
static public function baselinker_product_search()
{
global $mdb, $settings;
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
if ( !$sku ) {
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
exit;
}
$methodParams = '{
"storage_id": "bl_1",
"filter_sku": "' . $sku . '"
}';
$apiParams = [
"token" => $api_code,
"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 );
echo json_encode( $response );
exit;
}
// sellasist_product_select_delete
static public function sellasist_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::sellasist_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// apilo product select delete
static public function apilo_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::apilo_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// baselinker delete product linking
static public function baselinker_product_select_delete()
{
global $mdb;
if ( \admin\factory\Integrations::baselinker_product_select_delete( \S::get( 'product_id' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// sellasist_product_select_save
static public function sellasist_product_select_save()
{
global $mdb;
if ( \admin\factory\Integrations::sellasist_product_select_save( \S::get( 'product_id' ), \S::get( 'sellasist_product_id' ), \S::get( 'sellasist_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// apilo product select save
static public function apilo_product_select_save()
{
global $mdb;
if ( \admin\factory\Integrations::apilo_product_select_save( \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
static public function baselinker_product_select_save() {
global $mdb;
if ( \admin\factory\Integrations::baselinker_product_select_save( \S::get( 'product_id' ), \S::get( 'baselinker_product_id' ), \S::get( 'baselinker_product_name' ) ) )
echo json_encode( [ 'status' => 'ok' ] );
else
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
exit;
}
// shoppro_product_import
static public function shoppro_product_import()
{
global $mdb;
$shoppro_settings = \admin\factory\Integrations::shoppro_settings();
$mdb2 = new \medoo( [
'database_type' => 'mysql',
'database_name' => $shoppro_settings[ 'db_name' ],
'server' => $shoppro_settings[ 'db_host' ],
'username' => $shoppro_settings[ 'db_user' ],
'password' => $shoppro_settings[ 'db_password' ],
'charset' => 'utf8'
] );
$product_id = \S::get( 'product_id' );
$product = $mdb2 -> get( 'pp_shop_products', '*', [ 'id' => $product_id ] );
if ( $product )
{
$mdb -> insert( 'pp_shop_products', [
'price_netto' => $product[ 'price_netto' ],
'price_brutto' => $product[ 'price_brutto' ],
'vat' => $product[ 'vat' ],
'stock_0_buy' => $product[ 'stock_0_buy' ],
'quantity' => $product[ 'quantity' ],
'wp' => $product[ 'wp' ],
'sku' => $product[ 'sku' ],
'ean' => $product[ 'ean' ],
'custom_label_0' => $product[ 'custom_label_0' ],
'custom_label_1' => $product[ 'custom_label_1' ],
'custom_label_2' => $product[ 'custom_label_2' ],
'custom_label_3' => $product[ 'custom_label_3' ],
'custom_label_4' => $product[ 'custom_label_4' ],
'additional_message' => $product[ 'additional_message' ],
'additional_message_text' => $product[ 'additional_message_text' ],
'additional_message_required' => $product[ 'additional_message_required' ],
'weight' => $product[ 'weight' ]
] );
$new_product_id = $mdb -> id();
if ( $new_product_id )
{
$languages = $mdb2 -> select( 'pp_shop_products_langs', '*', [ 'product_id' => $product_id ] );
if ( is_array( $languages ) )
{
foreach ( $languages as $language )
{
$mdb -> insert( 'pp_shop_products_langs', [
'product_id' => $new_product_id,
'lang_id' => $language['lang_id'],
'name' => $language['name'],
'short_description' => $language['short_description'],
'description' => $language['description'],
'tab_name_1' => $language['tab_name_1'],
'tab_description_1' => $language['tab_description_1'],
'tab_name_2' => $language['tab_name_2'],
'tab_description_2' => $language['tab_description_2'],
'meta_title' => $language['meta_title'],
'meta_description' => $language['meta_description'],
'meta_keywords' => $language['meta_keywords'],
'seo_link' => $language['seo_link'],
'copy_from' => $language['copy_from'],
'warehouse_message_zero' => $language['warehouse_message_zero'],
'warehouse_message_nonzero' => $language['warehouse_message_nonzero'],
'canonical' => $language['canonical'],
'xml_name' => $language['xml_name']
] );
}
}
$images = $mdb2 -> select( 'pp_shop_products_images', '*', [ 'product_id' => $product_id ] );
if ( is_array( $images ) )
{
foreach ( $images as $image )
{
$image_url = 'https://' . $shoppro_settings['domain'] . $image['src'];
// pobierz zdjęcie za pomocą curl
$ch = curl_init( $image_url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
$image_data = curl_exec( $ch );
$image_data;
curl_close( $ch );
// ścieżdka do nowego zdjęcia to "/upload/product_images/product_[product_id]/[nazwa_zdjęcia]
$image_name = basename( $image_url );
$image_path = '../upload/product_images/product_' . $new_product_id . '/' . $image_name;
// utwórz katalog dla zdjęć produktu jeśli nie istnieje
if ( !file_exists( '../upload/product_images/product_' . $new_product_id ) )
mkdir( '../upload/product_images/product_' . $new_product_id, 0777, true );
// zapisz zdjęcie
file_put_contents( $image_path, $image_data );
// zapisz zdjęcie w bazie danych
$mdb -> insert( 'pp_shop_products_images', [
'product_id' => $new_product_id,
'src' => '/upload/product_images/product_' . $new_product_id . '/' . $image_name,
'o' => $image['o']
] );
}
}
\S::alert( 'Produkt został zaimportowany.' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
}
\S::alert( 'Podczas importowania produktu wystąpił błąd.' );
header( 'Location: /admin/shop_product/view_list/' );
exit;
}
}

View File

@@ -6,7 +6,6 @@ class ShopPaymentMethod
{
return \Tpl::view( 'shop-payment-method/view-list', [
'apilo_payment_types_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'payment-types-list' ) ),
'sellasist_payment_types_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'payment_types_list' ) ),
] );
}
}

View File

@@ -297,9 +297,7 @@ class ShopProduct
'html' => \Tpl::view( 'shop-product/products-list-table', [
'products' => $products['products'],
'current_page' => \S::get( 'current_page' ),
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
'show_xml_data' => \S::get_session( 'show_xml_data' )
] )
];
@@ -334,9 +332,7 @@ class ShopProduct
'current_page' => $current_page,
'query_array' => $query_array,
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 ),
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
'show_xml_data' => \S::get_session( 'show_xml_data' ),
'shoppro_enabled' => \admin\factory\Integrations::shoppro_settings( 'enabled' )
] );

View File

@@ -9,7 +9,7 @@ class ShopStatuses {
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'], $values['sellasist_status_id'], $values['baselinker_status_id'] ) )
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'] ) )
$response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];
echo json_encode( $response );
@@ -22,8 +22,6 @@ class ShopStatuses {
return \Tpl::view( 'shop-statuses/status-edit', [
'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
] );
}
@@ -31,8 +29,6 @@ class ShopStatuses {
{
return \Tpl::view( 'shop-statuses/view-list', [
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
] );
}
}

View File

@@ -8,7 +8,7 @@ class ShopTransport
$values = json_decode( \S::get( 'values' ), true );
if ( $id = \admin\factory\ShopTransport::transport_save(
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['sellasist_shipment_method_id'], $values['delivery_free']
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['delivery_free']
) )
$response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];
@@ -22,7 +22,6 @@ class ShopTransport
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
'payments_list' => \admin\factory\ShopPaymentMethod::payments_list(),
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
] );
}
@@ -30,7 +29,6 @@ class ShopTransport
{
return \Tpl::view( 'shop-transport/view-list', [
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
] );
}
}

View File

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

View File

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

View File

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

View File

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

View File

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