Post by fabioDexus » Fri Jun 03, 2011 8:58 am

To make the product show the Canon EOF product for example when you type EOF change the lines in opencart 1.5 in admin/model/catalog/product.php 334-340 to:

Code: Select all

			if (isset($data['filter_name']) && !is_null($data['filter_name'])) {
				$sql .= " AND LCASE(pd.name) LIKE '%" . $this->db->escape(strtolower($data['filter_name'])) . "%'";
			}

			if (isset($data['filter_model']) && !is_null($data['filter_model'])) {
				$sql .= " AND LCASE(p.model) LIKE '%" . $this->db->escape(strtolower($data['filter_model'])) . "%'";
			}
I will put this as a request in the apropriate area later

New member

Posts

Joined
Fri May 13, 2011 5:53 am

Post by fabioDexus » Fri Jun 03, 2011 9:28 am

Also i added a way to make quantity searchs for > and < like >900 etc:
Changed line 346 to:

Code: Select all

	if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
				$operator='=';
				if(strpos ($data['filter_quantity'],'<')!==false || strpos ($data['filter_quantity'],'<')!==false){
					$operator='<';
				}
				else if(strpos ($data['filter_quantity'],'>')!==false || strpos ($data['filter_quantity'],'>')!==false){
					$operator='>';
				}
				$quantity=trim(str_replace(array('<','>','<','>'), '', $data['filter_quantity']));
				$sql .= ' AND p.quantity '.$operator.'\'' .$this->db->escape( $quantity). '\'';
			}

New member

Posts

Joined
Fri May 13, 2011 5:53 am

Post by davidkimm » Wed Jul 27, 2011 10:30 am

Excellent.... the first part of your solution was what I was searching for... really liked the wildcard feature in 1.4.9.3 and bummed that it was missing in 1.5.0.5 ... your solution worked perfect..

Also, love the additional "less than or greater" search for quantity... that was the icing on the cake... its these small features that really makes a difference... two thumbs up! :drunk: thank you

ps - just curious... change that work for price too? or is price handled differently? Too lazy right now...

New member

Posts

Joined
Wed Mar 23, 2011 3:12 pm

Post by lloydmedley » Tue Sep 24, 2013 6:59 pm

You didn't put the code to replace and I know that some of my admin files have been modified by my theme so didn't try this method. Used this mod instead (thought I'd share as I found this thread first so others might too)

http://www.opencart.com/index.php?route ... _license=0

If I forgot to mention: it's OpenCart Vv1.5.6


New member

Posts

Joined
Tue Mar 29, 2011 11:18 pm

Post by xlam » Fri Sep 26, 2014 1:00 am

fabioDexus wrote:Also i added a way to make quantity searchs for > and < like >900 etc:
Changed line 346 to:

Code: Select all

	if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
				$operator='=';
				if(strpos ($data['filter_quantity'],'<')!==false || strpos ($data['filter_quantity'],'<')!==false){
					$operator='<';
				}
				else if(strpos ($data['filter_quantity'],'>')!==false || strpos ($data['filter_quantity'],'>')!==false){
					$operator='>';
				}
				$quantity=trim(str_replace(array('<','>','<','>'), '', $data['filter_quantity']));
				$sql .= ' AND p.quantity '.$operator.'\'' .$this->db->escape( $quantity). '\'';
			}
work for me on 1.5.5.1

Baju Muslim Baju Pria Baju Anak Baju Korea Sparepart Printer Baju Muslim JNE Surabaya


New member

Posts

Joined
Sun Dec 25, 2011 2:58 pm

Post by siteadvice » Thu Feb 04, 2016 2:18 am

To search by a part of the product name in Opencart 2+ you need to change lines 251 - 260 like so:

Code: Select all

		if (!empty($data['filter_name'])) {
			$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
		}

		if (!empty($data['filter_model'])) {
			$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'";
		}

		if (isset($data['filter_price']) && !is_null($data['filter_price'])) {
			$sql .= " AND p.price LIKE '%" . $this->db->escape($data['filter_price']) . "%'";
In a nutshell, you're just adding a % sign to the start of the search term as well as at the end of it.

inframes.com Website Design with Opencart, Coldfusion, Railo and Concrete5


User avatar
New member

Posts

Joined
Mon Oct 24, 2011 8:12 pm

Post by OSWorX » Thu Feb 04, 2016 3:30 am

I would also add

Code: Select all

LCASE
and

Code: Select all

strtolower
(as can be seen in the first post).

Otherwise the search item has to match exactly the term.

Forum Rules [en]: viewtopic.php?f=176&t=200480
Forumregeln [de]: viewtopic.php?f=37&t=114208
Commercial Request: viewforum.php?f=88

Image


User avatar
Expert Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by smarg » Wed Apr 13, 2016 2:36 pm

Hello to all,
I use version 1.5.6.4,with a theme installed and this code works for me. Also, after fixing the search problem, I had a problem with the product count and shown at the end of the page: "Showing 0 to 0 of 0 (0 Pages)". If anyone else have the same problem, I show you what I did to fix it.

First I show you what I changed to fix the product search:
The only I did was to add % in the line 345: "AND pd.name LIKE '%" and in line 349 " AND p.model LIKE '%". All the code in lines 344-350 is:
if (!empty($data['filter_name'])) {
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
}

if (!empty($data['filter_model'])) {
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'";
}

Second, I show you what I did to fix the procuct count at the end of admin page:

I changed the code in function:"public function getProfiles($product_id)" in the lines 600 to 607. Add % in line 602(" AND pd.name LIKE '%") and in line 606(" AND p.model LIKE '%"). The hole code is:

public function getProfiles($product_id) {
return $this->db->query("SELECT * FROM `" . DB_PREFIX . "product_profile` WHERE product_id = " . (int)$product_id)->rows;
}

public function getTotalProducts($data = array()) {
$sql = "SELECT COUNT(DISTINCT p.product_id) AS total FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id)";

if (!empty($data['filter_category_id'])) {
$sql .= " LEFT JOIN " . DB_PREFIX . "product_to_category p2c ON (p.product_id = p2c.product_id)";
}

$sql .= " WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "'";

if (!empty($data['filter_name'])) {
$sql .= " AND pd.name LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
}

if (!empty($data['filter_model'])) {
$sql .= " AND p.model LIKE '%" . $this->db->escape($data['filter_model']) . "%'";
}

I hope to help anyone has the same problem.

Newbie

Posts

Joined
Wed Apr 13, 2016 2:08 pm

Post by radi8tor » Sun Sep 30, 2018 8:52 am

smarg wrote:
Wed Apr 13, 2016 2:36 pm
Also, after fixing the search problem, I had a problem with the product count and shown at the end of the page: "Showing 0 to 0 of 0 (0 Pages)". If anyone else have the same problem, I show you what I did to fix it.
Thanks!

New member

Posts

Joined
Thu Feb 01, 2018 6:21 pm
Who is online

Users browsing this forum: No registered users and 4 guests