Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
  • Sign Up

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


Recommended Posts

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

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; ?>

  • +1 2
Link to post
Share on other sites

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

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

Link to post
Share on other sites

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

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

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

Link to post
Share on other sites

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

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

Link to post
Share on other sites

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

Link to post
Share on other sites

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

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

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; ?>

Link to post
Share on other sites

  • 1 year later...

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

$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; ?>

 

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

Link to post
Share on other sites

  • 2 years later...

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

Link to post
Share on other sites

  • 2 years later...
В 26.03.2013 в 11:24, Forzik сказал:

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; ?>

 

для product_form.tpl не проканало.. (((

Link to post
Share on other sites

  • 4 months later...
В 25.03.2013 в 08:30, Forzik сказал:

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

 


$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; ?>


Спасибо, работает. Для 2.3.0.2

 

$categories = $this->model_catalog_product->getCategories($product_id);
if ($categories)
  $categories_info = $this->model_catalog_category->getCategory($categories[0]['category_id']);
$data['category_id'] = $categories_info['category_id'];
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • 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.