Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс

This commit is contained in:
jimagie committed 2026-10-22 03:32:28 +05:00
commit f6ba0d2174
470 files changed
+26454

No files matched your search

@@ -0,0 +1,220 @@
<?php
use Bitrix\Iblock\Component\Tools;
use Bitrix\Main\Application;
use Bitrix\Main\Localization\Loc;
use Jinove\Vinoteca\Catalog\Countries;
use Jinove\Vinoteca\Catalog\EnumNames;
use Jinove\Vinoteca\Catalog\Listing;
use Jinove\Vinoteca\Catalog\PricePresets;
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die();
}
Loc::loadMessages(__FILE__);
class JinoveCatalogListingComponent extends CBitrixComponent
{
public function onPrepareComponentParams($params): array
{
$request = Application::getInstance()->getContext()->getRequest();
$sort = (string)$request->getQuery("sort");
$params["SECTION_CODE"] = (string)($params["SECTION_CODE"] ?? "");
$params["FILTER_PATH"] = (string)($params["FILTER_PATH"] ?? "");
$params["COUNTRY_CODE"] = (string)($params["COUNTRY_CODE"] ?? "");
$params["SORT"] = in_array($sort, Listing::SORTS, true) ? $sort : "";
$params["PAGE"] = max(1, (int)$request->getQuery("PAGEN_1"));
$params["VIEW"] = $request->getCookieRaw("vino_view") === "list" ? "list" : "grid";
$params["AJAX"] = ($params["AJAX"] ?? "") === "Y" ? "Y" : "N";
return $params;
}
public function executeComponent(): array
{
if ($this->arParams["COUNTRY_CODE"] !== "") {
return $this->executeCountry();
}
$catalog = Listing::catalogParams();
$sectionCode = $this->arParams["SECTION_CODE"];
$filterPath = $this->arParams["FILTER_PATH"];
$sort = $this->arParams["SORT"];
$basePath = Listing::basePath($sectionCode, $filterPath);
$priceCode = (string)(reset($catalog["PRICE_CODE"]) ?: "");
$this->arResult = [
"SECTION_CODE" => $sectionCode,
"FILTER_PARAMS" => Listing::filterParams($sectionCode, $filterPath),
"SECTION_PARAMS" => $this->sectionParams($catalog, $basePath, $priceCode),
];
$this->includeComponentTemplate();
return $this->arResult;
}
private function executeCountry(): array
{
$code = $this->arParams["COUNTRY_CODE"];
$countries = Countries::names();
if (!isset($countries[$code])) {
Tools::process404("", true, true, true);
return [];
}
$name = EnumNames::name("COUNTRY", $code, $countries[$code]);
$GLOBALS["wineFilter"] = ["PROPERTY_COUNTRY_VALUE" => $countries[$code]];
global $APPLICATION;
$APPLICATION->SetTitle($name);
$APPLICATION->SetPageProperty("title", Loc::getMessage("VINO_LISTING_COUNTRY_TITLE", ["#COUNTRY#" => $name]));
$APPLICATION->SetPageProperty("description", Loc::getMessage("VINO_LISTING_COUNTRY_DESCRIPTION", ["#COUNTRY#" => $name]));
$path = Listing::countryPath($code);
$APPLICATION->SetPageProperty("vino_canonical", $this->arParams["PAGE"] > 1 ? $path . "?PAGEN_1=" . $this->arParams["PAGE"] : $path);
$APPLICATION->SetPageProperty("og_image", VINO_HOST . SITE_TEMPLATE_PATH . "/assets/media/og-catalog.jpg");
$catalog = Listing::catalogParams();
$this->arResult = [
"COUNTRY_NAME" => $name,
"SECTION_PARAMS" => [
"IBLOCK_TYPE" => $catalog["IBLOCK_TYPE"],
"IBLOCK_ID" => $catalog["IBLOCK_ID"],
"SECTION_ID" => 0,
"FILTER_NAME" => "wineFilter",
"PRICE_CODE" => $catalog["PRICE_CODE"],
"BASKET_URL" => $catalog["BASKET_URL"],
"PAGE_ELEMENT_COUNT" => "24",
"LINE_ELEMENT_COUNT" => "3",
"INCLUDE_SUBSECTIONS" => "Y",
"ELEMENT_SORT_FIELD" => "SORT",
"ELEMENT_SORT_ORDER" => "ASC",
"ELEMENT_SORT_FIELD2" => "ID",
"ELEMENT_SORT_ORDER2" => "DESC",
"PROPERTY_CODE" => $catalog["LIST_PROPERTY_CODE"],
"CACHE_TYPE" => $catalog["CACHE_TYPE"],
"CACHE_TIME" => $catalog["CACHE_TIME"],
"CACHE_GROUPS" => $catalog["CACHE_GROUPS"],
"SET_TITLE" => "N",
"SET_BROWSER_TITLE" => "N",
"SET_META_KEYWORDS" => "N",
"SET_META_DESCRIPTION" => "N",
"SET_STATUS_404" => "N",
"ADD_SECTIONS_CHAIN" => "N",
"ACTION_VARIABLE" => $catalog["ACTION_VARIABLE"],
"PRODUCT_ID_VARIABLE" => $catalog["PRODUCT_ID_VARIABLE"],
"USE_PRODUCT_QUANTITY" => "Y",
"ADD_TO_BASKET_ACTION" => "ADD",
"DISPLAY_TOP_PAGER" => "N",
"DISPLAY_BOTTOM_PAGER" => "Y",
"PAGER_TEMPLATE" => "vinoteca",
"PAGER_SHOW_ALWAYS" => "N",
"PAGER_TITLE" => Loc::getMessage("VINO_LISTING_PAGER_TITLE"),
"VINO_TITLE_TAG" => "h2",
"SECTION_URL" => $catalog["SEF_FOLDER"] . $catalog["SEF_URL_TEMPLATES"]["section"],
"HIDE_NOT_AVAILABLE" => "N",
],
];
$this->includeComponentTemplate("country");
return $this->arResult;
}
private function sectionParams(array $catalog, string $basePath, string $priceCode): array
{
$sectionCode = $this->arParams["SECTION_CODE"];
$filterPath = $this->arParams["FILTER_PATH"];
$sort = $this->arParams["SORT"];
$ajax = $this->arParams["AJAX"] === "Y";
$priceField = "CATALOG_PRICE_" . PricePresets::groupId($priceCode);
$sorts = [
"new" => ["ID", "DESC"],
"price_asc" => [$priceField, "ASC"],
"price_desc" => [$priceField, "DESC"],
"name" => ["NAME", "ASC"],
];
$sortUrls = ["" => $basePath];
foreach (array_keys($sorts) as $code) {
$sortUrls[$code] = $basePath . "?sort=" . $code;
}
$pagePath = Listing::pagePath($sectionCode, $filterPath, $sort, $this->arParams["PAGE"]);
return [
"IBLOCK_TYPE" => $catalog["IBLOCK_TYPE"],
"IBLOCK_ID" => $catalog["IBLOCK_ID"],
"SECTION_CODE" => $sectionCode,
"FILTER_NAME" => "wineFilter",
"PRICE_CODE" => $catalog["PRICE_CODE"],
"BASKET_URL" => $catalog["BASKET_URL"],
"PAGE_ELEMENT_COUNT" => "12",
"LINE_ELEMENT_COUNT" => "3",
"INCLUDE_SUBSECTIONS" => "Y",
"ELEMENT_SORT_FIELD" => $sort !== "" ? $sorts[$sort][0] : "SORT",
"ELEMENT_SORT_ORDER" => $sort !== "" ? $sorts[$sort][1] : "ASC",
"ELEMENT_SORT_FIELD2" => "ID",
"ELEMENT_SORT_ORDER2" => "DESC",
"PROPERTY_CODE" => $catalog["LIST_PROPERTY_CODE"],
"CACHE_TYPE" => $catalog["CACHE_TYPE"],
"CACHE_TIME" => $catalog["CACHE_TIME"],
"CACHE_GROUPS" => $catalog["CACHE_GROUPS"],
"SET_TITLE" => "N",
"SET_BROWSER_TITLE" => "N",
"SET_META_KEYWORDS" => "N",
"SET_META_DESCRIPTION" => "N",
"SET_STATUS_404" => $ajax ? "N" : $catalog["SET_STATUS_404"],
"SHOW_404" => $ajax ? "N" : $catalog["SHOW_404"],
"FILE_404" => $catalog["FILE_404"],
"MESSAGE_404" => $catalog["MESSAGE_404"],
"ADD_SECTIONS_CHAIN" => "N",
"ACTION_VARIABLE" => $catalog["ACTION_VARIABLE"],
"PRODUCT_ID_VARIABLE" => $catalog["PRODUCT_ID_VARIABLE"],
"USE_PRODUCT_QUANTITY" => "Y",
"ADD_TO_BASKET_ACTION" => "ADD",
"SHOW_OLD_PRICE" => "Y",
"SHOW_DISCOUNT_PERCENT" => "Y",
"PRODUCT_DISPLAY_MODE" => "Y",
"DISPLAY_TOP_PAGER" => "N",
"DISPLAY_BOTTOM_PAGER" => "Y",
"PAGER_TEMPLATE" => "vinoteca",
"PAGER_SHOW_ALWAYS" => "N",
"PAGER_TITLE" => Loc::getMessage("VINO_LISTING_PAGER_TITLE"),
"PAGER_BASE_LINK_ENABLE" => "Y",
"PAGER_BASE_LINK" => $sortUrls[$sort],
"SECTION_URL" => $catalog["SEF_FOLDER"] . $catalog["SEF_URL_TEMPLATES"]["section"],
"DETAIL_URL" => $catalog["SEF_FOLDER"] . $catalog["SEF_URL_TEMPLATES"]["element"],
"HIDE_NOT_AVAILABLE" => "N",
"TEMPLATE_THEME" => "",
"VINO_AJAX" => $ajax ? "Y" : "N",
"VINO_TOOLBAR" => "Y",
"VINO_SORT" => $sort,
"VINO_SORT_URLS" => $sortUrls,
"VINO_PRICE_PRESETS" => $this->pricePresets($priceCode),
"VINO_VIEW" => $this->arParams["VIEW"],
"VINO_LIST_ID" => VINO_HOST . $pagePath . "#items",
"VINO_TITLE_TAG" => "h2",
];
}
private function pricePresets(string $priceCode): array
{
if ($priceCode === "") {
return [];
}
$sectionCode = $this->arParams["SECTION_CODE"];
$filterPath = $this->arParams["FILTER_PATH"];
$sectionPath = Listing::sectionPath($sectionCode);
$presets = [];
foreach (PricePresets::limits(VINO_CATALOG_IBLOCK, $sectionCode, $priceCode) as $limit) {
$presetPath = "price-" . strtolower($priceCode) . "-to-" . $limit;
$active = $filterPath === $presetPath;
$presets[] = [
"LIMIT" => $limit,
"URL" => $active ? $sectionPath : $sectionPath . "filter/" . $presetPath . "/apply/",
"ACTIVE" => $active,
];
}
if ($filterPath !== "" && !in_array(true, array_column($presets, "ACTIVE"), true)) {
return [];
}
return $presets;
}
}