在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')
不一定能有返回分类的原因.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值