Skip to content

Instantly share code, notes, and snippets.

@maximzasorin
Created November 23, 2015 15:01
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/9a00681cfe36c7fc8f1c to your computer and use it in GitHub Desktop.
Save maximzasorin/9a00681cfe36c7fc8f1c to your computer and use it in GitHub Desktop.
Наблюдатель, который скрывает модификации, отсутствующие на текущем складе (HostCMS)
<?php
/*
*
* В bootstrap.php:
*
// KAD: Скрываем модификации, которых нет в наличии на текущем складе
Core_Event::attach('shop_item.onBeforeShowXmlModifications', array('Shop_Item_Observers_Hidenotavailablemods', 'onBeforeShowXmlModifications'));
*
*/
defined('HOSTCMS') || exit('HostCMS: access denied.');
class Shop_Item_Observers_Hidenotavailablemods
{
static public function onBeforeShowXmlModifications($object, $args)
{
if (
(
defined('HIDE_NOT_AVAILABLE_MODS_SHOP_ID')
&&
HIDE_NOT_AVAILABLE_MODS_SHOP_ID == $object->shop_id
)
)
{
$oShop = Core_Entity::factory('Shop', HIDE_NOT_AVAILABLE_MODS_SHOP_ID);
$oCurrent_Warehouse = $oShop->Shop_Warehouses->getDefault();
$args[0]->queryBuilder()
->select('shop_items.*')
->leftJoin('shop_warehouse_items', 'shop_warehouse_items.shop_item_id', '=', 'shop_items.id', array(
array(
'AND' => array('shop_warehouse_items.shop_warehouse_id', '=', $oCurrent_Warehouse->id)
)
)
)
->where('shop_warehouse_items.count', '>', 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment