Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Undefined variable


Racoon

Recommended Posts

Здравствуйте!

Помогите, пожалуйста, устранить причину появления такого предупреждения:

 

Notice: Undefined variable: ocfilter_products_options in 

/usr/local/hosting/sites/shopmmcomua/www/vqmod/vqcache/vq2-catalog_controller_product_search.php on line 380

 

Появляется при работе фильтра, вернее, поиска по ключевому слову. Понимаю из предупреждения, что переменную эту нужно назначить, но, поскольку нуб, не знаю, где именно.

 

Версия: 1.5.6.1, если это важно.

 

 

 <?php 
class ControllerProductSearch extends Controller {  
public function index() {
        $this->document->addStyle('catalog/view/theme/default/stylesheet/category.css');
 
$this->language->load('product/search');
$this->load->model('catalog/category');
 
$this->load->model('catalog/product');
 
# OCFilter start
$this->load->model('catalog/ocfilter');
# OCFilter end
 
$this->load->model('tool/image');
 
        $this->data['empty_search_send_mail'] = false;
        if(isset($this->request->post['search-empty']))
        {
            $sender = isset($this->request->post['email']) ? $this->request->post['email'] : '';
            $name = isset($this->request->post['name']) ? $this->request->post['name'] : '';
            $phone = isset($this->request->post['phone']) ? $this->request->post['phone'] : '';
            $message = isset($this->request->post['message']) ? $this->request->post['message'] : '';
            $search_empty = isset($this->request->post['search-empty']) ? $this->request->post['search-empty'] : '';
 
            if($sender && $message)
            {
                $text = $this->language->get('text_mail_search').' '.$search_empty.'<br/>';
                $text .= $this->language->get('text_mail_name').' '.$name.'<br/>';
                $text .= $this->language->get('text_mail_phone').' '.$phone.'<br/>';
                $text .= $this->language->get('text_mail_message').' '.$message;
 
                $mail = new Mail();
                $mail->protocol = $this->config->get('config_mail_protocol');
                $mail->parameter = $this->config->get('config_mail_parameter');
                $mail->hostname = $this->config->get('config_smtp_host');
                $mail->username = $this->config->get('config_smtp_username');
                $mail->password = $this->config->get('config_smtp_password');
                $mail->port = $this->config->get('config_smtp_port');
                $mail->timeout = $this->config->get('config_smtp_timeout');
                $mail->setTo($this->config->get('config_email'));
                $mail->setFrom($this->config->get('config_email'));
                $mail->setSender($sender);
                $mail->setSubject(html_entity_decode($this->language->get('text_mail_title_empty'), ENT_QUOTES, 'UTF-8'));
                $mail->setHtml(html_entity_decode($text, ENT_QUOTES, 'UTF-8'));
                $mail->send();
 
                // Send to additional alert emails
                $emails = explode(',', $this->config->get('config_alert_emails'));
 
                foreach ($emails as $email) {
                    if ($email && preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $email)) {
                        $mail->setTo($email);
                        $mail->send();
                    }
                }
 
                $this->data['empty_search_send_mail'] = true;
            }
        }
 
if (isset($this->request->get['search'])) {
$search = $this->request->get['search'];
} else {
$search = '';
} 
 
if (isset($this->request->get['tag'])) {
$tag = $this->request->get['tag'];
} elseif (isset($this->request->get['search'])) {
$tag = $this->request->get['search'];
} else {
$tag = '';
} 
 
if (isset($this->request->get['description'])) {
$description = $this->request->get['description'];
} else {
$description = 0;
}
        if (isset($this->request->get['in_the_name'])) {
            $in_the_name = $this->request->get['in_the_name'];
        } else {
            $in_the_name = 0;
        }
 
        if (isset($this->request->get['category_id'])) {
$category_id = $this->request->get['category_id'];
} else {
$category_id = 0;
} 
 
if (isset($this->request->get['sub_category'])) {
$sub_category = $this->request->get['sub_category'];
} else {
$sub_category = '';
}
 
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
} 
 
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
 
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
} else {
$page = 1;
}
 
if (isset($this->request->get['limit'])) {
$limit = $this->request->get['limit'];
} else {
$limit = $this->config->get('config_catalog_limit');
}
 
