Post by steveharman » Mon Jul 15, 2013 8:57 pm

Hi,

I'm sure I've over-thought this problem which is why I can't figure it out!

On my category pages I'd like to feature some products / product images. Obviously there's the Featured module but that seems a little limited as I'd like to show products from the specific category being viewed - not products from other categories. For example if the user is viewing the iPad category then a selection iPads is shown, not iPhones.

Is it a case of manually duplicating the Featured module in the filesystem each time, renaming it Featured 2, 3 (etc.) and placing different "Featured" modules (appropriately populated with products) on the different category pages?

It feels like there must be a more elegant solution / extension for this... ;-)

Thanks,

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Mon Jul 15, 2013 9:59 pm

Here is the easy way to do this:
http://www.opencart.com/index.php?route ... on_id=7819

Here is a FREE way to do this:

FIRSTLY BACK UP ANY FILES YOU NEED TO EDIT BELOW

1) Make sure that the "Featured" module is on the category layout.
2) Open the catalog/controller/module/featured.php
3) Search for this code:

Code: Select all

$products = array_slice($products, 0, (int)$setting['limit']);
4) Underneath it add:

Code: Select all

		if(isset($this->request->get['route']) && $this->request->get['route'] == 'product/category'){
			$category_id = $this->request->get['path'];
		}else{
			$category_id = '';
		}
5) Then search for this code:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);
6) And replace it with this code:

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id, $category_id);
7) Open catalog/model/catalog/product.php
8) Search for this code:

Code: Select all

public function getProduct($product_id) {
9) Replace it with this code:

Code: Select all

public function getProduct($product_id, $category_id = false) {
10) Search for this code (it is quite a chunk of code here. It should around line 15):

Code: Select all

		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p 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) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND 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') . "'");
11) Replace it with this chunk of code:

Code: Select all

		if($category_id){
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p 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) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND 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') . "' AND p.product_id = (SELECT product_id FROM ".DB_PREFIX."product_to_category WHERE category_id = '".(int)$category_id."' AND product_id = p.product_id)");
		}else{
		$query = $this->db->query("SELECT DISTINCT *, pd.name AS name, p.image, m.name AS manufacturer, (SELECT price FROM " . DB_PREFIX . "product_discount pd2 WHERE pd2.product_id = p.product_id AND pd2.customer_group_id = '" . (int)$customer_group_id . "' AND pd2.quantity = '1' AND ((pd2.date_start = '0000-00-00' OR pd2.date_start < NOW()) AND (pd2.date_end = '0000-00-00' OR pd2.date_end > NOW())) ORDER BY pd2.priority ASC, pd2.price ASC LIMIT 1) AS discount, (SELECT price FROM " . DB_PREFIX . "product_special ps WHERE ps.product_id = p.product_id AND ps.customer_group_id = '" . (int)$customer_group_id . "' AND ((ps.date_start = '0000-00-00' OR ps.date_start < NOW()) AND (ps.date_end = '0000-00-00' OR ps.date_end > NOW())) ORDER BY ps.priority ASC, ps.price ASC LIMIT 1) AS special, (SELECT points FROM " . DB_PREFIX . "product_reward pr WHERE pr.product_id = p.product_id AND customer_group_id = '" . (int)$customer_group_id . "') AS reward, (SELECT ss.name FROM " . DB_PREFIX . "stock_status ss WHERE ss.stock_status_id = p.stock_status_id AND ss.language_id = '" . (int)$this->config->get('config_language_id') . "') AS stock_status, (SELECT wcd.unit FROM " . DB_PREFIX . "weight_class_description wcd WHERE p.weight_class_id = wcd.weight_class_id AND wcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS weight_class, (SELECT lcd.unit FROM " . DB_PREFIX . "length_class_description lcd WHERE p.length_class_id = lcd.length_class_id AND lcd.language_id = '" . (int)$this->config->get('config_language_id') . "') AS length_class, (SELECT AVG(rating) AS total FROM " . DB_PREFIX . "review r1 WHERE r1.product_id = p.product_id AND r1.status = '1' GROUP BY r1.product_id) AS rating, (SELECT COUNT(*) AS total FROM " . DB_PREFIX . "review r2 WHERE r2.product_id = p.product_id AND r2.status = '1' GROUP BY r2.product_id) AS reviews, p.sort_order FROM " . DB_PREFIX . "product p 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) LEFT JOIN " . DB_PREFIX . "manufacturer m ON (p.manufacturer_id = m.manufacturer_id) WHERE p.product_id = '" . (int)$product_id . "' AND 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') . "'");
		}
That should narrow all of the products down to the ones in the current category page you are on.

I hope this helps :)

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by steveharman » Mon Jul 15, 2013 10:17 pm

Thanks for the your work Peter, which will doubtless be useful for someone less likely to mess things up than I!

Unfortunately the "easy" option, which initially looked appealing seems to have died a death. The comments/reviews imply lots of errors, no reply from support and their demo link takes me to "This site has been suspended". Hmmm..

Thanks again though Peter I do appreciate your reply. If you / anyone knows of another module that does the same thing it would be great to hear.

Regards,

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Mon Jul 15, 2013 10:32 pm

I will put mine up in a VQMod file later tonight. I am working on a series of free extensions right now anyway to build up a portfolio.

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by pedro1993 » Mon Jul 15, 2013 10:32 pm

For now, if you want to give my tutorial a bash, here is it working:
http://test.embermonkey.com/1551_2/inde ... path=20_27

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by steveharman » Mon Jul 15, 2013 10:42 pm

Your site seems to offer just what I'm looking to do Peter! (different featured products across categories). If you do have the opportunity to put a VQMod out some time I'd be delighted / very grateful.

Thanks,

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Mon Jul 15, 2013 11:11 pm

Try this file I have attached :)

It should work for 1.5.5.x for sure!

Peter :)

Attachments


For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by steveharman » Mon Jul 15, 2013 11:24 pm

Fantastic work, thanks Peter.

So basically I populate the standard OpenCart "Featured" module with all the products I'd like featured on my site, and when inserted on say my 'iPad' category your module only shows products from category 'iPad' ? Sounds like it. Off to try now!

Cheers,

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Mon Jul 15, 2013 11:30 pm

Exactly. All you need to do is populate all featured products, and when you click on a particular category it will only show featured products from that category :)

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by steveharman » Mon Jul 15, 2013 11:52 pm

Marvelous. First though I have to work out what on Earth is going wrong with the Featured module itself. I've added some products to it and I can get it / them to show fine on the Home page and on Product pages - but when i add it on Category pages I just get an empty Featured box with a title ('Featured') but no thumbnails in it.

This is with the default OC template and without your mod installed, it's nothing to do with your work. Bizarre - must be the heat.

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Tue Jul 16, 2013 12:17 am

What version of OC are you using?

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by pedro1993 » Tue Jul 16, 2013 12:35 am

Also, here is an update. So if you go on a category page with no featured products, then the module won't display :)

Attachments


For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by steveharman » Tue Jul 16, 2013 12:37 am

Hi Peter,

\\ OC 1.5.5.1.

Thanks for the update, neat!

Steve

Active Member

Posts

Joined
Mon Mar 12, 2012 6:36 pm

Post by pedro1993 » Tue Jul 16, 2013 1:02 am

Then you should get results? If you are having more problems getting it working send me a PM :)

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland
Who is online

Users browsing this forum: RiguPhoto and 199 guests