Last active
August 14, 2018 15:36
Revisions
-
grachov revised this gist
May 22, 2014 . No changes.There are no files selected for viewing
-
grachov created this gist
Apr 30, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Установка: - файл `unpublish.class.php` разместить в директории `core/components/product_unpublish/processors/resource/` - создать плагин, скопировав содержимое файла `plugin.php`. Если необходимо снимать с публикации товары сразу после покупки, отмечаем для плагина событие `msOnCreateOrder`. Если необходимо снимать с публикации товары при получении заказом определенного статуса, необходимо отметить событие `msOnChangeOrderStatus` для плагина и поменять в коде `99` на ID статуса заказа. 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ <?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(); } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ <?php require_once MODX_CORE_PATH . 'model/modx/processors/resource/unpublish.class.php'; class CustomResourceUnPublishProcessor extends modResourceUnPublishProcessor { public function checkPermissions() { return true; } public function initialize() { $id = $this->getProperty('id', false); if (empty($id)) { return $this->modx->lexicon('resource_err_ns'); } $this->resource = $this->modx->getObject('modResource', $id); if (empty($this->resource)) { return $this->modx->lexicon('resource_err_nfs', array( 'id' => $id, )); } return true; } } return 'CustomResourceUnPublishProcessor';