if (isset($this->request->get['search'])) {
$this->document->setTitle($this->language->get('heading_title') .  ' - ' . $this->request->get['search']);
} else {
$this->document->setTitle($this->language->get('heading_title'));
}
 
$this->document->addScript('catalog/view/javascript/jquery/jquery.total-storage.min.js');
 
$this->data['breadcrumbs'] = array();
 
$this->data['breadcrumbs'][] = array(
'text'      => $this->language->get('text_home'),
'href'      => $this->config->get('config_url'),
'separator' => false
);
 
$url = '';
 
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
 
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
 
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
 
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
} 
 
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
 
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
} 
 
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
 
        if (isset($this->request->get['in_the_name'])) {
            $url .= '&in_the_name=' . $this->request->get['in_the_name'];
        }
 
$this->data['breadcrumbs'][] = array(
'text'      => $this->language->get('heading_title'),
'href'      => $this->url->link('product/search', $url),
'separator' => $this->language->get('text_separator')
);
 
        $this->data['action'] = $this->url->link('product/search', $url, 'SSL');
 
if (isset($this->request->get['search'])) {
$this->data['heading_title'] = $this->language->get('heading_title_new') .  ' "' . $this->request->get['search'].'"';
} else {
$this->data['heading_title'] = $this->language->get('heading_title');
}
 
$this->data['text_empty'] = $this->language->get('text_empty');
$this->data['text_critea'] = $this->language->get('text_critea');
$this->data['text_search'] = $this->language->get('text_search');
$this->data['text_keyword'] = $this->language->get('text_keyword');
$this->data['text_category'] = $this->language->get('text_category');
$this->data['text_sub_category'] = $this->language->get('text_sub_category');
$this->data['text_quantity'] = $this->language->get('text_quantity');
$this->data['text_manufacturer'] = $this->language->get('text_manufacturer');
$this->data['text_model'] = $this->language->get('text_model');
$this->data['text_price'] = $this->language->get('text_price');
$this->data['text_tax'] = $this->language->get('text_tax');
$this->data['text_points'] = $this->language->get('text_points');
$this->data['text_compare'] = sprintf($this->language->get('text_compare'), (isset($this->session->data['compare']) ? count($this->session->data['compare']) : 0));
$this->data['text_display'] = $this->language->get('text_display');
$this->data['text_list'] = $this->language->get('text_list');
$this->data['text_grid'] = $this->language->get('text_grid'); 
$this->data['text_sort'] = $this->language->get('text_sort');
$this->data['text_limit'] = $this->language->get('text_limit');
$this->data['text_special'] = $this->language->get('text_special');
$this->data['text_new'] = $this->language->get('text_new');
$this->data['text_hit'] = $this->language->get('text_hit');
$this->data['text_code'] = $this->language->get('text_code');
$this->data['button_cart'] = $this->language->get('button_cart');
 
$this->data['entry_search'] = $this->language->get('entry_search');
$this->data['entry_description'] = $this->language->get('entry_description');
 
$this->data['button_search'] = $this->language->get('button_search');
$this->data['button_cart'] = $this->language->get('button_cart');
$this->data['button_wishlist'] = $this->language->get('button_wishlist');
$this->data['button_compare'] = $this->language->get('button_compare');
$this->data['button_send'] = $this->language->get('button_send');
 
$this->data['phl_name'] = $this->language->get('phl_name');
$this->data['phl_phone'] = $this->language->get('phl_phone');
$this->data['phl_email'] = $this->language->get('phl_email');
$this->data['phl_message'] = $this->language->get('phl_message');
 
$this->data['err_name'] = $this->language->get('err_name');
$this->data['err_email'] = $this->language->get('err_email');
$this->data['err_message'] = $this->language->get('err_message');
$this->data['err_invalid_email'] = $this->language->get('err_invalid_email');
 
$this->data['text_mail_send'] = $this->language->get('text_mail_send');
 
$this->data['compare'] = $this->url->link('product/compare');
 
$this->load->model('catalog/category');
 
// 3 Level Category Search
$this->data['categories'] = array();
 
$categories_1 = $this->model_catalog_category->getCategories(0);
 
