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,408 @@
<?php
namespace Domain\Integrations;
class IntegrationsRepository
{
private $db;
private const SETTINGS_TABLES = [
'apilo' => 'pp_shop_apilo_settings',
'shoppro' => 'pp_shop_shoppro_settings',
];
public function __construct( $db )
{
$this->db = $db;
}
// ── Settings ────────────────────────────────────────────────
private function settingsTable( string $provider ): string
{
if ( !isset( self::SETTINGS_TABLES[$provider] ) )
throw new \InvalidArgumentException( "Unknown provider: $provider" );
return self::SETTINGS_TABLES[$provider];
}
public function getSettings( string $provider ): array
{
$table = $this->settingsTable( $provider );
$results = $this->db->query( "SELECT * FROM $table" )->fetchAll( \PDO::FETCH_ASSOC );
$settings = [];
foreach ( $results as $row )
$settings[$row['name']] = $row['value'];
return $settings;
}
public function getSetting( string $provider, string $name ): ?string
{
$table = $this->settingsTable( $provider );
$value = $this->db->get( $table, 'value', [ 'name' => $name ] );
return $value !== false ? $value : null;
}
public function saveSetting( string $provider, string $name, $value ): bool
{
$table = $this->settingsTable( $provider );
if ( $this->db->count( $table, [ 'name' => $name ] ) ) {
$this->db->update( $table, [ 'value' => $value ], [ 'name' => $name ] );
} else {
$this->db->insert( $table, [ 'name' => $name, 'value' => $value ] );
}
return true;
}
// ── Product linking (Apilo) ─────────────────────────────────
public function linkProduct( int $productId, $externalId, $externalName ): bool
{
return (bool) $this->db->update( 'pp_shop_products', [
'apilo_product_id' => $externalId,
'apilo_product_name' => \S::remove_special_chars( $externalName ),
], [ 'id' => $productId ] );
}
public function unlinkProduct( int $productId ): bool
{
return (bool) $this->db->update( 'pp_shop_products', [
'apilo_product_id' => null,
'apilo_product_name' => null,
], [ 'id' => $productId ] );
}
// ── Apilo OAuth ─────────────────────────────────────────────
public function apiloAuthorize( string $clientId, string $clientSecret, string $authCode ): bool
{
$postData = [
'grantType' => 'authorization_code',
'token' => $authCode,
];
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
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( $clientId . ":" . $clientSecret ),
"Accept: application/json"
] );
$response = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
curl_close( $ch );
return false;
}
curl_close( $ch );
$response = json_decode( $response, true );
if ( empty( $response['accessToken'] ) )
return false;
$this->saveSetting( 'apilo', 'access-token', $response['accessToken'] );
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] );
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] );
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] );
return true;
}
public function apiloGetAccessToken(): ?string
{
$settings = $this->getSettings( 'apilo' );
if ( empty( $settings['access-token-expire-at'] ) || empty( $settings['access-token'] ) )
return null;
$expireAt = new \DateTime( $settings['access-token-expire-at'] );
$now = new \DateTime( date( 'Y-m-d H:i:s' ) );
if ( $expireAt >= $now )
return $settings['access-token'];
// Token expired - refresh
$postData = [
'grantType' => 'refresh_token',
'token' => $settings['refresh-token'],
];
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Basic " . base64_encode( $settings['client-id'] . ":" . $settings['client-secret'] ),
"Accept: application/json"
] );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$response = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
curl_close( $ch );
return null;
}
curl_close( $ch );
$response = json_decode( $response, true );
if ( empty( $response['accessToken'] ) )
return null;
$this->saveSetting( 'apilo', 'access-token', $response['accessToken'] );
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] );
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] );
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] );
return $response['accessToken'];
}
// ── Apilo API fetch lists ───────────────────────────────────
private const APILO_ENDPOINTS = [
'platform' => 'https://projectpro.apilo.com/rest/api/orders/platform/map/',
'status' => 'https://projectpro.apilo.com/rest/api/orders/status/map/',
'carrier' => 'https://projectpro.apilo.com/rest/api/orders/carrier-account/map/',
'payment' => 'https://projectpro.apilo.com/rest/api/orders/payment/map/',
];
private const APILO_SETTINGS_KEYS = [
'platform' => 'platform-list',
'status' => 'status-types-list',
'carrier' => 'carrier-account-list',
'payment' => 'payment-types-list',
];
/**
* Fetch list from Apilo API and save to settings.
* @param string $type platform|status|carrier|payment
*/
public function apiloFetchList( string $type ): bool
{
if ( !isset( self::APILO_ENDPOINTS[$type] ) )
throw new \InvalidArgumentException( "Unknown apilo list type: $type" );
$accessToken = $this->apiloGetAccessToken();
if ( !$accessToken )
return false;
$ch = curl_init( self::APILO_ENDPOINTS[$type] );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $accessToken,
"Accept: application/json"
] );
$response = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
curl_close( $ch );
return false;
}
curl_close( $ch );
$data = json_decode( $response, true );
if ( !$data )
return false;
$this->saveSetting( 'apilo', self::APILO_SETTINGS_KEYS[$type], $data );
return true;
}
// ── Apilo product operations ────────────────────────────────
public function getProductSku( int $productId ): ?string
{
$sku = $this->db->get( 'pp_shop_products', 'sku', [ 'id' => $productId ] );
return $sku ?: null;
}
public function apiloProductSearch( string $sku ): array
{
$accessToken = $this->apiloGetAccessToken();
if ( !$accessToken )
return [ 'status' => 'error', 'msg' => 'Brak tokenu Apilo.' ];
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/?" . http_build_query( [ 'sku' => $sku ] );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $accessToken,
"Accept: application/json"
] );
$response = curl_exec( $ch );
if ( curl_errno( $ch ) ) {
curl_close( $ch );
return [ 'status' => 'error', 'msg' => 'Błąd cURL: ' . curl_error( $ch ) ];
}
curl_close( $ch );
$data = json_decode( $response, true );
if ( $data && isset( $data['products'] ) ) {
$data['status'] = 'SUCCESS';
return $data;
}
return [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ];
}
public function apiloCreateProduct( int $productId ): array
{
$accessToken = $this->apiloGetAccessToken();
if ( !$accessToken )
return [ 'success' => false, 'message' => 'Brak tokenu Apilo.' ];
$product = new \shop\Product( $productId );
$params = [
'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 )
$params['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( [ $params ] ) );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer " . $accessToken,
"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 ) ) {
$error = curl_error( $ch );
curl_close( $ch );
return [ 'success' => false, 'message' => 'Błąd cURL: ' . $error ];
}
curl_close( $ch );
if ( !empty( $responseData['products'] ) ) {
$this->db->update( 'pp_shop_products', [
'apilo_product_id' => reset( $responseData['products'] ),
'apilo_product_name' => $product->language['name'],
], [ 'id' => $product->id ] );
return [ 'success' => true, 'message' => 'Produkt został dodany do magazynu APILO.' ];
}
return [ 'success' => false, 'message' => 'Podczas dodawania produktu wystąpił błąd.' ];
}
// ── ShopPRO import ──────────────────────────────────────────
public function shopproImportProduct( int $productId ): array
{
$settings = $this->getSettings( 'shoppro' );
$mdb2 = new \medoo( [
'database_type' => 'mysql',
'database_name' => $settings['db_name'],
'server' => $settings['db_host'],
'username' => $settings['db_user'],
'password' => $settings['db_password'],
'charset' => 'utf8'
] );
$product = $mdb2->get( 'pp_shop_products', '*', [ 'id' => $productId ] );
if ( !$product )
return [ 'success' => false, 'message' => 'Podczas importowania produktu wystąpił błąd.' ];
$this->db->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'],
] );
$newProductId = $this->db->id();
if ( !$newProductId )
return [ 'success' => false, 'message' => 'Podczas importowania produktu wystąpił błąd.' ];
// Import translations
$languages = $mdb2->select( 'pp_shop_products_langs', '*', [ 'product_id' => $productId ] );
if ( is_array( $languages ) ) {
foreach ( $languages as $lang ) {
$this->db->insert( 'pp_shop_products_langs', [
'product_id' => $newProductId,
'lang_id' => $lang['lang_id'],
'name' => $lang['name'],
'short_description' => $lang['short_description'],
'description' => $lang['description'],
'tab_name_1' => $lang['tab_name_1'],
'tab_description_1' => $lang['tab_description_1'],
'tab_name_2' => $lang['tab_name_2'],
'tab_description_2' => $lang['tab_description_2'],
'meta_title' => $lang['meta_title'],
'meta_description' => $lang['meta_description'],
'meta_keywords' => $lang['meta_keywords'],
'seo_link' => $lang['seo_link'],
'copy_from' => $lang['copy_from'],
'warehouse_message_zero' => $lang['warehouse_message_zero'],
'warehouse_message_nonzero'=> $lang['warehouse_message_nonzero'],
'canonical' => $lang['canonical'],
'xml_name' => $lang['xml_name'],
] );
}
}
// Import images
$images = $mdb2->select( 'pp_shop_products_images', '*', [ 'product_id' => $productId ] );
if ( is_array( $images ) ) {
foreach ( $images as $image ) {
$imageUrl = 'https://' . $settings['domain'] . $image['src'];
$ch = curl_init( $imageUrl );
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 );
$imageData = curl_exec( $ch );
curl_close( $ch );
$imageName = basename( $imageUrl );
$imageDir = '../upload/product_images/product_' . $newProductId;
$imagePath = $imageDir . '/' . $imageName;
if ( !file_exists( $imageDir ) )
mkdir( $imageDir, 0777, true );
file_put_contents( $imagePath, $imageData );
$this->db->insert( 'pp_shop_products_images', [
'product_id' => $newProductId,
'src' => '/upload/product_images/product_' . $newProductId . '/' . $imageName,
'o' => $image['o'],
] );
}
}
return [ 'success' => true, 'message' => 'Produkt został zaimportowany.' ];
}
}

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

