Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Показывать главную категорию товара в списке товаров


 Share

Recommended Posts

Форумчане, хелп ми плиз, может у кого в закладках есть линк на решение вопроса?

 

Хочу в категориях показывать главную категорию товара (дочернюю) под названием товара.

Я нашел способ как показывать родительскую категорию, но не могу додуматься как полулить дочернюю.

 

Выкладываю свой код на вскакий случай

$this->load->model('catalog/product');
				
$cat = $this->model_catalog_product->getCategories($result['product_id']);

$category_name = $this->model_catalog_category->getCategory($categ[0]['category_id']);

$podcat = $category_name['name'];

$data['products'][] = array(
   'podcat'       => $podcat,

 

Link to comment
Share on other sites


Какая у вас спотому чторка опенкарт?
В ОcStore есть икой параметр, как главная категория товара. Не помню точно, есть икое в других спотому чторках..
Если у вас Осtore, можно в могдель товара вот икую функцию добавить:

public function getProductMainCategoryId($product_id) {
	$query = $this->db->query("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "' AND main_category = '1' LIMIT 1");

	return ($query->num_rows ? (int)$query->row['category_id'] : 0);
}

И тогда уже им, ггде у вас этот код:

$this->load->model('catalog/product');
				
$main_cat_id = $this->model_catalog_product->getProductMainCategoryId($result['product_id']);

if ($main_cat_id) {
	$category_name = $this->model_catalog_category->getCategory($main_cat_id);
} else {
	$category_name = 'Нет категории';
}

Об этот главной категории товара вы говорите?

Edited by Prooksius
  • +1 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.