foreach ($categories_1 as $category_1) {
$level_2_data = array();
 
$categories_2 = $this->model_catalog_category->getCategories($category_1['category_id']);
 
foreach ($categories_2 as $category_2) {
$level_3_data = array();
 
$categories_3 = $this->model_catalog_category->getCategories($category_2['category_id']);
 
foreach ($categories_3 as $category_3) {
$level_3_data[] = array(
'category_id' => $category_3['category_id'],
'name'        => $category_3['name'],
);
}
 
$level_2_data[] = array(
'category_id' => $category_2['category_id'], 
'name'        => $category_2['name'],
'children'    => $level_3_data
); 
}
 
$this->data['categories'][] = array(
'category_id' => $category_1['category_id'],
'name'        => $category_1['name'],
'children'    => $level_2_data
);
}
 
        $new_products = explode(',', $this->config->get('featured_product'));
        $hits = $this->model_catalog_product->getBestSellerProducts(1000);
 
$this->data['products'] = array();
        $product_total_arr = array();
        $product_total = 0;
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
            $data = array(
                'filter_name'         => $search,
                'filter_category_id'  => $category_id,
                'sort'                => $sort,
                'order'               => $order,
                'start'               => ($page - 1) * $limit,
                'limit'               => $limit
            );
 
            $allResults = array();
            if($description == 1 && $in_the_name == 0)
            {
                $data['filter_description'] = true;
                $data['search_type'] = 'desc';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $product_total_arr = array_merge($this->model_catalog_product->getSearchProductsTotalCount($data), $product_total_arr);
                $allResults = array_merge($allResults, $res);
            }
            elseif($in_the_name == 1 && $description == 1)
            {
                $data['filter_in_the_name'] = true;
                $data['filter_description'] = true;
                $data['search_type'] = 'all';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $product_total_arr = array_merge($this->model_catalog_product->getSearchProductsTotalCount($data), $product_total_arr);
                $allResults = array_merge($allResults, $res);
 
                /*unset($data['filter_in_the_name']);
 
                $data['filter_description'] = true;
                $data['search_type'] = 'desc';
                $res2 = $this->model_catalog_product->getSearchProducts($data);
                $product_total_arr = array_merge($this->model_catalog_product->getSearchProductsTotalCount($data), $product_total_arr);
                $allResults = array_merge($allResults, $res2);*/
            }
            else
            {
                $data['filter_in_the_name'] = true;
                $data['search_type'] = 'name';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $product_total_arr = array_merge($this->model_catalog_product->getSearchProductsTotalCount($data), $product_total_arr);
                $allResults = array_merge($allResults, $res);
            }
            $pta = array();
            foreach($product_total_arr as $p)
            {
                if(!in_array($p, $pta)) $pta[] = $p;
            }
            $product_total = count($pta);
            $this->data['product_total'] = $product_total;
 
            $products = array();
            
            $cod = (isset($_SESSION['ref_cod']) ? $_SESSION['ref_cod'] : '');
 
foreach ($allResults as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = false;
}
 
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
 
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
} 
 
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price']);
} else {
$tax = false;
}
 
                if(array_key_exists($result['product_id'], $products))
                {
                    if($products[$result['product_id']]['search_type'] == 'name')
                    {
                        $products[$result['product_id']]['description']  = $this->_prepareDesc($result['description'], $search);
                    }
                    continue;
                }
 
                $products[$result['product_id']] = array(
                    'search_type' => $result['search_type'],
'product_id'  => $result['product_id'],
# OCFilter start
'ocfilter_products_options' => $ocfilter_products_options[$result['product_id']],
# OCFilter end
'thumb'       => $image,
'name'        => $result['name'],
//'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price'       => $price,
'special'     => $special,
'tax'         => $tax,
//'rating'      => $result['rating'],
//'reviews'     => sprintf($this->language->get('text_reviews'), (int)$result['reviews']),
'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id'] . $url),
                    'hit'         => isset($hits[$result['product_id']]) ? true : false,
                    'new'         => in_array($result['product_id'],$new_products) ? true : false,
                    'sku'         => $cod . '-' . $result['sku'],
                    'new_link'    => in_array($result['product_id'],$new_products) ? $this->url->link('product/bingo', 'bin=new') : '',
                    'hit_link'    => isset($hits[$result['product_id']]) ? $this->url->link('product/bingo', 'bin=hit') : '',
                    'special_link'=> $special ? $this->url->link('product/bingo', 'bin=special') : '',
);
 
                if($result['search_type'] == 'desc' || $result['search_type'] == 'all') $products[$result['product_id']]['description']  = $this->_prepareDesc($result['description'], $search);
}
 
            if($sort == 'p.sort_order')
            {
                /*usort($products, function($a, $ B){
                    return $a['search_type'] == 'name' &&  $b['search_type'] == 'desc' ? 0 : 1;
                });*/
                usort($products, function($a, $ B){
                    if(isset($a['description']) && isset($b['description']) && trim($a['description']) != '' && trim($b['description']) != '') return 0;
                    if(isset($a['description']) && isset($b['description']) && trim($a['description']) == '' && trim($b['description']) == '') return 0;
                    if(isset($a['description']) && isset($b['description']) && trim($a['description']) != '' && trim($b['description']) == '') return 1;
                    if(!isset($a['description']) && isset($b['description']) && trim($b['description']) != '') return 0;
                    if(isset($a['description']) && trim($a['description']) != '' && !isset($b['description'])) return 1;
                    return 0;
                });
            }
 
            $this->data['products'] = $products;
 
