129 lines
5.0 KiB
PHP
129 lines
5.0 KiB
PHP
<?php
|
|
require_once __DIR__.'/../../src/EpakaApi.php';
|
|
require_once __DIR__.'/../../src/EpakaDB.php';
|
|
|
|
class EpakaMapModuleFrontController extends ModuleFrontController
|
|
{
|
|
private $api = null;
|
|
private $DB = null;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
// $this->display_column_left = false;
|
|
// $this->display_column_right = false;
|
|
|
|
$this->api = new EpakaApi();
|
|
$this->DB = new EpakaDB();
|
|
}
|
|
|
|
public function displayAjaxGetMachinesPoints()
|
|
{
|
|
if (!empty($epaka_api_email = Configuration::get('EPAKA_API_EMAIL')) &&
|
|
!empty($epaka_api_password = Configuration::get('EPAKA_API_PASSWORD')) &&
|
|
!empty($epaka_api_session = Configuration::get('EPAKA_API_SESSION'))) {
|
|
$this->api->init($epaka_api_email, $epaka_api_password, $epaka_api_session);
|
|
}
|
|
|
|
$endpoint = !empty(Tools::getValue('endpoint')) ? urldecode(Tools::getValue('endpoint')) : 'getInpostMachines.xml';
|
|
|
|
if (!$this->api->connected()) {
|
|
// $this->api->getApiTokenAuth(Configuration::get('EPAKA_API_EMAIL'), Configuration::get('EPAKA_API_PASSWORD'));
|
|
die(json_encode(array('status' => 'error', 'message' => 'Connection failed!', 'endpoint' => $endpoint)));
|
|
}
|
|
|
|
$responseType = "XML";
|
|
if(preg_match('/map_popup/', $endpoint)){
|
|
$responseType = "JSON";
|
|
}
|
|
|
|
$postData = $this->api->getMap(null, $endpoint, $_POST, $responseType);
|
|
|
|
die(json_encode($postData));
|
|
}
|
|
|
|
public function displayAjaxValidateMachinePoints()
|
|
{
|
|
$id_cart = Context::getContext()->cart->id;
|
|
if (empty($id_cart)) {
|
|
die(json_encode(['status' => 'error', 'message' => 'Wybierz']));
|
|
}
|
|
|
|
$id_carrier_prestashop = Tools::getValue('id_carrier_prestashop');
|
|
$id_carrier_epaka = Tools::getValue('id_carrier_epaka');
|
|
if (!empty($id_carrier_prestashop) && !empty($id_carrier_epaka)) {
|
|
|
|
// jesli kurier jest bez punktu odbioru (normalny kurier d2d)
|
|
$referencjeEpaka = $this->DB->getCourriersRelations($id_carrier_prestashop, $id_carrier_epaka);
|
|
if (!empty($referencjeEpaka) && count($referencjeEpaka) && $referencjeEpaka[0]['epaka_carrier_delivery_type'] == "d2d") {
|
|
die(json_encode(array('status' => 'ok')));
|
|
} elseif (empty($referencjeEpaka)) {
|
|
die(json_encode(array('status' => 'error', 'message' => 'Nie znaleziono referencji prestashop <-> epaka.')));
|
|
}
|
|
|
|
if ($this->DB->checkIfIsOrderReferenceIsOK($id_cart, $id_carrier_prestashop, $id_carrier_epaka)) {
|
|
die(json_encode(array('status' => 'ok')));
|
|
} else {
|
|
die(json_encode(array('status' => 'error', 'message' => 'Wybierz punkt odbioru.')));
|
|
}
|
|
}
|
|
|
|
die(json_encode(array('status' => 'ok')));
|
|
}
|
|
|
|
public function displayAjaxSaveMachinePoints()
|
|
{
|
|
$id_cart = Context::getContext()->cart->id;
|
|
if (empty($id_cart)) {
|
|
die(json_encode(['status' => 'error', 'message' => 'Błąd zapisu punktu odbioru.']));
|
|
}
|
|
|
|
$id_carrier_prestashop = Tools::getValue('id_carrier_prestashop');
|
|
$id_carrier_epaka = Tools::getValue('id_carrier_epaka');
|
|
$point_code = Tools::getValue('point_code');
|
|
$point_name = Tools::getValue('point_name');
|
|
|
|
if (!empty($id_carrier_prestashop) && (!empty($id_carrier_epaka) || $id_carrier_epaka=='0')) {
|
|
$insertData = [
|
|
'id_cart' => $id_cart,
|
|
'id_carrier_prestashop' => $id_carrier_prestashop,
|
|
'id_carrier_epaka' => $id_carrier_epaka,
|
|
];
|
|
if (!empty($point_code)) {
|
|
$insertData['point_code'] = $point_code;
|
|
} else {
|
|
$insertData['point_code'] = NULL;
|
|
}
|
|
if (!empty($point_name)) {
|
|
$insertData['point_name'] = $point_name;
|
|
} else {
|
|
$insertData['point_name'] = NULL;
|
|
}
|
|
|
|
// $result = Db::getInstance()->insert('epaka_delivery',$insertData, false, true, Db::ON_DUPLICATE_KEY);
|
|
// $result = Db::insertRelation(
|
|
// $insertData['id_cart'],
|
|
// $insertData['id_carrier_prestashop'],
|
|
// $insertData['id_carrier_epaka'],
|
|
// $insertData['point_code'],
|
|
// $insertData['point_name'],
|
|
// NULL
|
|
// );
|
|
$result = $this->DB->insertRelation(
|
|
$insertData['id_cart'],
|
|
$insertData['id_carrier_prestashop'],
|
|
$insertData['id_carrier_epaka'],
|
|
$insertData['point_code'],
|
|
$insertData['point_name'],
|
|
NULL
|
|
);
|
|
|
|
if($result){
|
|
die(json_encode(['status' => 'ok']));
|
|
}
|
|
}
|
|
|
|
die(json_encode(['status' => 'error', 'message' => 'Błąd zapisu punktu odbioru.']));
|
|
}
|
|
}
|