Last active
November 23, 2015 14:59
-
-
Save maximzasorin/60566925d19de4b37ff4 to your computer and use it in GitHub Desktop.
Наблюдатель, который скрывает товары, отсутствующие на текущем складе (HostCMS)
This file contains 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 characters
<?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