View File

@@ -1,21 +0,0 @@
<?
namespace front\factory;
class Shop
{
static public function baselinker_settings( $admin = false )
{
global $mdb;
if ( !$settings = \Cache::fetch( 'baselinker_settings' ) or $admin )
{
$results = $mdb -> select( 'pp_shop_baselinker_settings', '*' );
if ( is_array( $results ) ) foreach ( $results as $row )
$settings[ $row['name'] ] = $row['value'];
if ( !$admin)
\Cache::store( 'baselinker_settings', $settings );
}
return $settings;
}
}

View File

@@ -136,9 +136,7 @@ class ShopOrder
'summary' => \S::normalize_decimal( $basket_summary + $transport_cost ),
'coupon_id' => $coupon ? $coupon -> id : null,
'message' => $basket_message ? $basket_message : null,
'baselinker_order_status_date' => date( 'Y-m-d H:i:s' ),
'apilo_order_status_date' => date( 'Y-m-d H:i:s' ),
'sellasist_order_status_date' => date( 'Y-m-d H:i:s' ),
] );
$order_id = $mdb -> id();

View File

@@ -3,12 +3,6 @@ namespace front\factory;
class ShopPaymentMethod
{
// get_sellasist_payment_method_id
static public function get_sellasist_payment_method_id( $payment_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_payment_methods', 'sellasist_payment_type_id', [ 'id' => $payment_method_id ] );
}
// get_apilo_payment_method_id
static public function get_apilo_payment_method_id( $payment_method_id ) {
global $mdb;

View File

@@ -3,17 +3,6 @@ namespace front\factory;
class ShopProduct
{
// get_sellasist_product_id
static public function get_sellasist_product_id( $product_id ) {
global $mdb;
if ( !$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' => $product_id ] ) ) {
$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' =>
$mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] )
] );
}
return $sellasist_product_id;
}
// get_product_sku
static public function get_product_sku( $product_id, $parent = false )
{

View File

@@ -3,32 +3,17 @@ namespace front\factory;
class ShopStatuses {
// get_baselinker_order_status_id
static public function get_baselinker_order_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'baselinker_status_id', [ 'id' => $status_id ] );
}
// get_apilo_status_id
static public function get_apilo_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'apilo_status_id', [ 'id' => $status_id ] );
}
// get sellasist status id
static public function get_sellasist_status_id( $status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'sellasist_status_id', [ 'id' => $status_id ] );
}
// get_shop_status_by_integration_status_id
static public function get_shop_status_by_integration_status_id( $integration, $integration_status_id )
{
global $mdb;
if ( $integration == 'sellasist' )
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'sellasist_status_id' => $integration_status_id ] );
if ( $integration == 'apilo' )
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'apilo_status_id' => $integration_status_id ] );
}

