-
-
Save webinmd/11f05ba309315ce8bfeaafa4033dd309 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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(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