Skip to content

Commit 8721f0a

Browse files
committed
Add category filter for YML extended
1 parent fc8e90d commit 8721f0a

File tree

6 files changed

+85
-17
lines changed

6 files changed

+85
-17
lines changed

classes/Rees46/Component/YmlRendererExtended.php

+24-15
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,33 @@ private function getInfoBlock()
171171

172172
private function getCategories()
173173
{
174-
if ( $this->info_block ):
175-
$filter = [
176-
'IBLOCK_ID' => (int) $this->info_block,
177-
'ACTIVE' => 'Y',
178-
'IBLOCK_ACTIVE' => 'Y',
179-
'GLOBAL_ACTIVE' => 'Y'
180-
];
181-
$db_acc = CIBlockSection::GetList(['left_margin'=>'asc'], $filter);
182-
while ($arAcc = $db_acc->GetNext()):
174+
if (Options::getCategories()[0] || $this->info_block) {
175+
if (Options::getCategories()[0]) {
176+
$filter = [
177+
'ID' => unserialize(Options::getCategories()[0]),
178+
'ACTIVE' => 'Y',
179+
'IBLOCK_ACTIVE' => 'Y',
180+
'GLOBAL_ACTIVE' => 'Y'
181+
];
182+
} else if ($this->info_block) {
183+
$filter = [
184+
'IBLOCK_ID' => (int)$this->info_block,
185+
'ACTIVE' => 'Y',
186+
'IBLOCK_ACTIVE' => 'Y',
187+
'GLOBAL_ACTIVE' => 'Y'
188+
];
189+
}
190+
191+
$db_acc = CIBlockSection::GetList(['left_margin' => 'asc'], $filter);
192+
while ($arAcc = $db_acc->GetNext()) {
183193
$this->categories[] = [
184-
'id' => $arAcc['ID'],
194+
'id' => $arAcc['ID'],
185195
'parent_id' => intval($arAcc['IBLOCK_SECTION_ID']) > 0 ? $arAcc['IBLOCK_SECTION_ID'] : null,
186-
'name' => iconv(SITE_CHARSET,'utf-8',$arAcc['NAME']),
187-
'url' => $this->serverOrigin . (!empty($arAcc['~SECTION_PAGE_URL']) ? $arAcc['~SECTION_PAGE_URL'] : (!empty($arAcc['SECTION_PAGE_URL']) ? $arAcc['SECTION_PAGE_URL'] : ''))
196+
'name' => iconv(SITE_CHARSET, 'utf-8', $arAcc['NAME']),
197+
'url' => $this->serverOrigin . (!empty($arAcc['~SECTION_PAGE_URL']) ? $arAcc['~SECTION_PAGE_URL'] : (!empty($arAcc['SECTION_PAGE_URL']) ? $arAcc['SECTION_PAGE_URL'] : ''))
188198
];
189-
endwhile;
190-
endif;
199+
}
200+
}
191201
}
192202

193203
private function getOffers()
@@ -714,7 +724,6 @@ class REES46YMLExtendedExport
714724
protected string $_file;
715725
protected string $_tmpFile;
716726
protected $_engine;
717-
718727
public array $shopInfo = [
719728
'name' => '',
720729
'company' => '',

classes/Rees46/Options.php

+4
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ public static function getProperties()
5151
{
5252
return explode(',', Option::get(\mk_rees46::MODULE_ID, 'properties'));
5353
}
54+
55+
public static function getCategories() {
56+
return explode(',', Option::get(\mk_rees46::MODULE_ID, 'categories'));
57+
}
5458
}

install/version.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22
$arModuleVersion = array(
3-
'VERSION' => '3.4.11',
4-
'VERSION_DATE' => '2024-06-06 12:00:00',
3+
'VERSION' => '3.5.0',
4+
'VERSION_DATE' => '2024-06-11 12:00:00',
55
);

options.php

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@
5959
else:
6060
Option::set(mk_rees46::MODULE_ID, 'properties', null);
6161
endif;
62+
if (isset($_REQUEST['categories'])):
63+
Option::set(mk_rees46::MODULE_ID, 'categories', serialize($_REQUEST['categories']));
64+
else:
65+
Option::set(mk_rees46::MODULE_ID, 'categories', null);
66+
endif;
6267
endif;
6368

6469
$export_state = Export::STATUS_NOT_PERFORMED;

options/form.php

+47
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,32 @@
4040
$selected_product_info_block = Options::getProductInfoBlock();
4141
$selected_offer_info_block = Options::getOfferInfoBlock();
4242

43+
// Список категорий
44+
$categories = [];
45+
if ($selected_product_info_block):
46+
foreach ( $info_blocks as $block ):
47+
if (
48+
$block['id'] == $selected_product_info_block
49+
) {
50+
$filter = [
51+
'IBLOCK_ID' => (int) $block['id'],
52+
'ACTIVE' => 'Y',
53+
'IBLOCK_ACTIVE' => 'Y',
54+
'GLOBAL_ACTIVE' => 'Y'
55+
];
56+
$db_acc = CIBlockSection::GetList(['left_margin'=>'asc'], $filter);
57+
while ($arAcc = $db_acc->GetNext()):
58+
$categories[] = [
59+
'id' => $arAcc['ID'],
60+
'parent_id' => intval($arAcc['IBLOCK_SECTION_ID']) > 0 ? $arAcc['IBLOCK_SECTION_ID'] : null,
61+
'name' => iconv(SITE_CHARSET,'utf-8',$arAcc['NAME']),
62+
];
63+
endwhile;
64+
}
65+
endforeach;
66+
endif;
67+
$categories_selected = (Options::getCategories()[0]) ? unserialize(Options::getCategories()[0]) : [];
68+
4369
// Список свойств и параметров
4470
$properties = [];
4571
$params_properties = [];
@@ -302,6 +328,27 @@
302328
</td>
303329
</tr>
304330
<?php if ($selected_product_info_block): ?>
331+
<tr class="heading">
332+
<td colspan="2"><b>Список категорий</b></td>
333+
</tr>
334+
<tr class="bx-in-group">
335+
<td class="adm-detail-valign-top adm-detail-content-cell-l"
336+
style="width: 40%"><?= GetMessage('REES_OPTIONS_YML_EXTENDED_CATEGORIES') ?></td>
337+
<td class="adm-detail-content-cell-r"
338+
style="width: 60%">
339+
<?php foreach ($categories as $category): ?>
340+
<label <?php if ($category['parent_id']) {?>style="margin-left: 15px"<?php } ?>>
341+
<input type="checkbox" id="user_group_category_<?=$category['id'];?>"
342+
value="<?=$category['id'];?>"
343+
<?php if (in_array($category['id'], $categories_selected)): ?>
344+
checked="checked"
345+
<?php endif; ?>
346+
name="categories[]" style="margin: 0 5px 0 0"/>
347+
<span><?=$category['name'];?></span>
348+
</label><br>
349+
<?php endforeach; ?>
350+
</td>
351+
</tr>
305352
<tr class="heading">
306353
<td colspan="2"><b>Список свойств</b></td>
307354
</tr>

update/3.5.0/description.ru

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<ul>
2+
<li>Добавлена возможность указать категории для генерации расширенного товарного фида</li>
3+
</ul>

0 commit comments

Comments
 (0)