63 lines
2.2 KiB
PHP
63 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ElninoBundle\Controller;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class FixCancelledOrdersInAbraController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/fixCancelledOrdersInAbra/", name="fixCancelledOrdersInAbra")
|
|
*/
|
|
public function fixCancelledOrdersInAbraAction()
|
|
{
|
|
$config = findModule(\Modules::ORDERS, \Modules::SUB_NOTIFY_NOT_PAID);
|
|
$paymentMethods = [];
|
|
foreach ((array) ($config ?? []) as $notifySettings) {
|
|
if (($notifySettings['cancelHours'] ?? 0) > 0) {
|
|
$paymentMethods = array_merge($paymentMethods, $notifySettings['forPaymentMethods'] ?? []);
|
|
}
|
|
}
|
|
|
|
if (count($paymentMethods) <= 0) {
|
|
echo 'Automatické storno je vypnuté.';
|
|
exit;
|
|
}
|
|
|
|
$abra = new \AbraElnino();
|
|
$fixedCount = 0;
|
|
ob_end_clean();
|
|
ob_implicit_flush(true);
|
|
ini_set('max_execution_time', 60 * 60 * 10);
|
|
|
|
$orderResults = sqlQueryBuilder()->select('o.id')->from('orders', 'o')
|
|
->where('o.status_payed = 0 AND o.status_storno = 1')
|
|
->andWhere(\Query\Order::byPaymentMethods($paymentMethods))
|
|
->groupBy('o.id')
|
|
->orderBy('o.date_accept', 'ASC')->execute();
|
|
foreach ($orderResults as $orderResult) {
|
|
$order = new \Order();
|
|
$order->createFromDB($orderResult['id']);
|
|
if ($order->getData('abra_status_checked')) {
|
|
continue;
|
|
}
|
|
$result = $abra->getOrderStatus($order);
|
|
if ($result == 0) {
|
|
try {
|
|
$order->storno(false, null, false);
|
|
echo $order->id.', '.PHP_EOL;
|
|
$fixedCount++;
|
|
} catch (\Exception $e) {
|
|
if ($e->getMessage() != 'ERROR:WEB007 - OBJEKT v Abře neexistuje.') {
|
|
throw $e;
|
|
}
|
|
}
|
|
}
|
|
$order->setData('abra_status_checked', true);
|
|
}
|
|
echo PHP_EOL.PHP_EOL.'Opraveno objednávek: '.$fixedCount;
|
|
exit;
|
|
}
|
|
}
|