$url = '';
 
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
 
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
 
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
 
            if (isset($this->request->get['in_the_name'])) {
                $url .= '&in_the_name=' . $this->request->get['in_the_name'];
            }
 
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
 
$this->data['sorts'] = array();
 
            $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_rating_desc'),
                'value' => 'rating-DESC',
                'href'  => $this->url->link('product/search', 'sort=rating&order=DESC' . $url)
            );
 
$this->data['sorts'][] = array(
'text'  => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href'  => $this->url->link('product/search', 'sort=p.price&order=ASC' . $url)
); 
 
$this->data['sorts'][] = array(
'text'  => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href'  => $this->url->link('product/search', 'sort=p.price&order=DESC' . $url)
);
 
            $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_news_sort'),
                'value' => 'news-DESC',
                'href'  => $this->url->link('product/search', 'sort=news&order=DESC' . $url)
            );
 
            $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_hits_sort'),
                'value' => 'hits-DESC',
                'href'  => $this->url->link('product/search', 'sort=hits&order=DESC' . $url)
            );
 
            $this->data['sorts'][] = array(
                'text'  => $this->language->get('text_special_sort'),
                'value' => 'special-DESC',
                'href'  => $this->url->link('product/search', 'sort=special&order=DESC' . $url)
            );
 
$url = '';
 
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
 
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
 
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
 
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
 
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
 
            if (isset($this->request->get['in_the_name'])) {
                $url .= '&in_the_name=' . $this->request->get['in_the_name'];
            }
 
$this->data['limits'] = array();
 
$limits = array_unique(array($this->config->get('config_catalog_limit'), 25, 50, 75, 100));
 
sort($limits);
 
foreach($limits as $value){
$this->data['limits'][] = array(
'text'  => $value,
'value' => $value,
'href'  => $this->url->link('product/search', $url . '&limit=' . $value)
);
}
            $this->data['limits'][] = array(
                'text'  => $this->language->get('text_all'),
                'value' => -1,
                'href'  => $this->url->link('product/search', $url . '&limit=' . -1)
            );
 
$url = '';
 
