- 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>
173 lines
6.0 KiB
PHP
173 lines
6.0 KiB
PHP
<?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;
|
|
}
|
|
}
|