A
A
Ali Ali2021-02-21 00:41:47
opencart
Ali Ali, 2021-02-21 00:41:47

Error in OPEN cart when searching?

It gives an error when searching the site.

Fatal error: Cannot redeclare ControllerProductSearch::ajax() in /home/admin/web/mister-watch.ru/public_html/system/modification/catalog/controller/product/search.php on line 93


file: search.php

public function  ajax() {
            
                    $this->load->model('tool/image');
          
          
          if(isset($this->request->get['keyword'])) {
            $data = array();
            // Parse all keywords to lowercase
            $keywords = utf8_strtolower( $this->request->get['keyword'] );
            // Perform search only if we have some keywords
            if( utf8_strlen($keywords) >= 3 ) {
              $parts = explode( ' ', $keywords );
              $add = '';
              // Generating search
              foreach( $parts as $part ) {
                $add .= ' AND (LOWER(pd.name) LIKE "%' . $this->db->escape($part) . '%"';
                $add .= ' OR LOWER(p.model) LIKE "%' . $this->db->escape($part) . '%")';
              }
              $add = substr( $add, 4 );
              $sql  = 'SELECT pd.product_id, pd.name, p.image, p.model FROM ' . DB_PREFIX . 'product_description AS pd ';
              $sql .= 'LEFT JOIN ' . DB_PREFIX . 'product AS p ON p.product_id = pd.product_id ';
              $sql .= 'LEFT JOIN ' . DB_PREFIX . 'product_to_store AS p2s ON p2s.product_id = pd.product_id ';
              $sql .= 'WHERE ' . $add . ' AND p.status = 1 ';
              $sql .= 'AND pd.language_id = ' . (int)$this->config->get('config_language_id');
              $sql .= ' AND p2s.store_id =  ' . (int)$this->config->get('config_store_id'); 
              $sql .= ' ORDER BY p.sort_order ASC, LOWER(pd.name) ASC, LOWER(p.model) ASC';
              $sql .= ' LIMIT 10';
                            
                            
                            

              $res = $this->db->query( $sql );
              if( $res ) {
                $data = ( isset($res->rows) ) ? $res->rows : $res->row;
        
                                    
                                 
                                    
                // For the seo url stuff
                $basehref = 'product/product&keyword=' . $this->request->get['keyword'] . '&product_id=';
                foreach( $data as $key => $values ) {
                    
                                    if (isset($values['image']) && $values['image'] != "") {
               
                                        $values['image'] = $this->model_tool_image->resize($values['image'], 60, 60);
                                    }    
                                    
                  $data[$key] = array(
                    'name' => htmlspecialchars_decode($values['name'] . ' (' . $values['model'] . ')', ENT_QUOTES),
                    'href' => $this->url->link($basehref . $values['product_id']),
                                        'image' => $values['image']
                  );
                }
              }
            }
          }
          echo json_encode( $data );
        }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ali Ali, 2021-02-24
@Ali_1

In another forum I found an answer, they advised me to comment on this piece of code, /*-----*/ and the problem was solved.
There is only a problem with the cart, the product is not added to the cart.

W
web-mechanic, 2021-02-24
@amfetamine

- google translate?
nope, haven't heard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question