|
<?php |
|
/** |
|
* @var array $scriptProperties |
|
*/ |
|
if (!function_exists('unpublishProduct')) { |
|
function unpublishProduct($modx, $id) |
|
{ |
|
if (empty($modx->error)) { |
|
$modx->getService('error', 'modError'); |
|
} else { |
|
$modx->error->reset(); |
|
} |
|
/** |
|
* @var modProcessorResponse $response |
|
*/ |
|
$response = $modx->runProcessor('resource/unpublish', array( |
|
'id' => $id, |
|
), array( |
|
'processors_path' => $modx->getOption('product_unpublish.core_path', null, $modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/product_unpublish/') . 'processors/', |
|
)); |
|
if ($response->isError()) { |
|
$modx->log(modX::LOG_LEVEL_ERROR, 'Error occurred while unpublishing the resource with ID ' . $id . ': ' . $response->getMessage()); |
|
} |
|
} |
|
} |
|
switch ($modx->event->name) { |
|
case 'msOnCreateOrder': |
|
$order = $modx->getOption('msOrder', $scriptProperties); |
|
if (!is_object($order)) { |
|
return; |
|
} |
|
foreach ($order->getMany('Products') as $orderProduct) { |
|
unpublishProduct($modx, $orderProduct->get('product_id')); |
|
} |
|
break; |
|
case 'msOnChangeOrderStatus': |
|
if ($modx->getOption('status', $scriptProperties) != 99) { |
|
return; |
|
} |
|
$order = $modx->getOption('order', $scriptProperties); |
|
if (!is_object($order)) { |
|
return; |
|
} |
|
foreach ($order->getMany('Products') as $orderProduct) { |
|
unpublishProduct($modx, $orderProduct->get('product_id')); |
|
} |
|
break; |
|
} |
|
if (!empty($modx->error)) { |
|
$modx->error->reset(); |
|
} |