Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
switch ($modx->event->name) {
case 'msopOnModificationSave':
$modification = $modx->getOption('modification', $scriptProperties);
if (!$modification) {
return;
}
/** @var msProduct $product */
$product = $modification->getOne('Product');
if (!$product) {
return;
}
$modx->invokeEvent('OnDocFormSave', array(
'mode' => modSystemEvent::MODE_UPD,
'id' => $product->get('id'),
'resource' => &$product,
'reloadOnly' => false,
));
break;
case 'OnDocFormSave':
$product = $modx->getOption('resource', $scriptProperties);
if (!$product) {
return;
}
$price = $product->get('price');
$q = $modx->newQuery('msopModification');
$q->where(array(
'rid' => $product->get('id'),
'type' => 1,
'active' => 1,
));
$q->select('MAX(CAST(`price` AS DECIMAL(10,2))) as price');
if ($stmt = $q->prepare()) {
if ($value = $modx->getValue($stmt)) {
$price = $value;
}
}
$product->set('price', $price);
$product->save();
break;
}
@vgrish

This comment has been minimized.

Copy link
Owner Author

commented May 19, 2018

создать плагин с данным кодом. Назначить два события * OnDocFormSave* и * msopOnModificationSave*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.