Jump to content
Sign in to follow this  

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

Recommended Posts



Никак не найду решение: как находясь в карточке товара поставить ссылку на родительскую категорию?

Share this post

Link to post
Share on other sites

Сделал так

 // $categories = explode('_', $this->request->get['path']);
 // print_r($categories);


 // получаем ID категории для генерации правильного URL и сортируем по родительской категории, чтобы родительская шла всегда первой
 $categories_for_url = $this->db->query("
 SELECT `t1`.`category_id` FROM `" . DB_PREFIX . "product_to_category` as `t1`
 LEFT JOIN `" . DB_PREFIX . "category` as `t2` ON `t1`.`category_id` = `t2`.`category_id`
 WHERE `t1`.`product_id`='" . $product_id . "'
 ORDER BY `t2`.`parent_id` ASC

 if($categories_for_url->num_rows > 0)
	$category_id = '';
	foreach($categories_for_url->rows as $category)
		$category_id .= $category['category_id'] . '_';
	$category_id = trim($category_id, '_');
	// echo $category_id;
	// echo $this->url->link('product/product', 'path=' . $category_id . '&product_id=' . $product_id);
	// echo $this->url->link('product/product', 'path=' . $category_id);
	$cat_info = $this->model_catalog_category->getCategory($category_id);
	$category_link = '<a href="'.$this->url->link('product/product', 'path=' . $category_id).'">'.$cat_info['name'].'</a>';
	// echo $category_link;

Share this post

Link to post
Share on other sites

Тему можно закрывать

Share this post

Link to post
Share on other sites

вы такую нецензурщину накодили... добавьте товар в две категории или в под(подподпод)категорию.

если у вас нет $this->request->get['path'] - у вас opencart и перешли в товар из модуля. телодвижений надо больше для достижения результата.

если у вас ocStore - в настройках магазина чпу "seopro" и формируйте ссылку по последнему id в $this->request->get['path'].

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.

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.