44 lines
1.7 KiB
PHP
44 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Bitrix\Main\Application;
|
|
use Bitrix\Main\Engine\CurrentUser;
|
|
use Bitrix\Main\Localization\Loc;
|
|
use Jinove\Vinoteca\Personal\Orders;
|
|
|
|
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
|
|
die();
|
|
}
|
|
|
|
Loc::loadMessages(__FILE__);
|
|
|
|
class JinovePersonalOrdersComponent extends CBitrixComponent
|
|
{
|
|
public function executeComponent(): array
|
|
{
|
|
$userId = (int)CurrentUser::get()->getId();
|
|
if ($userId <= 0) {
|
|
LocalRedirect(SITE_DIR . "login/?back=" . rawurlencode(Application::getInstance()->getContext()->getRequest()->getRequestUri()));
|
|
}
|
|
$request = Application::getInstance()->getContext()->getRequest();
|
|
$completed = (string)$request->getQuery("status") === "completed";
|
|
$page = max(1, min(50, (int)$request->getQuery("page")));
|
|
$result = Orders::forUser($userId, $completed, $page);
|
|
$GLOBALS["APPLICATION"]->SetTitle(Loc::getMessage("VINO_ORD_PAGE_TITLE"));
|
|
$GLOBALS["APPLICATION"]->SetPageProperty("description", Loc::getMessage("VINO_ORD_PAGE_DESCRIPTION"));
|
|
$GLOBALS["APPLICATION"]->SetPageProperty("vino_alternates", "N");
|
|
$GLOBALS["APPLICATION"]->SetPageProperty("vino_schema", "N");
|
|
$GLOBALS["APPLICATION"]->SetPageProperty("robots", "noindex, nofollow");
|
|
$this->arResult = [
|
|
"COMPLETED" => $completed,
|
|
"ORDERS" => $result["orders"],
|
|
"MORE_URL" => $result["more"] ? SITE_DIR . "personal/orders/?" . ($completed ? "status=completed&" : "") . "page=" . ($page + 1) : "",
|
|
"BASE_URL" => SITE_DIR . "personal/orders/",
|
|
"CATALOG_URL" => SITE_DIR . "catalog/",
|
|
];
|
|
$this->includeComponentTemplate();
|
|
|
|
return $this->arResult;
|
|
}
|
|
}
|