Advertisement
NFL

Untitled

NFL
Dec 23rd, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.45 KB | None | 0 0
  1. public function getCategory($id, $all = false) {
  2.  
  3.         if (!is_numeric($id)) {
  4.             //Определение ID категории...
  5.         }
  6.  
  7.         if ($all) {
  8.            
  9.         } else {
  10.             //$field = is_numeric($id)?'data_id':'alias';    
  11.             $moduleId = $this->getModuleId();
  12.             $list = $this->getAdapter()
  13.                             ->select()
  14.                             ->from(array('p' => $this->_name))
  15.                             ->where("p.category_id = ?", $id)
  16.                             ->joinLeft(array('m'=>'system_meta'), "m.data_id = p.data_id AND m.module_id=$moduleId")
  17.                             ->group('p.data_id')
  18.                             ->query()->fetchAll();
  19.             //Докрутить постраничку...
  20.             $idsList = array(); //Список ID выбранных продуктов, для дальнейшей обработки
  21.             array_walk($list, create_function('$k, $v, &$idsList', '$idsList[] = $k["data_id"];'), &$idsList);
  22.             $list = array_combine($idsList, $list); //Подготовили массив продуктов для дальнейшей обработки...
  23.            
  24.             /**
  25.              * Выбираем характеристики...
  26.              */
  27.             $model = new Catalog_Model_Products_Properties;
  28.             $properties = $this->getAdapter()
  29.                     ->select()
  30.                     ->from(array('pp'=>$model->getTableName()))
  31.                     ->where('product_id IN (?)', $idsList)
  32.                     ->joinLeft(array('cp'=>'catalog_properties'), 'cp.id=pp.property_id', array('property_title'=>'title', 'type'))
  33.                     ->query()->fetchAll();
  34.             //Подготавливаем характеристики...
  35.             $preparedProperties = array();
  36.             foreach($properties as $v) {
  37.                 $preparedProperties[$v['product_id']]['properties'][$v['property_id']]['title'] = $v['property_title'];
  38.                 $preparedProperties[$v['product_id']]['properties'][$v['property_id']]['type'] = $v['type'];
  39.                 $preparedProperties[$v['product_id']]['properties'][$v['property_id']]['values'][] = $v['value'];
  40.             }
  41.             foreach($list as $i=>&$v) {
  42.                 $v['properties'] = $preparedProperties[$i]['properties'];
  43.             }
  44.            
  45.            
  46.             Zend_Debug::dump($list);
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement