久久久久久久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)
主站蜘蛛池模板: 欧美国产日韩一区二区三区 | 国产乱码精品一区二区三区中文 | 久久久久久网站 | 一区二区中文 | 久久久久久久夜 | 欧美日一区 | 欧美成年黄网站色视频 | 欧美久久久久 | 国产精品免费一区二区三区四区 | 久热久热 | 久久久国产一区二区三区四区小说 | 午夜精品久久 | 欧美日韩中文字幕 | 国产精品视频久久 | 欧美精品一区二区免费 | 久久精品视频一区二区 | 国产黄色大片在线观看 | 狠狠干综合视频 | 欧美激情在线播放 | 毛片一区 | 夜夜艹天天干 | 久久久精品国产 | 国产1区 | 亚洲中午字幕 | 成人夜晚看av| 成人国产精品色哟哟 | 99热在线播放 | 超碰导航 | 成人免费视频网站 | 国产成人aⅴ | 国产亚洲精品久久久久动 | 亚洲视频欧美视频 | 国产中文字幕av | 国产精品精品视频一区二区三区 | 国产一区二区在线视频 | 精品亚洲一区二区三区 | 91视频网址 | 日韩三区在线观看 | 国产精品一区二区av | 日韩在线免费 | 天天操夜夜操 |