Skip to content

Instantly share code, notes, and snippets.

@yandexmarketforbitrix
Last active July 24, 2024 03:15
Show Gist options
  • Save yandexmarketforbitrix/e1e40662b03e62770556592ca9769e90 to your computer and use it in GitHub Desktop.
Save yandexmarketforbitrix/e1e40662b03e62770556592ca9769e90 to your computer and use it in GitHub Desktop.
Тег sets для модуля Яндекс.Маркета

Как настроить:

  1. Зарегистрируйте обработчик.
  2. Создайте прайс-лист ^1, на вкладке Общие настройки выберите новый Вид размещения.
  3. Добавьте Коллекцию ^3. Самое простое - выбрать Тип коллекции Разделы инфоблока.

Какие особенности на текущий момент:

  1. Тег sets размещен после offers.
  2. Множественное значение set-ids будет выгружено в виде отдельных тегов.

^1 - Маркет для продавцов - Подготовка прайс-листа - Прайс-листы

^2 - Маркет для продавцов - Подготовка прайс-листа - Коллекции

<?php
use Bitrix\Main;
require __DIR__ . '/webmasterformat.php';
$eventManager = Main\EventManager::getInstance();
$eventManager->addEventHandler('yandex.market', 'onExportXmlFormatBuildList', function() {
return new Main\EventResult(Main\EventResult::SUCCESS, [
'SERVICE' => 'myWebmaster',
'TYPE_LIST' => [
'myFormat' => \PhpInterface\YandexMarket\WebmasterFormat::class,
],
]);
});
<?php
namespace PhpInterface\YandexMarket;
use Bitrix\Main\Loader;
use Yandex\Market\Export\Xml;
if (!Loader::includeModule('yandex.market')) { return; }
class WebmasterFormat extends Xml\Format\YandexMarket\Simple
{
public function getRoot()
{
$root = parent::getRoot();
$shop = $root->getChild('shop');
if ($shop === null) { return $root; }
$collections = $shop->getChild('collections');
if ($collections === null) { return $root; }
$collections->extendParameters([
'id' => $collections->getId(),
'name' => 'sets',
]);
return $root;
}
public function getCollectionParentName()
{
return 'sets';
}
public function getCollection()
{
$collection = parent::getCollection();
$collection->extendParameters([
'id' => $collection->getId(),
'name' => 'set',
]);
return $collection;
}
public function getCollectionId()
{
$collection = parent::getCollectionId();
$collection->extendParameters([
'id' => $collection->getId(),
'name' => 'set-ids',
'multiple' => true,
]);
return $collection;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment