сейчас напишу, как сделать.
UPD
решение для товаров, которые входят только в одну категорию
Обновление от 2011.02.08 - 12:01
Всем, кто использовал мой метод, настоятельно рекомендую заменить старый код на новый.
+ исправлена ошибка проявляющаяся при большой вложенности категорий;
+ исправлено формирование ссылок на категории в "крошках".
1. Открываем файл
catalog/controller/product/product.phpменяем
if (isset($this->request->get['path'])) {
$path = '';
foreach (explode('_', $this->request->get['path']) as $path_id) {
$category_info = $this->model_catalog_category->getCategory($path_id);
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
if ($category_info) {
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
'text' => $category_info['name'],
'separator' => $this->language->get('text_separator')
);
}
}
}на
/* webme - fix for product breadcrumbs - part_#1 - start */
$wRestoreBreadcrumbs = "0";
/* webme - fix for product breadcrumbs - part_#1 - end */
if (isset($this->request->get['path'])) {
$path = '';
foreach (explode('_', $this->request->get['path']) as $path_id) {
$category_info = $this->model_catalog_category->getCategory($path_id);
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
if ($category_info) {
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $path),
'text' => $category_info['name'],
'separator' => $this->language->get('text_separator')
);
}
}
} else { /* webme - fix for product breadcrumbs - part_#2 - start */
$wRestoreBreadcrumbs = "1";
} /* webme - fix for product breadcrumbs - part_#2 - end */мотаем ниже.перед
$product_info = $this->model_catalog_product->getProduct($product_id);вставляем
/* webme - fix for product breadcrumbs - part_#3 - start */
if ($wRestoreBreadcrumbs == "1") {
$wcat = $this->model_catalog_product->getCategories($product_id);
if (count($wcat) == 1) {
$w_category_id = $wcat['0']['category_id'];
$w_BreadCrumbs = $this->model_catalog_product->wbm_getPath($w_category_id);
$w_totalCrumbs = count($w_BreadCrumbs);
foreach ($w_BreadCrumbs as $pos => $w_BreadCrumb) {
$w_BreadCrumb_href = "";
$w_i = 0;
for($w_i = 0; $w_i <= $pos; $w_i++) {
if (empty($w_BreadCrumb_href)) {
$w_BreadCrumb_href .= $w_BreadCrumbs[$w_i]["category_id"];
} else {
$w_BreadCrumb_href .= "_".$w_BreadCrumbs[$w_i]["category_id"];
}
}
$this->document->breadcrumbs[] = array(
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $w_BreadCrumb_href),
'text' => $w_BreadCrumb['name'],
'separator' => $this->language->get('text_separator')
);
}
}
}
/* webme - fix for product breadcrumbs - part_#3 - end */сохраняем, закрываем.2. Открываем файл
catalog/model/catalog/product.phpв конец файла, перед
}
?>вставляем
/* webme - fix for product breadcrumbs - part_#1 - start */
public function wbm_getPath($category_id) {
$productPath = array();
$result = $this->wbm_getProductCategoryInfo($category_id);
$productPath2 = array();
if ($result['parent_id'] > 0) {
$productPath2 = $this->wbm_getPath($result['parent_id']);
foreach ($productPath2 as $productPath2_item) {
array_push($productPath, $productPath2_item);
}
}
array_push($productPath, $result);
return $productPath;
}
public function wbm_getProductCategoryInfo($catID) {
$sql = "SELECT DISTINCT c.category_id as category_id, c.parent_id as parent_id, cd.name as name FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.category_id = '" . (int)$catID . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'";
$query = $this->db->query($sql);
return $query->row;
}
public function wbm_getParentCategory($catID) {
$sql = "SELECT DISTINCT c.parent_id as parent_id, cd.name as name FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.parent_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) WHERE c.category_id = '" . (int)$catID . "' AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND c.status = '1'";
$query = $this->db->query($sql);
return $query->row;
}
/* webme - fix for product breadcrumbs - part_#1 - end */сохраняем, закрываем.3. Пользуемся :)
Возможно в модель запихнул лишнюю функцию (которая не используется).
Однако ужасно устал, поэтому принимайте "как есть".