Пример #1
0
 /**
  * Get list product by condition tolerances and weight of extra field
  *
  * @author MinhNV
  * Date 2010/08/18
  */
 private function getListProductByCondOfExtraField()
 {
     $cat_product_id = Url::get('cat_product_id', 0);
     $product_id = Url::get('product_id', 0);
     $cur_page = Url::get('page_no', 0);
     $table = CGlobal::TABLE_PRODUCTS_PRODUCT;
     $aryExtraField = array();
     $aryExtraProduct = array();
     $aryProduct = array();
     $aryData = array();
     $query = '';
     $fq = array();
     if ($cat_product_id > 0 && $product_id > 0) {
         $aryExtra = array();
         $table = SoLib::getTableProduct($cat_product_id, $product_id);
         $aryExtra = DB::get_row('SELECT name,extra_fields FROM ' . $table . ' WHERE id= ' . $product_id . ' ');
         if ($aryExtra['extra_fields'] != '') {
             $objJSON = new Services_JSON();
             $aryExtraProduct = objectToArray($objJSON->decode($aryExtra['extra_fields']));
         }
         $aryExtraField = $this->getListExtraField($cat_product_id);
         //if($cat_product_id > 0)  {
         //	$query .= '( published:1 AND  category_id:'.$cat_product_id.' AND min_price:[1 TO *] AND max_price:[1 TO *]) AND ';
         //}
         //else {
         //	$query .= '( published:1 AND min_price:[1 TO *] AND max_price:[1 TO *]) AND ';
         //}
         $fq[] = "published:1 AND status:1";
         if ($cat_product_id > 0) {
             $query .= '( category_id:' . $cat_product_id . ' AND min_price:[1 TO *] AND max_price:[1 TO *]) AND ';
         } else {
             $query .= '( min_price:[1 TO *] AND max_price:[1 TO *]) AND ';
         }
         $querySolr = '';
         $querySolr = $this->buildQueryFromTolerancesAndWeightOfExtraField($aryExtraField, $aryExtraProduct);
         if ($querySolr == '') {
             if (strlen($query) > 0) {
                 $query = substr($query, 0, strlen($query) - 4);
             }
         } else {
             $query .= '(' . $querySolr . ')';
         }
         //add them dieu kien search name de cho chinh xac
         if ($aryExtra['name'] != '') {
             $objLib = new SoLib();
             $query .= ' AND name:' . $objLib->escapeSolrKeyword(trim($aryExtra['name']));
         }
         //if($query != '') {
         //
         //}
         //if (strlen($query) > 0) {
         //	$query = substr($query, 0, (strlen($query) - 4));
         //}
         //var_dump($query);
         $params = array();
         $params['fl'] = 'id, name, min_price, max_price, num_classified, images, date, description';
         //$params['fq'] = "-id : $product_id";
         $fq[] = "-id : {$product_id}";
         $params['fq'] = $fq;
         if ($query != "") {
             $solr = Solr::getInstanceProduct();
             $start = 0;
             $offset = self::NUMBER_PER_PAGE;
             $responseCheck = $solr->search($query, 0, 0);
             $total_row = 0;
             $paging = '';
             if ($responseCheck) {
                 if ($responseCheck->getHttpStatus() == 200) {
                     $total_row = $responseCheck->response->numFound;
                     if ($total_row > 0) {
                         $url_path = 'ajax.php?act=so_advanced&code=get_list_product_extra_field&cat_product_id=' . $cat_product_id . '&product_id=' . $product_id;
                         BMPaging::AjaxPagingSolr($paging, $start, $total_row, $offset, self::NUMBER_PAGE_SHOW, 'page_no', true, $url_path, 'paging_ajax_extra_field_template');
                         $response = $solr->search($query, $start, $offset, $params);
                         if ($response->getHttpStatus() == 200) {
                             if ($response->response->numFound > 0) {
                                 $i = 0;
                                 foreach ($response->response->docs as $doc) {
                                     $aryProduct[$i]['id'] = $doc->id;
                                     $aryProduct[$i]['name'] = $doc->name;
                                     $aryProduct[$i]['min_price'] = number_format($doc->min_price, 0, '.', '.');
                                     $aryProduct[$i]['max_price'] = number_format($doc->max_price, 0, '.', '.');
                                     $aryProduct[$i]['num_classified'] = $doc->num_classified;
                                     $aryProduct[$i]['description'] = $doc->description;
                                     $aryProduct[$i]['images'] = SoImg::getImage($doc->images, $doc->id, SoImg::FOLDER_PRODUCT, $doc->date, '70x0');
                                     $i++;
                                 }
                             }
                         } else {
                             $aryData['msg'] = 'Query solr thất bại.';
                             $aryData['intIsOK'] = -1;
                         }
                         if (is_array($aryProduct) && count($aryProduct) > 0) {
                             global $display;
                             $display->add('aryProduct', $aryProduct);
                             $display->add('paging', $paging);
                             $display->add('total_row', $total_row);
                             $aryHtml = $display->output('list_product_extra_field', true, 'SoBoxAdvanced');
                             $aryData['htmlProduct'] = $aryHtml;
                             $aryData['intIsOK'] = 1;
                         }
                     }
                 } else {
                     $aryData['msg'] = 'Query solr thất bại.';
                     $aryData['intIsOK'] = -1;
                 }
             }
         }
     }
     echo json_encode($aryData);
     exit;
 }