WIP: ecommerce
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
$id = $_REQUEST['baselinker_details'];
|
||||
brecho($id);
|
||||
|
||||
$baselinker_config = loadConfiguration();
|
||||
$order = getOrder($baselinker_config['token'], $id);
|
||||
brecho($order);
|
||||
function loadConfiguration()
|
||||
{
|
||||
global $db;
|
||||
$dbRes = $db->query("SELECT * FROM config WHERE category='baselinker'");
|
||||
$config = [];
|
||||
while ($row = $db->fetchByAssoc($dbRes)) {
|
||||
$config[$row['name']] = $row['value'];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
function getOrder($token, $orderId)
|
||||
{
|
||||
$methodParams = '{
|
||||
"order_id": ' . $orderId . '
|
||||
}';
|
||||
$apiParams = [
|
||||
"method" => "getOrders",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init("https://api.baselinker.com/connector.php");
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, ["X-BLToken: " . $token]);
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 0);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($apiParams));
|
||||
$res = json_decode(curl_exec($curl));
|
||||
if ($res->orders[0]->order_source != '') {
|
||||
return $res->orders[0];
|
||||
}
|
||||
}
|
||||
function brecho($msg)
|
||||
{
|
||||
echo '<br><pre>';
|
||||
var_dump($msg);
|
||||
echo PHP_EOL;
|
||||
echo '</pre><br>';
|
||||
}
|
||||
@@ -109,6 +109,12 @@ function blockUI($msg) {
|
||||
function copyToClipboard(text) {
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
function openDetails(id) {
|
||||
function openDetails(id, origin) {
|
||||
window.console.log(origin);
|
||||
if (origin.startsWith('apilo')) {
|
||||
window.open("index.php?module=EcmInvoiceOuts&action=ecommerce&apilo_details="+id, "_blank");
|
||||
} else {
|
||||
window.open("index.php?module=EcmInvoiceOuts&action=ecommerce&baselinker_details="+id, "_blank");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -153,7 +153,7 @@
|
||||
{$ROW.sum_by_products}
|
||||
{math equation="abs(x-y)" x=$ROW.total_netto y=$ROW.sum_by_products assign="price_difference"}
|
||||
{if $price_difference > 0.02}
|
||||
<span style="color: red; font-weight: bold; cursor: pointer" onclick="openDetails('{$ROW.order_no}')">!!!</span>
|
||||
<span style="color: red; font-weight: bold; cursor: pointer" onclick="openDetails('{$ROW.order_no}', '{$ROW.origin}')">!!!</span>
|
||||
{/if}
|
||||
</td>
|
||||
<td>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
// ?XDEBUG_SESSION_START=PHPSTORM
|
||||
//importApiloInvoices();
|
||||
//importInvoices();
|
||||
function importInvoices()
|
||||
{
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
@@ -10,9 +10,8 @@ function importInvoices()
|
||||
$offset = intval($db->fetchByAssoc($dbRes)['last_id']);
|
||||
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
|
||||
if (isset($invoices->error)) {
|
||||
if (refreshApiloToken($apilo_config['refresh_token'], $apilo_config['client_id'], $apilo_config['client_secret']) == true) {
|
||||
if (refreshApiloToken($apilo_config['refreshToken'], $apilo_config['clientId'], $apilo_config['clientSecret']) == true) {
|
||||
$apilo_config = loadApiloConfiguration();
|
||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||
} else {
|
||||
@@ -72,41 +71,42 @@ function loadApiloInvoices($token, $offset)
|
||||
}
|
||||
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
||||
{
|
||||
$url = "https://api.apilo.com/oauth/token";
|
||||
$url = "https://twinpol.apilo.com/rest/auth/token/";
|
||||
|
||||
$data = [
|
||||
'grant_type' => 'refresh_token',
|
||||
'refresh_token' => $refreshToken,
|
||||
'client_id' => $clientId,
|
||||
'client_secret' => $clientSecret
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $refreshToken,
|
||||
];
|
||||
|
||||
$headers = [
|
||||
'Content-Type: application/x-www-form-urlencoded',
|
||||
'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json'
|
||||
];
|
||||
|
||||
$curl = curl_init($url);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
$err = curl_error($curl);
|
||||
curl_close($curl);
|
||||
|
||||
brecho($response);
|
||||
brecho($httpCode);
|
||||
if ($httpCode !== 200) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$tokenData = json_decode($response, true);
|
||||
|
||||
if (isset($tokenData['access_token'])) {
|
||||
brecho($tokenData);
|
||||
if (isset($tokenData['accessToken'])) {
|
||||
global $db;
|
||||
$db->query("UPDATE config SET value='" . $tokenData['access_token'] . "' WHERE category='apilo' AND name='access_token'");
|
||||
|
||||
if (isset($tokenData['refresh_token'])) {
|
||||
$db->query("UPDATE config SET value='" . $tokenData['refresh_token'] . "' WHERE category='apilo' AND name='refresh_token'");
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ if (isset($_REQUEST['import_baselinker'])) {
|
||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php');
|
||||
} else if (isset($_REQUEST['apilo_details'])) {
|
||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/apiloInvoiceDetails.php');
|
||||
} else if (isset($_REQUEST['baselinker_details'])) {
|
||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/baselinkerInvoiceDetails.php');
|
||||
} else if (isset($_REQUEST['apilo_products'])) {
|
||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/checkApiloProducts.php');
|
||||
} else {
|
||||
|
||||
@@ -86,6 +86,7 @@ function importBaselinkerInvoices()
|
||||
require_once('modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importBaselinkerInvoices.php');
|
||||
importFV('7688'); // FV Polska
|
||||
//importFV('15356'); // FV Polska (stare)
|
||||
importFV('53096'); // FV Temu
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user