if (isset($this->request->get['search'])) {
$url .= '&search=' . urlencode(html_entity_decode($this->request->get['search'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . urlencode(html_entity_decode($this->request->get['tag'], ENT_QUOTES, 'UTF-8'));
}
 
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
 
if (isset($this->request->get['category_id'])) {
$url .= '&category_id=' . $this->request->get['category_id'];
}
 
if (isset($this->request->get['sub_category'])) {
$url .= '&sub_category=' . $this->request->get['sub_category'];
}
 
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
} 
 
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
 
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
 
            if (isset($this->request->get['in_the_name'])) {
                $url .= '&in_the_name=' . $this->request->get['in_the_name'];
            }
 
$pagination = new Pagination();
$pagination->total = $product_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->text = $this->language->get('text_pagination');
            $pagination->text_first = false;
            $pagination->text_last = false;
            $pagination->text_next = $this->language->get('text_next');
            $pagination->text_prev = $this->language->get('text_prev');
$pagination->url = $this->url->link('product/search', $url . '&page={page}');
 
$this->data['pagination'] = $pagination->render();
} 
 
$this->data['search'] = $search;
$this->data['description'] = $description;
$this->data['category_id'] = $category_id;
$this->data['sub_category'] = $sub_category;
 
$this->data['sort'] = $sort;
$this->data['order'] = $order;
$this->data['limit'] = $limit;
 
        $ver = 3;
        $lecs_arr[1] = array('1','01','21','31','41','51','61','71','81','91');
        $lecs_arr[2] = array('2','3','4','02','03','04','22','23','24','32','33','34','42','43','44','52','53','54','62','63','64','72','73','74','82','83','84','92','93','94');
        $tot_p = (isset($product_total) ? $product_total : 0);
        if($tot_p < 10){
            if(in_array(strval($tot_p),$lecs_arr[1])){
                $ver = 1;
            }elseif(in_array(strval($tot_p),$lecs_arr[2])){
                $ver = 2;
            }
        }else{
            $prod_str = substr(strval($tot_p),-2);
            if(in_array($prod_str,$lecs_arr[1])){
                $ver = 1;
            }elseif(in_array($prod_str,$lecs_arr[2])){
                $ver = 2;
            }
        }
        $this->data['text_count_results'] = sprintf($this->language->get('text_count_results_'.$ver),$tot_p);
        //$this->data['text_count_results'] = str_replace('%s', (isset($product_total) ? $product_total : 0), $this->language->get('text_count_results'));
 
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/search.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/search.tpl';
} else {
$this->template = 'default/template/product/search.tpl';
}
 
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
 
