Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
msOptionsColor
<?php
/** @var modX $modx */
/** @var array $scriptProperties */
switch ($modx->event->name) {
case 'OnDocFormSave':
/*
id ресурса откуда копируем
ключ опции которую копируем
*/
$rid = 11984;
$key = 'memory';
$mode = $modx->getOption('mode', $scriptProperties);
$resource = $modx->getOption('resource', $scriptProperties);
if ($mode != modSystemEvent::MODE_NEW) {
return;
}
$fqn = $modx->getOption('msoptionscolor_class', null, 'msoptionscolor.msoptionscolor', true);
$path = $modx->getOption('msoptionscolor_core_path', null,
$modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/msoptionscolor/');
$msoptionscolor = $modx->getService(
$fqn,
'',
$path . 'model/',
array('core_path' => $path)
);
if (!$msoptionscolor) {
return;
}
$msoptionscolor->initialize($modx->context->key);
if (!$msoptionscolor->isWorkingClassKey($resource)
OR
!$msoptionscolor->isWorkingTemplates($resource)
) {
return;
}
$class = 'msocColor';
$q = $modx->newQuery($class);
$q->where(array('rid' => $rid, 'key' => $key));
/** @var xPDOObject|$color */
foreach ($modx->getIterator($class, $q) as $color) {
$msoptionscolor->setProductOptions($resource->get('id'), array($key => $color->get('value')));
/** @var xPDOObject $o */
$o = $modx->newObject($class);
$o->fromArray($color->toArray(), '', true);
$o->set('rid', $resource->get('id'));
$o->save();
}
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment