Files
kupshop/bundles/KupShop/ContentBundle/View/OrderStatusView.php
2025-08-02 16:30:27 +02:00

131 lines
2.9 KiB
PHP

<?php
/**
* Created by PhpStorm.
* User: ondra
* Date: 18.1.18
* Time: 14:08.
*/
namespace KupShop\ContentBundle\View;
use KupShop\ContentBundle\Util\Captcha;
use KupShop\ContentBundle\View\Exception\ValidationException;
use KupShop\KupShopBundle\Views\Traits\RequestTrait;
use KupShop\KupShopBundle\Views\View;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class OrderStatusView extends View
{
use RequestTrait;
protected $template = 'orderStatus.tpl';
protected $user;
protected $orderId;
public function __construct()
{
$this->user = \User::getCurrentUser();
}
public function getResponse(?Request $request = null)
{
if (!findModule('orders')) {
redirection('MODUL_NOT_FOUND');
}
if ($this->user) {
return new RedirectResponse(
createScriptURL([
'URL' => 'launch.php',
's' => 'orders',
'ESCAPE' => 'NO',
])
);
}
return parent::getResponse($request);
}
public function getTitle()
{
return parent::getTitle();
}
public function getBodyVariables()
{
$vars = parent::getBodyVariables();
if ($this->orderId) {
if ($this->checkCaptcha()) {
if ($order = $this->getOrder()) {
$vars['order'] = $order;
} else {
addUserMessage('Objednávka neexistuje.');
}
} else {
addUserMessage('Chybný kontrolní kód.');
}
}
return $vars;
}
public function getBreadcrumbs()
{
if ($this->user) {
$url = createScriptURL([
'URL' => 'launch.php',
's' => 'orders',
]);
return getReturnNavigation(-1, 'NO_TYPE', [['link' => $url, 'text' => translate('returnNav', 'orderView')[0]], ['text' => translate('returnNav', 'orderView')[1]]]);
}
return getReturnNavigation(-1, 'NO_TYPE', [translate('returnNav', 'orderView')[1]]);
}
private function getOrder()
{
$IDo = sqlFormatInput($this->orderId);
$IDo = returnSQLResult('SELECT id FROM '.getTableName('orders')." WHERE order_no='{$IDo}'");
if (!$IDo) {
return false;
}
$orderObj = new \Order();
if ($orderObj->createFromDB($IDo)) {
$orderObj->status_text = $orderObj->getStatusText();
return $orderObj;
}
return false;
}
private function checkCaptcha()
{
try {
Captcha::checkCaptcha();
} catch (ValidationException $e) {
return false;
}
return true;
}
/**
* @return $this
*/
public function setOrderId($orderId)
{
$this->orderId = $orderId;
return $this;
}
}