Index: branches/unlabeled/unlabeled-1.10.2/kernel/units/categories/categories_event_handler.php =================================================================== diff -u -N -r4381 -r4382 --- branches/unlabeled/unlabeled-1.10.2/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 4381) +++ branches/unlabeled/unlabeled-1.10.2/kernel/units/categories/categories_event_handler.php (.../categories_event_handler.php) (revision 4382) @@ -8,23 +8,23 @@ * @param kEvent $event */ function OnCategoryUp(&$event) - { + { $category_table = $this->Application->getUnitOption($event->Prefix,'TableName'); $current_cat = $this->Application->GetVar('m_cat_id'); - + if($current_cat) { $sql = 'SELECT ParentId FROM '.$category_table.' WHERE CategoryId = '.$current_cat; $cat_to_go = $this->Conn->GetOne($sql); } - else + else { $cat_to_go = 0; } - + $event->redirect_params = Array('m_cat_id' => $cat_to_go); } - + /** * Goes to home category * @@ -35,7 +35,7 @@ $cat_to_go = 0; $event->redirect_params = Array('m_cat_id' => $cat_to_go); } - + /** * Apply system filter to categories list * @@ -44,16 +44,23 @@ function SetCustomQuery(&$event) { parent::SetCustomQuery($event); - + $types=$event->getEventParam('types'); $except_types=$event->getEventParam('except'); $object =& $event->getObject(); $type_clauses = Array(); - + $object =& $event->getObject(); - + if ( $event->getEventParam('parent_cat_id') ) { $parent_cat_id = $event->getEventParam('parent_cat_id'); + + if ($parent_cat_id == 'Root') { + $module_name = getArrayValue($params, 'module') ? $params['module'] : 'In-Commerce'; + $module =& $this->Application->recallObject('mod.'.$module_name); + $parent_cat_id = $module->GetDBField('RootCat'); + } + } else { $parent_cat_id = $this->Application->GetVar('c_id'); @@ -64,7 +71,7 @@ $parent_cat_id = 0; } } - + if ($parent_cat_id != 'any') { if ($event->getEventParam('recursive')) { $current_path = $this->Conn->GetOne('SELECT ParentPath FROM '.TABLE_PREFIX.'Category WHERE CategoryId='.$parent_cat_id); @@ -75,9 +82,9 @@ $object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id); } } - + $object->addFilter('parent_filter', 'ParentId = '.$parent_cat_id); - + $view_perm = 1; $object->addFilter('perm_filter', 'PermId = '.$view_perm); if ( !$this->Application->IsAdmin() ) @@ -98,7 +105,7 @@ SELECT ResourceId FROM '.$this->Application->getUnitOption($event->Prefix, 'TableName').' WHERE CategoryId = '.$parent_cat_id ); - + $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship WHERE SourceId = '.$resource_id.' AND SourceType = 1'; $related_cats = $this->Conn->GetCol($sql); @@ -108,30 +115,30 @@ $related_cats2 = $this->Conn->GetCol($sql); $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array(); $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) ); - + if($related_cats) { $type_clauses['category_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')'; $type_clauses['category_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')'; } - else + else { $type_clauses['category_related']['include'] = '0'; $type_clauses['category_related']['except'] = '1'; } $type_clauses['category_related']['having_filter'] = false; } - + if(strpos($types, 'product_related') !== false) { $object->removeFilter('parent_filter'); - + $product_id = $event->getEventParam('product_id') ? $event->getEventParam('product_id') : $this->Application->GetVar('p_id'); $resource_id = $this->Conn->GetOne(' SELECT ResourceId FROM '.$this->Application->getUnitOption('p', 'TableName').' WHERE ProductId = '.$product_id ); - + $sql = 'SELECT DISTINCT(TargetId) FROM '.TABLE_PREFIX.'Relationship WHERE SourceId = '.$resource_id.' AND TargetType = 1'; $related_cats = $this->Conn->GetCol($sql); @@ -141,36 +148,36 @@ $related_cats2 = $this->Conn->GetCol($sql); $related_cats2 = is_array($related_cats2) ? $related_cats2 : Array(); $related_cats = array_unique( array_merge( $related_cats2, $related_cats ) ); - + if($related_cats) { $type_clauses['product_related']['include'] = '%1$s.ResourceId IN ('.implode(',', $related_cats).')'; $type_clauses['product_related']['except'] = '%1$s.ResourceId NOT IN ('.implode(',', $related_cats).')'; } - else + else { $type_clauses['product_related']['include'] = '0'; $type_clauses['product_related']['except'] = '1'; } $type_clauses['product_related']['having_filter'] = false; } - + /********************************************/ - + $includes_or_filter =& $this->Application->makeClass('kMultipleFilter'); $includes_or_filter->setType(FLT_TYPE_OR); - + $excepts_and_filter =& $this->Application->makeClass('kMultipleFilter'); $excepts_and_filter->setType(FLT_TYPE_AND); $includes_or_filter_h =& $this->Application->makeClass('kMultipleFilter'); $includes_or_filter_h->setType(FLT_TYPE_OR); - + $excepts_and_filter_h =& $this->Application->makeClass('kMultipleFilter'); $excepts_and_filter_h->setType(FLT_TYPE_AND); $except_types_array=explode(',', $types); - + if ($types){ $types_array=explode(',', $types); for ($i=0; $iaddFilter('includes_filter', $includes_or_filter); $object->addFilter('excepts_filter', $excepts_and_filter); - + $object->addFilter('includes_filter_h', $includes_or_filter_h, HAVING_FILTER); $object->addFilter('excepts_filter_h', $excepts_and_filter_h, HAVING_FILTER); } - + function GetPassedId(&$event) { if ( $this->Application->IsAdmin() ) return parent::getPassedID($event); - + $ret = $this->Application->GetVar('m_cat_id'); if($ret) return $ret; - + return parent::getPassedID($event); } - + /** * Rebuilds category cache * @@ -230,7 +237,7 @@ $this->Application->StoreVar('PermCache_UpdateRequired', 1); $event->SetRedirectParam('index_file', 'category/category_maint.php'); } - + /** * Adds calculates fields for item statuses * @@ -240,14 +247,14 @@ function prepareObject(&$object, &$event) { $object =& $event->getObject( Array('skip_autoload' => true) ); - + $object->addCalculatedField('IsNew', ' IF(%1$s.NewItem = 2, IF(%1$s.CreatedOn >= (UNIX_TIMESTAMP() - '. $this->Application->ConfigValue('Category_DaysNew'). '*3600*24), 1, 0), %1$s.NewItem )'); - + } }