Exemplo n.º 1
0
 private function _getProducts(array $params)
 {
     $searchTxt = trim(isset($params['searchTxt']) ? $params['searchTxt'] : '');
     if ($searchTxt === '') {
         throw new Exception('SearchTxt is needed');
     }
     $pageSize = isset($params['pageSize']) && ($pageSize = trim($params['pageSize'])) !== '' ? $pageSize : DaoQuery::DEFAUTL_PAGE_SIZE;
     $pageNo = isset($params['pageNo']) && ($pageNo = trim($params['pageNo'])) !== '' ? $pageNo : null;
     $orderBy = isset($params['orderBy']) ? $params['orderBy'] : array();
     $isKit = isset($params['isKit']) ? $params['isKit'] === true : null;
     $sqlParams = array('searchTxtExact' => $searchTxt);
     $searchTokens = array();
     StringUtilsAbstract::permute(preg_split("/[\\s,]+/", trim($searchTxt)), $searchTokens);
     $nameLikeArray = $skuLikeArray = array();
     foreach ($searchTokens as $index => $tokenArray) {
         $key = 'token' . $index;
         $sqlParams[$key] = '%' . implode('%', $tokenArray) . '%';
         $nameLikeArray[] = 'name like :' . $key;
         $skuLikeArray[] = 'sku like :' . $key;
     }
     $where = array('mageId = :searchTxtExact OR (' . implode(' OR ', $nameLikeArray) . ') OR (' . implode(' OR ', $skuLikeArray) . ')');
     $stats = array();
     $items = Product::getAllByCriteria(implode(' AND ', $where), $sqlParams, true, $pageNo, $pageSize, $orderBy, $stats);
     $results = array();
     $results['items'] = array_map(create_function('$a', 'return $a->getJson();'), $items);
     $results['pagination'] = $stats;
     $results['pageStats'] = $stats;
     return $results;
 }