php - Get Parent Category of Product in Sub-Category Open Cart -


if trying add php statement on product page template looks this:

<?php if (product has parent category = 146) { //  } elseif (product has parent category = 130) { //  } else { // } ?> 

ofcourse isnt code, how this? im trying parent category subcategory in. appreciated. thanks!

update:

each product placed in multiple categories.. should have array of parent categories. here database structure found this.

product_to_category

product_id | category_id 

category

category_id | parent_id | ... 

in catalog/controller/product/product.php find

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

add after

$cat_info = $this->model_catalog_product->getcategories($this->request->get['product_id']); // give category of product      foreach($cat_info $cat_id){     $cat = $this->model_catalog_category->getparentcategories($cat_id['category_id']);     //this give parent category               if(!empty($cat)){           foreach($cat $ids){           $this->data['path_id'][] = $ids['path_id'];             }        }     } 

in catalog/model/catalog/category.php add

public function getparentcategories($category_id) {     $query = $this->db->query("select path_id " . db_prefix . "category_path category_id = '" . (int)$category_id . "' , '" . (int)$category_id . "'!=path_id");      return $query->rows; } 

now in product.tpl

<?php  if(in_array(20,$path_id)){   echo 'exists'; }else{   echo 'not exists'; } ?> 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -