久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 magento 中獲取當前產品的類別名稱(在產品

how to get category name of current product (on product detail page) in magento(如何在 magento 中獲取當前產品的類別名稱(在產品詳細信息頁面上))
本文介紹了如何在 magento 中獲取當前產品的類別名稱(在產品詳細信息頁面上)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用了以下代碼,但不適用于這種情況:

$_category_detail=Mage::registry('current_category');echo $_category_detail->getName();

得到致命錯誤:在/app/design/frontend/base/default/template/catalog/product/view.phtml中的非對象上調用成員函數getName()>

我們制作了一些過濾器并在 head.phtml 中使用以下提及的代碼:

$is_product = Mage::registry('product');如果($is_product){if(is_object(Mage::registry('current_category'))){$category_name = Mage::registry('current_category')->getName();}else{ $category_name = "";}}

但這僅在您從類別轉到產品時才有效.如果您直接訪問產品頁面,則不會顯示任何內容

解決方案

這是因為產品可以附加到多個類別.在您的情況下,當您訪問從類別頁面引用的產品頁面時,您的會話具有類別信息.但是如果您直接訪問產品頁面,Magento 無法知道您來自哪個類別,因此無法顯示特定類別,因為您的產品可以有多個類別.

但在您的情況下,如果您的產品只附加一個類別,您可以使用此代碼,它顯示產品的第一個類別名稱;

 $categoryIds = $_product->getCategoryIds();如果(計數($categoryIds)){$firstCategoryId = $categoryIds[0];$_category = Mage::getModel('catalog/category')->load($firstCategoryId);echo $_category->getName();}

I used following codes but didn't work for this case:

$_category_detail=Mage::registry('current_category');
echo $_category_detail->getName();

got Fatal error: Call to a member function getName() on a non-object in /app/design/frontend/base/default/template/catalog/product/view.phtml

we make some filters and use below mention code in head.phtml:

$is_product = Mage::registry('product');

if($is_product){ 

  if(is_object(Mage::registry('current_category'))){ 
    $category_name = Mage::registry('current_category')->getName(); 
  }
  else{ $category_name = ""; }

}

But this only works if you go from a category to a product. If you visit the product page directly nothing is being displayed

解決方案

It's because products can be attached to multiple categories. In your situation, when you visit a product page referred from a category page, your session has category information. But if you visit directly product page, Magento can not know which category you came from, so it can not show you a specific category, because your product can have multiple categories.

But in your situation, if your products are attached only one category, you can use this code, it shows first category name of product;

        $categoryIds = $_product->getCategoryIds();

        if(count($categoryIds) ){
            $firstCategoryId = $categoryIds[0];
            $_category = Mage::getModel('catalog/category')->load($firstCategoryId);

            echo $_category->getName();
        }

這篇關于如何在 magento 中獲取當前產品的類別名稱(在產品詳細信息頁面上)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: 日本理论片好看理论片 | 成人深夜福利 | 国产亚洲网站 | 色吧综合网 | 欧美激情综合五月色丁香小说 | 中文字幕亚洲精品 | 欧美一区二区三区在线视频 | 国产成人精品免高潮在线观看 | 黄色片免费看视频 | 开操网 | 欧美aaaaaaaa | 日日夜夜草 | 狠狠干五月天 | 日本网站免费在线观看 | 97免费在线观看视频 | 亚洲精品视频在线播放 | 黑色丝袜三级在线播放 | 国产美女黄色 | 在线毛片网 | 99久久精品国产毛片 | 色综合一区二区 | 久久成人高清视频 | 欧美一级二级视频 | 偷拍自拍网址 | 日韩在线视频一区 | 日韩精品视频在线 | 亚洲一区二区三区桃乃木香奈 | 日韩精品一区二区三区视频播放 | 成人免费在线视频 | 亚洲成人免费视频在线观看 | 一级黄色片免费 | 成人精品视频在线观看 | 亚洲精品日韩一区二区电影 | 国产精品久久国产精品 | 三级国产三级在线 | caoporn视频 | 午夜影院操 | 亚洲精品二区 | 免费在线一区二区 | 日本一区高清 | 精品国产精品三级精品av网址 |