Skip to content

Instantly share code, notes, and snippets.

@maximzasorin
Last active November 20, 2015 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maximzasorin/558b00284a7fd69ae8e0 to your computer and use it in GitHub Desktop.
Save maximzasorin/558b00284a7fd69ae8e0 to your computer and use it in GitHub Desktop.
Наблюдатель для запрета индексации модификаций товаров, которых нет в наличии (HostCMS)
<?php
/*
* В bootstrap.php:
*
// Запрет индексации модификаций и товаров, которых нет в наличии
Core_Event::attach('shop_item.onAfterSave', array('Shop_Item_Observers_Setindexing', 'onAfterSave'));
*
*/
defined('HOSTCMS') || exit('HostCMS: access denied.');
class Shop_Item_Observers_Setindexing
{
static public function onAfterSave($object, $args)
{
// Запрещаем индексацию модификаций и товаров, которых нет в наличии
if (
($object->getRest() == 0 || $object->modification_id != 0)
&&
$object->indexing == 1
)
{
$object->indexing = 0;
$object->save();
}
// Разрешаем индексацию немодификаций, которые есть в наличии
else if (
($object->getRest() > 0 && $object->modification_id == 0)
&&
$object->indexing == 0
)
{
$object->indexing = 1;
$object->save();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment