Post by jens_b » Mon Apr 13, 2015 7:26 pm

Hi,

How can I add Attribute Text & Manufacturer Name to the search results?

I've messed around in catalog/model/catalog/product.php
but only managed to add manufacturer_id (not helping much hehe) like this:

Code: Select all

$sql .= " OR LCASE(p.manufacturer_id) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
Not sure how to add so it searches table oc_product_attribute - text & oc_manufacturer - name

Please help!

OpenCart 2.0.1.1
Last edited by jens_b on Tue Apr 14, 2015 1:45 am, edited 2 times in total.

New member

Posts

Joined
Mon Oct 28, 2013 6:19 pm

Post by chulcha » Tue Apr 14, 2015 12:04 am

getProducts
1.

Code: Select all

			if (!empty($data['filter_name'])) {
				$sql .= " OR LCASE(p.model) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.sku) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.upc) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.ean) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.jan) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.isbn) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
				$sql .= " OR LCASE(p.mpn) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";
//Add
				$sql .= " OR LCASE(m.name) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";

			}
2.

Code: Select all

		$sql .= " LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'";
add next code

Code: Select all

$sql .= " LEFT JOIN " . DB_PREFIX . "manufacturer m ON (m.manufactured_id = p.manufacturer_id)";
In the code, errors may occur

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm

Post by jens_b » Tue Apr 14, 2015 1:44 am

Thank you very much chulcha! works perfect!

I also added this for attributes text search

Code: Select all

. DB_PREFIX . "product_attribute pa ON (p.product_id = pa.product_id) LEFT JOIN " .
and then

Code: Select all

$sql .= " OR LCASE(pa.text) = '" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "'";

New member

Posts

Joined
Mon Oct 28, 2013 6:19 pm

Post by chulcha » Tue Apr 14, 2015 4:41 am

Possible to use the next code

$sql .= " OR LCASE(m.name) LIKE '%" . $this->db->escape(utf8_strtolower($data['filter_name'])) . "%'";

If you have one language, then our code is completed
If you have one language, then code is completed for use, otherwise you should also check and language



pa.language_id = '" . (int)$this->config->get('config_language_id') . "'

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm
Who is online

Users browsing this forum: No registered users and 184 guests