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) {
|
function copyToClipboard(text) {
|
||||||
navigator.clipboard.writeText(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");
|
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}
|
{$ROW.sum_by_products}
|
||||||
{math equation="abs(x-y)" x=$ROW.total_netto y=$ROW.sum_by_products assign="price_difference"}
|
{math equation="abs(x-y)" x=$ROW.total_netto y=$ROW.sum_by_products assign="price_difference"}
|
||||||
{if $price_difference > 0.02}
|
{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}
|
{/if}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
// ?XDEBUG_SESSION_START=PHPSTORM
|
// ?XDEBUG_SESSION_START=PHPSTORM
|
||||||
//importApiloInvoices();
|
//importInvoices();
|
||||||
function importInvoices()
|
function importInvoices()
|
||||||
{
|
{
|
||||||
$apilo_config = loadApiloConfiguration();
|
$apilo_config = loadApiloConfiguration();
|
||||||
@@ -10,9 +10,8 @@ function importInvoices()
|
|||||||
$offset = intval($db->fetchByAssoc($dbRes)['last_id']);
|
$offset = intval($db->fetchByAssoc($dbRes)['last_id']);
|
||||||
|
|
||||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||||
|
|
||||||
if (isset($invoices->error)) {
|
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();
|
$apilo_config = loadApiloConfiguration();
|
||||||
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
$invoices = loadApiloInvoices($apilo_config['token'], $offset);
|
||||||
} else {
|
} else {
|
||||||
@@ -72,41 +71,42 @@ function loadApiloInvoices($token, $offset)
|
|||||||
}
|
}
|
||||||
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
function refreshApiloToken($refreshToken, $clientId, $clientSecret)
|
||||||
{
|
{
|
||||||
$url = "https://api.apilo.com/oauth/token";
|
$url = "https://twinpol.apilo.com/rest/auth/token/";
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'grant_type' => 'refresh_token',
|
'grantType' => 'refresh_token',
|
||||||
'refresh_token' => $refreshToken,
|
'token' => $refreshToken,
|
||||||
'client_id' => $clientId,
|
|
||||||
'client_secret' => $clientSecret
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type: application/x-www-form-urlencoded',
|
'Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret),
|
||||||
|
'Content-Type: application/json',
|
||||||
'Accept: application/json'
|
'Accept: application/json'
|
||||||
];
|
];
|
||||||
|
|
||||||
$curl = curl_init($url);
|
$curl = curl_init($url);
|
||||||
curl_setopt($curl, CURLOPT_POST, true);
|
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_HTTPHEADER, $headers);
|
||||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||||
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
||||||
|
|
||||||
$response = curl_exec($curl);
|
$response = curl_exec($curl);
|
||||||
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||||
|
$err = curl_error($curl);
|
||||||
curl_close($curl);
|
curl_close($curl);
|
||||||
|
|
||||||
|
brecho($response);
|
||||||
|
brecho($httpCode);
|
||||||
if ($httpCode !== 200) {
|
if ($httpCode !== 200) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tokenData = json_decode($response, true);
|
$tokenData = json_decode($response, true);
|
||||||
|
|
||||||
if (isset($tokenData['access_token'])) {
|
brecho($tokenData);
|
||||||
|
if (isset($tokenData['accessToken'])) {
|
||||||
global $db;
|
global $db;
|
||||||
$db->query("UPDATE config SET value='" . $tokenData['access_token'] . "' WHERE category='apilo' AND name='access_token'");
|
$db->query("UPDATE config SET value='" . $tokenData['access_token'] . "' WHERE category='apilo' AND name='access_token'");
|
||||||
|
|
||||||
if (isset($tokenData['refresh_token'])) {
|
if (isset($tokenData['refresh_token'])) {
|
||||||
$db->query("UPDATE config SET value='" . $tokenData['refresh_token'] . "' WHERE category='apilo' AND name='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');
|
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php');
|
||||||
} else if (isset($_REQUEST['apilo_details'])) {
|
} else if (isset($_REQUEST['apilo_details'])) {
|
||||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/apiloInvoiceDetails.php');
|
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'])) {
|
} else if (isset($_REQUEST['apilo_products'])) {
|
||||||
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/checkApiloProducts.php');
|
include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/checkApiloProducts.php');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ function importBaselinkerInvoices()
|
|||||||
require_once('modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importBaselinkerInvoices.php');
|
require_once('modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importBaselinkerInvoices.php');
|
||||||
importFV('7688'); // FV Polska
|
importFV('7688'); // FV Polska
|
||||||
//importFV('15356'); // FV Polska (stare)
|
//importFV('15356'); // FV Polska (stare)
|
||||||
|
importFV('53096'); // FV Temu
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user