Skip to content

Instantly share code, notes, and snippets.

@modExpert
Last active November 8, 2024 01:13
Show Gist options
  • Save modExpert/83dd715c081a296b7fab1ba0a4490cb2 to your computer and use it in GitHub Desktop.
Save modExpert/83dd715c081a296b7fab1ba0a4490cb2 to your computer and use it in GitHub Desktop.
<?php
/*
* Кусок кода для добавления товара, чтобы пути были вида product/alias
*/
// Создание товара
$resource = $modx->newObject('msProduct');
// Название
$resource->set('pagetitle', 'Товар №1');
// Генерация алиаса из имени
$resource->set('alias', $resource->cleanAlias('Товар №1'));
// Родитель куда поместить товар
$resource->set('parent', 1);
// Заморозить URL
$product->set('uri_override', 1);
// Контент в ресурсе
$resource->set('content', 'Описание');
// Класс ресурса
$resource->set('class_key', 'msProduct');
// Опубликован
$resource->set('published', 1);
// ID шаблона товара
$resource->set('template', $modx->getOption('ms2_template_product_default'));
// Показывать в дереве ресурсов
$resource->set('show_in_tree', 0);
// Не показывать в меню
$resource->set('hidemenu', 1);
// Доступен для поиска
$resource->set('searchable', 1);
// Сохраняем всё
$resource->save();
// Добавляем в TV поля если нужно
$resource->setTVValue('custom', 'TV поле');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment