if(isset($_GET['path'])) {
$path = $_GET['path'];
$cats = explode('_', $path);
$cat_id = $cats[count($cats) - 1];
}
but it works only then in product page going via categories page, then going to product page via latest or special it shows error:
Notice: Undefined variable: cat_id in /home/madairstil/domains/madairstilius.lt/public_html/oc/catalog/view/theme/black_shadow/template/product/product.tpl on line 156Notice: Undefined variable: cat_id in /home/madairstil/domains/madairstilius.lt/public_html/oc/catalog/view/theme/black_shadow/template/product/product.tpl on line 156................
In product description i need make to work this function:
if(($cat_id==51) or ($cat_id==53) or ($cat_id==54) or ($cat_id==55) or ($cat_id==68) or ($cat_id==57) or ($cat_id==58) or ($cat_id==59) or ($cat_id==60) or ($cat_id==62) or ($cat_id==69) or ($cat_id==65))
{
echo "<center><div class='size_tab_border'>
<table width='100%' border='1' cellpadding='0' cellspacing='0' class='ismeru_lentele'>
<tbody>
<tr>
<th colspan='7'>
.....
Thanks for help
OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter
I found the categories id for a product are stored in the following database :
product_to_category
so it must need to read this database with a product id to get all it's categories.
I need to investigate more
EDIT:
I did this quick mod to check if a product match a category, in 3 steps :
1. EDIT /catalog/model/catalog/product.php
BEFORE
Code: Select all
public function getTotalProductsByCategoryId($category_id = 0) {
Code: Select all
//MOD START
//check if product is in given category list
public function isProductInCategories($categories_id=array(), $product_id=null) {
$categories_id = implode(',',(array)$categories_id);
$sql = "SELECT 1 FROM " . DB_PREFIX . "product_to_category p2c WHERE p2c.product_id = '".(int)$product_id."' AND p2c.category_id IN (" . $categories_id . ")";
$query = $this->db->query($sql);
return (bool)$query->num_rows;
}
//MOD END
2. EDITcatalog/controller/product/product.php
BEFORE
Code: Select all
$product_info = $this->model_catalog_product->getProduct($product_id);
Code: Select all
// MOD START
$catlist = array(51,52,53);
$this->data['isProductInCategories'] = $this->model_catalog_product->isProductInCategories($catlist, $product_id);
// MOD END
3. EDIT catalog/view/theme/default/product.tpl
USE ANYWHERE
Code: Select all
<?php
// MOD START
if ( $isProductInCategories )
/* do things here*/
// MOD END
?>
Code: Select all
//To match multiples cat :
$catlist = array(1,4,5,6);
Code: Select all
//To match one unique cat :
$catlist = array(4);
one quick solution compared to the long solution above would be by modifying your catalog/model/catalog/product.php file.
Find in the getProducts method:
Code: Select all
$sql = "SELECT p.product_id, (SELECT
Code: Select all
$sql = "SELECT p.product_id, " . (!empty($data['filter_category_id']) ? (!empty($data['filter_sub_category']) ? "`cp`.`path_id` AS `category_id`," : "`p2c`.`category_id` AS `category_id`,") : "") . " (SELECT
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Thank you so much for your reply, I am not really a programmer. I don’t really know how to make this work. How do i pull out the path_id or the category_id from each controllers by using the getProducts method??
What I am trying to do is display extra information on product page for only selected categories.
SO far this is what I have
In catalog/controller/product/product.php
Code: Select all
if (isset ($this->request->get['path'])) {
$path = $this->request->get['path'];
$cats = explode('_', $path);
$data['cat_id'] = $cats[count($cats) - 1];
}
Code: Select all
<?php if (isset($cat_id) && $cat_id == '20'){ ?>
<!-- My content here… -->
<?php } ?>
But when I open the same product via Latest Module I get this error.
Notice: Undefined variable: cat_id in/var/www/vhosts/shop/catalog/view/theme/default/template/product/product.tpl on line 282
I get this error because I guess there is no path ID in the URL when products are opened via latest module.
Could you please tell me how can I fix this issue? Could you provide a simple example so I could follow please??
Thank you for Help
Karen
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Sorry I am a little confused here, are you saying that i should include this condition below in the following file
catalog/controller/module/latest.php
Code: Select all
if (isset ($this->request->get['path'])) {
$path = $this->request->get['path'];
$cats = explode('_', $path);
$data['cat_id'] = $cats[count($cats) - 1];
}
But again the extra information is not appearing on the product page when i view the product page via latest module.
Dedication and passion goes to those who are able to push and merge a project.
Regards,
Straightlight
Programmer / Opencart Tester
Users browsing this forum: No registered users and 337 guests