$this->response->setOutput($this->render());
}
 
    public function get_search() {
        $this->language->load('product/search');
 
        $this->load->model('catalog/category');
 
        $this->load->model('catalog/product');
 
# OCFilter start
$this->load->model('catalog/ocfilter');
# OCFilter end
 
        $this->load->model('tool/image');
 
        if (isset($this->request->post['search'])) {
            $search = $this->request->post['search'];
        } else {
            $search = '';
        }
 
        if (isset($this->request->post['description'])) {
            $description = (int)$this->request->post['description'];
        } else {
            $description = 0;
        }
 
        if (isset($this->request->post['category_id'])) {
            $category_id = (int)$this->request->post['category_id'];
        } else {
            $category_id = 0;
        }
 
        if (isset($this->request->post['in_the_name'])) {
            $in_the_name = (int)$this->request->post['in_the_name'];
        } else {
            $in_the_name = 0;
        }
 
        $this->load->model('catalog/category');
 
        $products = array();
 
        if (isset($this->request->post['search'])) {
            $data = array(
                'filter_name'         => $search,
                'filter_category_id'  => $category_id,
            );
 
            $allResults = array();
            if($description == 1 && $in_the_name == 0)
            {
                $data['filter_description'] = true;
                $data['search_type'] = 'desc';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $allResults = array_merge($allResults, $res);
            }
            elseif($in_the_name == 1 && $description == 1)
            {
                $data['filter_in_the_name'] = true;
                $data['search_type'] = 'name';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $allResults = array_merge($allResults, $res);
 
                unset($data['filter_in_the_name']);
 
                $data['filter_description'] = true;
                $data['search_type'] = 'desc';
                $res2 = $this->model_catalog_product->getSearchProducts($data);
                $allResults = array_merge($allResults, $res2);
            }
            else
            {
                $data['filter_in_the_name'] = true;
                $data['search_type'] = 'name';
                $res = $this->model_catalog_product->getSearchProducts($data);
                $allResults = array_merge($allResults, $res);
            }
 
            foreach ($allResults as $result) {
                if ($result['image']) {
                    $image = $this->model_tool_image->resize($result['image'], 104, 74);
                } else {
                    $image = false;
                }
 
                if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                    $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    $price = false;
                }
 
                if ((float)$result['special']) {
                    $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
                } else {
                    $special = false;
                }
 
                if(array_key_exists($result['product_id'], $products))
                {
                    if($products[$result['product_id']]['search_type'] == 'name')
                    {
                        $products[$result['product_id']]['description']  = $this->_prepareDesc($result['description'], $search);
                    }
                    continue;
                }
 
                $products[$result['product_id']] = array(
                    'search_type'  => $result['search_type'],
                    'product_id'   => $result['product_id'],
# OCFilter start
'ocfilter_products_options' => $ocfilter_products_options[$result['product_id']],
# OCFilter end
                    'thumb'        => $image,
                    'name'         => $result['name'],
                    'price'        => ($special ? $special : $price),
                    'href'         => $this->url->link('product/product', 'product_id=' . $result['product_id'])
                );
                if($result['search_type'] == 'desc') $products[$result['product_id']]['description']  = $this->_prepareDesc($result['description'], $search);
            }
        }
 
        usort($products, function($a, $ B){
            if(isset($a['description']) && isset($b['description']) && trim($a['description']) != '' && trim($b['description']) != '') return 0;
            if(isset($a['description']) && isset($b['description']) && trim($a['description']) == '' && trim($b['description']) == '') return 0;
            if(isset($a['description']) && isset($b['description']) && trim($a['description']) != '' && trim($b['description']) == '') return 1;
            if(!isset($a['description']) && isset($b['description']) && trim($b['description']) != '') return 0;
            if(isset($a['description']) && trim($a['description']) != '' && !isset($b['description'])) return 1;
            return 0;
        });
 
        $url_goto_full_str = '';
        if($search) $url_goto_full_str .= 'search='.$search;
        if($description > 0) $url_goto_full_str .= '&description='.$description;
        if($category_id > 0) $url_goto_full_str .= '&category_id='.$category_id;
        if($in_the_name > 0) $url_goto_full_str .= '&in_the_name='.$in_the_name;
 
        $url_goto_full = $this->url->link('product/search', $url_goto_full_str);
 
        $this->response->setOutput(json_encode(array('results'=>array_values($products), 'goto_full'=>$url_goto_full)));
    }
 
    private function _prepareDesc($desc = '', $term = '')
    {
        if(!$desc || !$term) return '';
 
        $desc = trim(str_replace(array("\r\n", "\r", "\n", "\t"), ' ', strip_tags(preg_replace("/<\s*style.*?>(.*?)<\/\s*?style[^>\w]*?>/isU","",html_entity_decode($desc, ENT_QUOTES, 'UTF-8')))));
        $termArr = explode(' ', $term);
 
        $needTerm = function_exists('utf8_strpos') && function_exists('utf8_strtolower') && function_exists('utf8_strtolower')
            ? utf8_strpos(utf8_strtolower($desc), utf8_strtolower($termArr[0])) : strpos(strtolower($desc), strtolower($termArr[0]));
 
        if($needTerm === false) return '';
        $originTerm_tmp = function_exists('utf8_substr') && function_exists('utf8_strlen') ? utf8_substr($desc, $needTerm, utf8_strlen($desc) - $needTerm) :  substr($desc, $needTerm, strlen($desc) - $needTerm);
        $originTerm = '';
 
        for($i=0;$i<strlen($originTerm_tmp);$i++)
        {
            if($originTerm_tmp[$i] == ' ') break;
            $originTerm .= $originTerm_tmp[$i];
        }
 
        if($originTerm == '') return '';
 
        $newDesc = str_replace($originTerm, "<b>".$originTerm."</b>", $desc);
 
        $newRight = function_exists('utf8_substr') ? utf8_substr($newDesc, 0, $needTerm + 80) : substr($newDesc, 0, $needTerm + 80);
        $needTermOrigin = function_exists('utf8_strpos') ? utf8_strpos($newRight, "<b>".$originTerm."</b>") : strpos($newRight, "<b>".$originTerm."</b>");
 
        return function_exists('utf8_substr') ? ($needTermOrigin < 80 ? '' : '...').utf8_substr(utf8_substr($newRight, ($needTermOrigin - 80 < 0 ? 0 : $needTermOrigin - 80) , strlen($newRight)), 0, 160+$needTermOrigin).(strlen($desc) - $needTerm < 80 ? '' : '...')
            : ($needTermOrigin < 80 ? '' : '...').substr(substr($newRight, ($needTermOrigin - 80 < 0 ? 0 : $needTermOrigin - 80) , strlen($newRight)), 0, 160+$needTermOrigin).(strlen($desc) - $needTerm < 80 ? '' : '...');
    }
}
?>
Надіслати
Поділитися на інших сайтах


Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку
×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.