2017-01-02 12:25:33 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* 2007-2015 PrestaShop
|
2016-01-04 12:49:26 +01:00
|
|
|
*
|
|
|
|
* NOTICE OF LICENSE
|
|
|
|
*
|
|
|
|
* This source file is subject to the Academic Free License (AFL 3.0)
|
|
|
|
* that is bundled with this package in the file LICENSE.txt.
|
|
|
|
* It is also available through the world-wide-web at this URL:
|
|
|
|
* http://opensource.org/licenses/afl-3.0.php
|
|
|
|
* If you did not receive a copy of the license and are unable to
|
|
|
|
* obtain it through the world-wide-web, please send an email
|
|
|
|
* to license@prestashop.com so we can send you a copy immediately.
|
|
|
|
*
|
|
|
|
* DISCLAIMER
|
|
|
|
*
|
|
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
|
|
*
|
2017-01-02 12:25:33 +01:00
|
|
|
* @author PrestaShop SA <contact@prestashop.com>
|
|
|
|
* @copyright 2007-2015 PrestaShop SA
|
|
|
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
|
|
|
* International Registered Trademark & Property of PrestaShop SA
|
2016-01-04 12:49:26 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-01-02 12:25:33 +01:00
|
|
|
* File called by ajax. It's like a controller, you have to send the
|
|
|
|
* method name of the webservice and implement it.
|
2016-01-04 12:49:26 +01:00
|
|
|
* Each Name method allow to instanciate an object containing
|
2017-01-02 12:25:33 +01:00
|
|
|
* methods to manage correctly the data and name fields
|
2016-01-04 12:49:26 +01:00
|
|
|
*/
|
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/*
|
|
|
|
* Clean displayed content for Admin ajax query
|
|
|
|
*/
|
|
|
|
@ob_clean();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Front Ajax query, need the front cookie and MR class
|
|
|
|
* When it's back query, the PS core made the work
|
|
|
|
*/
|
|
|
|
if (!defined('_PS_ADMIN_DIR_'))
|
|
|
|
{
|
|
|
|
require_once(realpath(dirname(__FILE__).'/../../config/config.inc.php'));
|
|
|
|
require_once(realpath(dirname(__FILE__).'/../../init.php'));
|
|
|
|
require_once(dirname(__FILE__).'/mondialrelay.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
$mondialrelay = isset($this) ? $this : new Mondialrelay();
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
require_once(dirname(__FILE__).'/classes/MRCreateTickets.php');
|
|
|
|
require_once(dirname(__FILE__).'/classes/MRGetTickets.php');
|
|
|
|
require_once(dirname(__FILE__).'/classes/MRGetRelayPoint.php');
|
|
|
|
require_once(dirname(__FILE__).'/classes/MRRelayDetail.php');
|
|
|
|
require_once(dirname(__FILE__).'/classes/MRManagement.php');
|
|
|
|
require_once(dirname(__FILE__).'/classes/MRDownloadPDF.php');
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/* Can't use Tools at this time... Need to know if _PS_ADMIN_DIR_ has to be defined */
|
|
|
|
$method = Tools::getValue('method');
|
|
|
|
$token = Tools::getValue('mrtoken');
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/* Access page List liable to the generated token*/
|
2016-01-04 12:49:26 +01:00
|
|
|
$accessPageList = array(
|
|
|
|
MondialRelay::getToken('front') => array(
|
|
|
|
'MRGetRelayPoint',
|
2017-01-02 12:25:33 +01:00
|
|
|
'addSelectedCarrierToDB'
|
|
|
|
),
|
2016-01-04 12:49:26 +01:00
|
|
|
MondialRelay::getToken('back') => array(
|
|
|
|
'MRGetTickets',
|
|
|
|
'MRCreateTickets',
|
|
|
|
'MRDeleteHistory',
|
|
|
|
'uninstallDetail',
|
2017-01-02 12:25:33 +01:00
|
|
|
'DeleteHistory',
|
|
|
|
'MRDownloadPDF'
|
|
|
|
)
|
|
|
|
);
|
2016-01-04 12:49:26 +01:00
|
|
|
|
|
|
|
$params = array();
|
|
|
|
$result = array();
|
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/* If the method name associated to the token received doesn't match with*/
|
|
|
|
/* the list, then we kill the request*/
|
2016-01-04 12:49:26 +01:00
|
|
|
if (!isset($accessPageList[$token]) || !in_array($method, $accessPageList[$token]))
|
|
|
|
exit();
|
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/* Method name allow to instanciate his object to properly call the*/
|
|
|
|
/* implemented interface method and do his job*/
|
|
|
|
switch ($method)
|
2016-01-04 12:49:26 +01:00
|
|
|
{
|
|
|
|
case 'MRCreateTickets':
|
|
|
|
$params['orderIdList'] = Tools::getValue('order_id_list');
|
|
|
|
$params['totalOrder'] = Tools::getValue('numSelected');
|
|
|
|
$params['weightList'] = Tools::getValue('weight_list');
|
2017-01-02 12:25:33 +01:00
|
|
|
$params['insuranceList'] = Tools::getValue('insurance_list');
|
2016-01-04 12:49:26 +01:00
|
|
|
break;
|
|
|
|
case 'MRGetTickets':
|
|
|
|
$params['detailedExpeditionList'] = Tools::getValue('detailedExpeditionList');
|
|
|
|
break;
|
2017-01-02 12:25:33 +01:00
|
|
|
case 'MRDownloadPDF':
|
|
|
|
$params['Expeditions'] = Tools::getValue('detailedExpeditionList');
|
|
|
|
break;
|
2016-01-04 12:49:26 +01:00
|
|
|
case 'DeleteHistory':
|
|
|
|
$params['historyIdList'] = Tools::getValue('history_id_list');
|
|
|
|
break;
|
|
|
|
case 'uninstallDetail':
|
|
|
|
$params['action'] = Tools::getValue('action');
|
|
|
|
break;
|
|
|
|
case 'MRGetRelayPoint':
|
|
|
|
$params['id_carrier'] = Tools::getValue('id_carrier');
|
2017-01-02 12:25:33 +01:00
|
|
|
$params['weight'] = Context::getContext()->cart->getTotalWeight();
|
|
|
|
$params['id_address_delivery'] = Context::getContext()->cart->id_address_delivery;
|
2016-01-04 12:49:26 +01:00
|
|
|
break;
|
|
|
|
case 'addSelectedCarrierToDB':
|
|
|
|
$params['id_carrier'] = Tools::getValue('id_carrier');
|
2017-01-02 12:25:33 +01:00
|
|
|
$params['id_cart'] = Context::getContext()->cart->id;
|
|
|
|
$params['id_customer'] = Context::getContext()->customer->id;
|
2016-01-04 12:49:26 +01:00
|
|
|
$params['id_mr_method'] = Tools::getValue('id_mr_method');
|
|
|
|
$params['relayPointInfo'] = Tools::getValue('relayPointInfo');
|
|
|
|
break;
|
|
|
|
default:
|
2017-01-02 12:25:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Try to instanciate the method object name and call the necessaries method*/
|
|
|
|
try
|
2016-01-04 12:49:26 +01:00
|
|
|
{
|
|
|
|
if (class_exists($method, false))
|
|
|
|
{
|
2017-01-02 12:25:33 +01:00
|
|
|
/* $this is the current mondialrelay object loaded when use in BO. Use for perf*/
|
|
|
|
$obj = new $method($params, $mondialrelay);
|
2016-01-04 12:49:26 +01:00
|
|
|
|
2017-01-02 12:25:33 +01:00
|
|
|
/* Verify that the class implement correctly the interface*/
|
|
|
|
/* Else use a Management class to do some ajax stuff*/
|
2016-01-04 12:49:26 +01:00
|
|
|
if (($obj instanceof IMondialRelayWSMethod))
|
|
|
|
{
|
|
|
|
$obj->init();
|
|
|
|
$obj->send();
|
|
|
|
$result = $obj->getResult();
|
|
|
|
}
|
|
|
|
unset($obj);
|
|
|
|
}
|
2017-01-02 12:25:33 +01:00
|
|
|
else if (($management = new MRManagement($params)) && method_exists($management, $method))
|
|
|
|
$result = $management->{$method}();
|
|
|
|
else
|
2016-01-04 12:49:26 +01:00
|
|
|
throw new Exception('Method Class : '.$method.' can\'t be found');
|
|
|
|
unset($management);
|
|
|
|
}
|
|
|
|
catch(Exception $e)
|
|
|
|
{
|
2017-01-02 12:25:33 +01:00
|
|
|
echo MRTools::jsonEncode(array('other' => array('error' => array($e->getMessage()))));
|
2016-01-04 12:49:26 +01:00
|
|
|
exit(-1);
|
|
|
|
}
|
2017-01-02 12:25:33 +01:00
|
|
|
echo MRTools::jsonEncode($result);
|
2016-01-04 12:49:26 +01:00
|
|
|
exit(0);
|