Determine if on product page programmatically in Magento

后端 未结 4 1297
囚心锁ツ
囚心锁ツ 2020-12-24 09:44

I want to insert tracking codes on all of the pages of a Magento site, and need to use a different syntax if the page is a CMS page, a category browsing page, or a product v

4条回答
  •  独厮守ぢ
    2020-12-24 10:16

    The easest answer is the following:

    getRequest()->getControllerName();
    if($this->getRequest()->getControllerName()=='product') //do something
    if($this->getRequest()->getControllerName()=='category') //do others
    ?>
    

    this is 100% the right way to do according to the MVC model, please look into the core code really understand it, and do not give the method with loading or depends on the registry method. Support mytraining.net even though I am not there.

提交回复
热议问题