<?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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
создать плагин с данным кодом. Назначить два события * OnDocFormSave* и * msopOnModificationSave*