Skip to content

Instantly share code, notes, and snippets.

@vgrish
Last active May 19, 2018 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vgrish/85b5d8e9e3a159975b330cc90d63f3ca to your computer and use it in GitHub Desktop.
Save vgrish/85b5d8e9e3a159975b330cc90d63f3ca to your computer and use it in GitHub Desktop.
<?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
Copy link
Author

vgrish commented May 19, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment