This shows you the differences between two versions of the page.
koding:hostcms:shop:poluchenie_kolichestva_modifikacij_tovarov [06.05.15 в 18:36] Артем Куц создано |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <code><?php | ||
- | defined('HOSTCMS') || exit('HostCMS: access denied.'); | ||
- | |||
- | /** | ||
- | * Получение количества модификаций товара | ||
- | * | ||
- | * @author KAD artem.kuts@gmail.com | ||
- | |||
- | Core_Event::attach('Shop_Item_Model.onBeforeGetXml', array('Kad_Shop_Item_Collectionobserver', 'onBeforeGetXml')); | ||
- | |||
- | * | ||
- | * Копирование и использование файлов модуля | ||
- | * в коммерческих целях ЗАПРЕЩЕНО | ||
- | * | ||
- | */ | ||
- | |||
- | class Kad_Shop_Observers_Collectionobserver | ||
- | { | ||
- | static public function onBeforeGetXml($object, $params) | ||
- | { | ||
- | $shop_item = $object; | ||
- | |||
- | $oCore_QueryBuilder_Select = Core_QueryBuilder::select(array('count(*)', 'result')) | ||
- | ->from('shop_items') | ||
- | ->where('modification_id', '=', $shop_item->id); | ||
- | $aRows = $oCore_QueryBuilder_Select->execute()->asAssoc()->result(); | ||
- | $count = $aRows[0]['result']; | ||
- | |||
- | $shop_item->addEntity( | ||
- | Core::factory('Core_Xml_Entity')->name('modifications_count')->value($count) | ||
- | ); | ||
- | } | ||
- | }</code> |