Files
wyczarujprezent.pl/modules/ecsgtmpro/controllers/front/callback.php
2024-10-28 22:14:22 +01:00

125 lines
3.6 KiB
PHP

<?php
/**
* 2022 ECSoft
*
* 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 dev.ecsoft@gmail.com so we can send you a copy immediately.
*
* @author ECSoft <dev.ecsoft@gmail.com>
* @copyright 2022 ECSoft
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of ECSoft
*/
include_once dirname(__FILE__) . '/../../classes/EcsGtmProTools.php';
class EcsGtmProCallbackModuleFrontController extends ModuleFrontController
{
protected $updated = 0;
public function __construct()
{
if (Tools::usingSecureMode()) {
$this->ssl = true;
}
return parent::__construct();
}
public function display()
{
echo $this->updated;
return '';
}
public function initContent()
{
$p = Tools::getValue('p');
if (!empty($p)) {
$params = EcsGtmProTools::jsonDecode(base64_decode(urldecode($p)), true);
if (isset($params['type'])) {
switch ($params['type']) {
case 'orderconfirmation':
$this->orderConfirmation($params['params']);
break;
case 'orderrefund':
$this->orderRefund($params['params']);
break;
case 'orderresend':
$this->orderResend($params['params']);
break;
default:
break;
}
}
}
}
protected function orderResend($params)
{
$orders = $params['orders'];
$id_shop = $params['id_shop'];
foreach ($orders as $order_id) {
$gtmOrder = EcsGtmProOrder::getByOrderId($order_id, $id_shop);
$gtmOrder->resent = ((int) $gtmOrder->resent) + 1;
$gtmOrder->save();
$order = new Order($order_id);
if (Validate::isLoadedObject($order)) {
$id_cart = $order->id_cart;
$pool = $this->module->getResendPool($id_shop);
if (isset($pool[$id_cart])) {
unset($pool[$id_cart]);
$this->module->updateResendPool($pool, $id_shop);
}
}
$this->updated++;
}
die(EcsGtmProTools::jsonEncode(array(
'model' => $gtmOrder
)));
}
protected function orderConfirmation($params)
{
$orders = $params['orders'];
$id_shop = $params['id_shop'];
foreach ($orders as $order_id) {
$gtmOrder = EcsGtmProOrder::getByOrderId($order_id, $id_shop);
if ($gtmOrder->sent == 0) {
$gtmOrder->sent = 1;
$gtmOrder->save();
$this->updated++;
}
}
die(EcsGtmProTools::jsonEncode(array(
'model' => $gtmOrder
)));
}
protected function orderRefund($params)
{
$order_id = $params['order'];
$id_shop = $params['id_shop'];
$pool = $this->module->getRefundPool($id_shop);
if (isset($pool[$order_id])) {
unset($pool[$order_id]);
$this->module->updateRefundPool($pool, $id_shop);
$this->updated++;
}
}
}