Created
February 22, 2018 08:46
-
-
Save alexsoin/8fae68f66fd786cf71b5159c10d06aee to your computer and use it in GitHub Desktop.
создание товара miniShop2 через процессор
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$response = $modx->runProcessor('resource/create', array( | |
'class_key' => 'msProduct', | |
'pagetitle' => 'Товар', | |
'parent' => 55, | |
'template' => 11, | |
'show_in_tree' => 1, | |
//Данные | |
'price' => 100, | |
'old_price' => 0, | |
'favorite' => 0, | |
'popular' => 0, | |
//стандартные опции товара | |
'color' => array('Синий', 'Красный'), | |
'size' => array('S', 'M'), | |
'tags' => array('Тег1', 'Тег2'), | |
//свои опции созданные в настройках | |
'options-КЛЮЧ_ОПЦИИ' => array('значение1', 'значение2'), | |
//TV - 10 это id TV | |
'tv10' => 'Значение' | |
)); |
выяснил, при вызове скрипта от гостя (к примеру в ncron) - нет доступа. Скрипт выполняется если только пользователь является админом. Заменил $modx->runProcessor('resource/create' на $modx->newObject('msProduct' все норм.
/** @var modX $modx */
/** @var modUser $user */
$user->addSessionContext('web');
if (!$user->isAuthenticated('mgr')) {
require_once MODX_BASE_PATH . 'config.core.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
/* instantiate the modX class with the appropriate configuration */
$modx = new modX();
/* initialize the proper context */
$modx->initialize($modx->context->key);
}
/** @var modProcessorResponse $response */
$response = $modx->runProcessor('resource/create', array(
//...
@R2m0x94 для чего это?
@alexsoin это для создания ресурса пользователем, не для контекстов mgr. Торопился, забыл описание добавить, да и подумал и так понятно, вдруг кому пригодится. Кстати конвертер классный, респект!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@charset200
не знаю, что у тебя не работает, у меня всё норм отрабатывает