Created
March 26, 2017 07:32
-
-
Save vgrish/9f5377eef8d7c72f87a4b625f3e1729a 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 | |
if ($modx->event->name != 'msopOnModificationSave') { | |
return; | |
} | |
$modification = $modx->getOption('modification', $scriptProperties); | |
if (!$modification) { | |
return; | |
} | |
/** @var msProduct $product */ | |
$product = $modification->getOne('Product'); | |
if (!$product) { | |
return; | |
} | |
$sklad = trim($product->getTVValue('sklad')); | |
if (!in_array($sklad, array('', 'магазин'))) { | |
return; | |
} | |
$count = 0; | |
$q = $modx->newQuery('msopModification'); | |
$q->where(array( | |
'rid' => $product->get('id'), | |
'type' => 1, | |
'active' => 1, | |
'count:>' => 0, | |
)); | |
$q->select('SUM(count)'); | |
if ($stmt = $q->prepare()) { | |
$count = (int)$modx->getValue($stmt); | |
} | |
if (empty($count)) { | |
$product->setTVValue('ostatki', $count); | |
$product->setTVValue('sklad', 'нет в наличии'); | |
} else { | |
$product->setTVValue('ostatki', $count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment