在magento下,如何判断是分类查看页面还是产品查看页面

下面的代码回答了这个问题

 // if this is a product view page
            if (Mage::registry('product')) {
                // get collection of categories this product is associated with
                $categories = Mage::registry('product')->getCategoryCollection()
                    ->setPage(1, 1)

 

 if (!$this->_currentCategoryKey) {
            $category = Mage::registry('current_category');
            if ($category) {
                $this->_currentCategoryKey = $category->getPath();


须知,这两个变量不一定存在.至少目前的版本中是这样的.尽管说有了产品我们就能找到分类.但是

Mage::registry('current_category')
不一定能获取到当前分类.因为,如果一个产品不是通过列表,而是通过搜索结果而被访问,那么由于MAGENTO中,一个产品可能属于多个分类,那么就不可能有一个当前分类了.这或许是为什么magento中调用
Mage::registry('current_category')
不一定能有返回分类的原因.

你可能感兴趣的:(产品,Magento)