Jump to content
Sign in to follow this  
Forzik

[Решено] узнать id категории

Recommended Posts

Подскажите как узнать id категории находясь в подробном описании товара.

Share this post


Link to post
Share on other sites

нашел в котролер добавляем

$categories = $this->model_catalog_product->getCategories($product_id);
if ($categories)
  $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$this->data['category_id] = $categories_info['category_id'];

и в view <?php echo $category_id; ?>

Share this post


Link to post
Share on other sites

В оригинальном Опенкарт - наугад (первую попавшуюся из нескольких, как постом выше).

В ocStore / SeoPro - через main_category_id.

Share this post


Link to post
Share on other sites

В оригинальном Опенкарт - наугад (первую попавшуюся из нескольких, как постом выше).

В ocStore / SeoPro - через main_category_id.

не подскажите как вывести не id main а в который находиться товар (например заходим в категорию меню(id_59) дальше суши(id_60) я выбираю товар в данной категории и в карточке товара выводиться id_60 )

Share this post


Link to post
Share on other sites

так это вам не по товару надо, а по "path=" в адресной строке.

смотрите контроллер модуля категорий.

Share this post


Link to post
Share on other sites

В контроллере товара тоже должно уже быть, там bradcrumbs выводится.

Share this post


Link to post
Share on other sites

может и не выводиться :wink:

Share this post


Link to post
Share on other sites

может и не выводиться :wink:

Во view? Может. Но вряд ли её извлечение и вычисление из контроллера вычищают.

Share this post


Link to post
Share on other sites

catalog/controller/product/product.php

после:

$this->data['points'] = $product_info['points'];

добавить:

$in_category = array();
$q = $this->db->query("SELECT p2c.`category_id`, cd.name FROM " . DB_PREFIX . "product_to_category p2c LEFT join " . DB_PREFIX . "category_description cd ON cd.category_id = p2c.`category_id` WHERE product_id = '".$this->request->get['product_id']."' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
if ($q->num_rows) {
$rows = $q->rows;
foreach ($rows as $row) {
$el = array();
$el['name'] = $row['name'];
$el['cat_id'] = $row['category_id'];
$el['href'] = $this->url->link('product/category', 'path=' . $row['category_id']);
$in_category[] = $el;
}
}
if (count($in_category)) {
$mas = array();
foreach ($in_category as $cat) {
$mas[] = $cat['cat_id'];
}
$this->data['id_category'] = implode(', ',$mas);
}

catalog/view/theme/default/template/product/product.tpl

в нужном месте добавить:

Код (text):

<b>ID категорий товара:</b> <?php echo $id_category; ?>

Share this post


Link to post
Share on other sites

нашел в котролер добавляем

$categories = $this->model_catalog_product->getCategories($product_id);
if ($categories)
   $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$this->data['category_id] = $categories_info['category_id'];
и в view <?php echo $category_id; ?>

 

спасибо, проверил все работает!  :-)

Share this post


Link to post
Share on other sites

А как вывести такой же id, только на странице каталога товаров?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

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.