Post by edseljay » Thu Aug 04, 2016 4:48 pm

How can i display the Category of Products in "product/search.tpl" and in "product/product.tpl"
See Image Attachment:

on the default it display the:
1. Product Name
2.Product Description
3.Price
4.Tax

i also want to display the Category of the product because i want to do if the product is equal on a certain category do a certain condition.. hope someone could help me.. thanks

Attachments

Capture.PNG

Capture.PNG (186.75 KiB) Viewed 1095 times


New member

Posts

Joined
Tue Jul 12, 2016 11:25 am

Post by paulfeakins » Thu Aug 04, 2016 5:46 pm

You would need to add some code in to the controllers for both of those templates that looks up and adds the category name to the products array which is created here (products.php line 440):

Code: Select all

$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get($this->config->get('config_theme') . '_product_description_length')) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $rating,
					'href'        => $this->url->link('product/product', 'product_id=' . $result['product_id'])
				);
Then you would have to output this in the .tpls.

For quick, professional OpenCart support please email info@antropy.co.uk


User avatar
Guru Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - Reigate, Surrey, United Kingdom

Post by straightlight » Thu Aug 04, 2016 11:34 pm

Unfortunately, this may require a more advanced tweaking to make this working. Followed is a working example: http://forum.opencart.com/viewtopic.php ... me#p630228 . Working on the latest module. It can definitely fit to display the category of products. :)

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by edseljay » Fri Aug 05, 2016 1:14 pm

hi paulfeakins that's what im trying to do since yesterday but still no luck im new into open cart and im not used to OOP php im more familiar in procedural php my bad but still thanks thou...

hi straightlight thanks for the link i have another question.. it is possible to put a query in template?
example

Code: Select all

$query = mysql_query("SELECT * FROM tbl_product WHERE product_no='$product_no'");
$row = mysql_fetch_assoc($query);

echo $row['product_name'];
im new in open cart and OOP but still im learing bit by bit... thanks
Last edited by straightlight on Fri Aug 05, 2016 7:11 pm, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Tue Jul 12, 2016 11:25 am

Post by straightlight » Fri Aug 05, 2016 7:15 pm

Opencart does use its own Object Registry to call the database. However, since your enquiry is about gathering a specific product from the database, I would rather suggest to build a new module rather than making generic database calls compared to the above.

Followed is the documentation on how to build a new module: http://docs.opencart.com/developer/module/ . Take note that if you're using or about to use the latest Opencart release, this topic will also be useful for new extensions / modules development: http://forum.opencart.com/viewtopic.php?f=183&t=165958

As for the Opencart Object Registry, in order to call the database as the above, you could simply use into your module as an example:

Code: Select all

$this->load->model('catalog/product');

$product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);

echo html_entity_decode($product_info['name'], ENT_QUOTES, 'UTF-8');
which the:

Code: Select all

$this->request->get['product_id']
would need to originate from your URL. :)

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by edseljay » Mon Aug 22, 2016 3:50 pm

thanks alot straightlight....

New member

Posts

Joined
Tue Jul 12, 2016 11:25 am
Who is online

Users browsing this forum: No registered users and 31 guests