Skip to content

Instantly share code, notes, and snippets.

@maximzasorin
Last active November 23, 2015 14:59
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/60566925d19de4b37ff4 to your computer and use it in GitHub Desktop.
Save maximzasorin/60566925d19de4b37ff4 to your computer and use it in GitHub Desktop.
Наблюдатель, который скрывает товары, отсутствующие на текущем складе (HostCMS)
<?php
/*
*
* В bootstrap.php:
*
// Скрываем товары, которых нет в наличии на текущем складе
Core_Event::attach('Shop_Controller_Show.onBeforeRedeclaredShow', array('Shop_Item_Observers_Hidenotavailableitems', 'onBeforeRedeclaredShow'));
*
*/
defined('HOSTCMS') || exit('HostCMS: access denied.');
class Shop_Item_Observers_Hidenotavailableitems
{
static public function onBeforeRedeclaredShow($object, $args)
{
if (
(
defined('HIDE_NOT_ABAILABLE_ITEMS_SHOP_ID')
&&
HIDE_NOT_ABAILABLE_ITEMS_SHOP_ID == $object->getEntity()->id
)
&&
!$object->item
)
{
$oShop = Core_Entity::factory('Shop', HIDE_NOT_ABAILABLE_ITEMS_SHOP_ID);
$oCurrent_Warehouse = $oShop->Shop_Warehouses->getDefault();
$object->shopItems()
->queryBuilder()
->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