Vinoteca: wine shop on 1C-Bitrix (module, template, components, pages)
This commit is contained in:
commit
52795535ae
586 files changed
+27619
No files matched your search
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca\Controller;
|
||||
|
||||
use Bitrix\Main\Engine\ActionFilter\HttpMethod;
|
||||
use Bitrix\Main\Engine\Controller;
|
||||
use Bitrix\Main\Engine\Response\Component;
|
||||
use Bitrix\Main\Error;
|
||||
use Jinove\Vinoteca\Catalog\Listing;
|
||||
|
||||
class Catalog extends Controller
|
||||
{
|
||||
public function configureActions(): array
|
||||
{
|
||||
return [
|
||||
"listing" => [
|
||||
"prefilters" => [new HttpMethod([HttpMethod::METHOD_GET])],
|
||||
],
|
||||
"filter" => [
|
||||
"prefilters" => [new HttpMethod([HttpMethod::METHOD_GET])],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function listingAction(string $path): ?Component
|
||||
{
|
||||
$route = Listing::parsePath($path);
|
||||
if ($route === null) {
|
||||
$this->addError(new Error("Wrong path"));
|
||||
|
||||
return null;
|
||||
}
|
||||
if (!Listing::filterPathIsValid($route["SECTION_CODE"], $route["FILTER_PATH"])) {
|
||||
$this->addError(new Error("Wrong filter"));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Component(
|
||||
"jinove:catalog.listing",
|
||||
"",
|
||||
[
|
||||
"SECTION_CODE" => $route["SECTION_CODE"],
|
||||
"FILTER_PATH" => $route["FILTER_PATH"],
|
||||
"AJAX" => "Y",
|
||||
],
|
||||
[],
|
||||
static function (): array {
|
||||
global $APPLICATION;
|
||||
|
||||
return ["title" => (string)($APPLICATION->GetPageProperty("title") ?: $APPLICATION->GetTitle())];
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public function filterAction(string $section): ?array
|
||||
{
|
||||
$route = Listing::parsePath(Listing::sectionPath($section));
|
||||
if ($route === null) {
|
||||
$this->addError(new Error("Wrong section"));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
global $APPLICATION;
|
||||
ob_start();
|
||||
$result = $APPLICATION->IncludeComponent(
|
||||
"bitrix:catalog.smart.filter",
|
||||
"",
|
||||
Listing::filterParams($route["SECTION_CODE"], ""),
|
||||
null,
|
||||
[],
|
||||
true
|
||||
);
|
||||
ob_end_clean();
|
||||
|
||||
$disabled = [];
|
||||
foreach ((array)($result["ITEMS"] ?? []) as $item) {
|
||||
if (!empty($item["PRICE"])) {
|
||||
continue;
|
||||
}
|
||||
foreach ((array)($item["VALUES"] ?? []) as $value) {
|
||||
$disabled[$value["CONTROL_NAME"]] = !empty($value["DISABLED"]);
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"url" => (string)($result["JS_FILTER_PARAMS"]["SEF_SET_FILTER_URL"] ?? Listing::sectionPath($route["SECTION_CODE"])),
|
||||
"disabled" => $disabled,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user