View File

@@ -2,12 +2,6 @@
namespace front\factory;
class ShopTransport
{
// get_sellasist_transport_id
static public function get_sellasist_transport_id( $transport_method_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_transports', 'sellasist_shipment_method_id', [ 'id' => $transport_method_id ] );
}
// get_apilo_carrier_account_id
static public function get_apilo_carrier_account_id( $transport_method_id )
{

View File

@@ -8,9 +8,7 @@ class Order implements \ArrayAccess
public $statuses;
public $status;
public $client_email;
public $sellasist_order_id;
public $summary;
public $baselinker_order_id;
public $apilo_order_id;
public $date_order;
public $payment_method_id;
@@ -61,12 +59,6 @@ class Order implements \ArrayAccess
return $statuses;
}
public function update_baselinker_order_status_date( $date )
{
global $mdb;
return $mdb -> update( 'pp_shop_orders', [ 'baselinker_order_status_date' => $date ], [ 'id' => $this -> id ] );
}
public function update_aplio_order_status_date( $date )
{
global $mdb;
@@ -77,28 +69,6 @@ class Order implements \ArrayAccess
public function set_as_unpaid() {
global $mdb;
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] ) {
if ( $this -> sellasist_order_id ) {
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
'paid' => 0,
'payment_status' => 'unpaid'
] ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"accept: application/json",
"apiKey: " . $sellasist_settings['api_code'],
"Content-Type: application/json"
) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_exec( $ch );
curl_close( $ch );
}
}
$mdb -> update( 'pp_shop_orders', [ 'paid' => 0 ], [ 'id' => $this -> id ] );
return true;
}
@@ -108,53 +78,6 @@ class Order implements \ArrayAccess
{
global $mdb, $config;
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] )
{
if ( $this -> sellasist_order_id )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
'paid' => str_replace( ',', '.', $this -> summary ),
'payment_status' => 'paid'
] ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"accept: application/json",
"apiKey: " . $sellasist_settings['api_code'],
"Content-Type: application/json"
) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_exec( $ch );
curl_close( $ch );
}
}
$baselinker_settings = \admin\factory\Integrations::baselinker_settings();
if ( $baselinker_settings['enabled'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders'] )
{
if ( $this -> baselinker_order_id )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://api.baselinker.com/connector.php" );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( [
'token' => $baselinker_settings['api_code'],
'method' => 'setOrderPayment',
'parameters' => json_encode( [
'order_id' => $this -> baselinker_order_id,
'payment_done' => $this -> summary,
'payment_date' => time( 'Y-m-d H:i:s' )
] )
] ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_exec( $ch );
curl_close( $ch );
}
}
// apilo
$apilo_settings = \admin\factory\Integrations::apilo_settings();
if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders'] )
@@ -233,51 +156,6 @@ class Order implements \ArrayAccess
$response['result'] = true;
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] )
{
if ( $this -> sellasist_order_id )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
'status' => \front\factory\ShopStatuses::get_sellasist_status_id( $status )
] ) );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"accept: application/json",
"apiKey: " . $sellasist_settings['api_code'],
"Content-Type: application/json"
) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
curl_exec( $ch );
curl_close( $ch );
}
}
$baselinker_settings = \admin\factory\Integrations::baselinker_settings();
if ( $baselinker_settings['enabled'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders'] )
{
if ( $this -> baselinker_order_id )
{
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://api.baselinker.com/connector.php" );
curl_setopt( $ch, CURLOPT_POST, 1 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( [
'token' => $baselinker_settings['api_code'],
'method' => 'setOrderStatus',
'parameters' => json_encode( [
'order_id' => $this -> baselinker_order_id,
'status_id' => \shop\ShopStatus::get_baselinker_status_by_shop_status( $status )
] )
] ) );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
$curl_result = curl_exec( $ch );
curl_close( $ch );
}
}
// apilo
$apilo_settings = \admin\factory\Integrations::apilo_settings();
if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders'] )

View File

@@ -264,18 +264,6 @@ class Product implements \ArrayAccess
return false;
}
// pobierz id produktu z Baselinker
static public function get_baselinker_product_id( int $product_id )
{
global $mdb;
$result = $mdb -> get( 'pp_shop_products', [ 'parent_id', 'baselinker_product_id' ], [ 'id' => $product_id ] );
if ( $result['baselinker_product_id'] )
return $result['baselinker_product_id'];
else
return $mdb -> get( 'pp_shop_products', 'baselinker_product_id', [ 'id' => $result['parent_id'] ] );
}
// pobierz kod SKU
static public function get_product_sku( int $product_id )
{

View File

@@ -1,15 +0,0 @@
<?
namespace shop;
class ShopStatus {
// get_status_by_baselinker_status
static public function get_shop_status_by_baselinker_status( int $baselinker_status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'baselinker_status_id' => $baselinker_status_id ] );
}
// get_baselinker_status_by_shop_status
static public function get_baselinker_status_by_shop_status( int $shop_status_id ) {
global $mdb;
return $mdb -> get( 'pp_shop_statuses', 'baselinker_status_id', [ 'id' => $shop_status_id ] );
}
}