1

I have found a tutorial, which seems to work only on very old version of Magento, it changes title from PRODUCT NAME TO.

(Product Name) Review - (Review Title)

It just displays old default url instead .

<?php

class Mage_Review_Block_View extends Mage_Catalog_Block_Product_Abstract
{


      public function __construct()
        {
            parent::__construct();
            $this->setTemplate('review/view.phtml');
        }

        /**
         * Retrieve current product model from registry
         *
         * @return Mage_Catalog_Model_Product
         */
        public function getProductData()
    {
        return Mage::registry('current_product');
    }

    /**
     * Retrieve current review model from registry
     *
     * @return Mage_Review_Model_Review
     */
    public function getReviewData()
    {
        return Mage::registry('current_review');
    }

    /**
     * Prepare link to review list for current product
     *
     * @return string
     */
    public function getBackUrl()
    {
        return Mage::getUrl('*/*/list', array('id' => $this->getProductData()->getId()));
    }

    /**
     * Retrieve collection of ratings
     *
     * @return Mage_Rating_Model_Mysql4_Rating_Option_Vote_Collection
     */
    public function getRating()
    {
        if( !$this->getRatingCollection() ) {
            $ratingCollection = Mage::getModel('rating/rating_option_vote')
                ->getResourceCollection()
                ->setReviewFilter($this->getReviewId())
                ->setStoreFilter(Mage::app()->getStore()->getId())
                ->addRatingInfo(Mage::app()->getStore()->getId())
                ->load();
            $this->setRatingCollection( ( $ratingCollection->getSize() ) ? $ratingCollection : false );
        }
        return $this->getRatingCollection();
    }

    /**
     * Retrieve rating summary for current product
     *
     * @return string
     */
    public function getRatingSummary()
    {
        if( !$this->getRatingSummaryCache() ) {
            $this->setRatingSummaryCache(Mage::getModel('rating/rating')->getEntitySummary($this->getProductData()->getId()));
        }
        return $this->getRatingSummaryCache();
    }

    /**
     * Retrieve total review count for current product
     *
     * @return string
     */
    public function getTotalReviews()
    {
        if( !$this->getTotalReviewsCache() ) {
            $this->setTotalReviewsCache(Mage::getModel('review/review')->getTotalReviews($this->getProductData()->getId(),

false, Mage::app()->getStore()->getId())); } return $this->getTotalReviewsCache(); }

    /**
     * Format date in long format
     *
     * @param string $date
     * @return string
     */
    public function dateFormat($date)
    {
        return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_LONG);
    }
}

    /**
     * Set Page title
     */
    protected function _prepareLayout()
    {
        $headBlock = $this->getLayout()->getBlock('head');
        if ($headBlock) 
        {
          $title = array();
          if ($product = $this->getProductData()) 
          {
              $title[] = $product->getName() . ' Review';
          }

          if ($review = $this->getReviewData()) 
          {
              $title[] = $review->getTitle();
          }

          $title = implode(' - ', $title);
            $headBlock->setTitle($title);
        }

        return parent::_prepareLayout();
    }
}

http://icebergcommerce.com/software/blog/iss/article/seo-tip-changing-magento-product-review-page-titles/#comments

Has anyone ever figured out a way to display "(Product Name) Review - (Review Title)" for each review in meta title on Magento 1.9.?

1

As per as,your question. you want to set review page title to (Product Name) Review - (Review Title)`.

First, you have working on wrong class for set title for review page. It should be Mage_Review_Block_Product_View

This can be easily achieve by two process.

  • Using magento event core_block_abstract_to_html_before/review_product_list
  • Using rewrite class Mage_Review_Block_Product_View

Then using Mage::app()->getLayout()->getBlock('head')->setTitle($title); You will set the title of page.

Issue:

But you will get logic issue whenever a product have more than one review. That time you can use first review title

If you want to achieve using class rewrite class then you can try

<?php
class [ModuleNameSpace]_[ModuleName]_Block_Review_Product_View  extends Mage_Review_Block_Product_View{

   protected function _prepareLayout(){

      // format (Product Name) Review - (Review Title)

      $title=$this->getProduct()->getName(); 
      $title=$title.' Review ';
          // get first time of review from collection
          if($this->getReviewsCollection()->getSize()){
              $firstReview=$this->getReviewsCollection()->getFirstItem();
              $title=$title.'- '.$firstReview->getTitle();
          }
       $this->getLayout()->getBlock('head')->setTitle($title);

     return parent::_prepareLayout();
    }
}
  • Hey, wow, thank you! Shall I just add that code to /public_html/app/code/core/Mage/Review/controllers/ProductController.php? As I tried and titles still did not update – Vygantas Oct 13 '15 at 15:05
  • yes it will works .It is very bad idea to work on core file on file..Use block class rewrite & event – Amit Bera Oct 13 '15 at 15:10
0

Try add the above code to viewAction() in

app/code/core/Mage/Review/controllers/ProductController.php

Edit : replace this

public function viewAction()
    {
        $review = $this->_loadReview((int) $this->getRequest()->getParam('id'));
        if (!$review) {
            $this->_forward('noroute');
            return;
        }

        $product = $this->_loadProduct($review->getEntityPkValue());
        if (!$product) {
            $this->_forward('noroute');
            return;
        }

        $this->loadLayout();
        $this->_initLayoutMessages('review/session');
        $this->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }

With

public function viewAction()
    {
        $review = $this->_loadReview((int) $this->getRequest()->getParam('id'));
        if (!$review) {
            $this->_forward('noroute');
            return;
        }

        $product = $this->_loadProduct($review->getEntityPkValue());
        if (!$product) {
            $this->_forward('noroute');
            return;
        }
        $headBlock = $this->getLayout()->getBlock('head');
        if ($headBlock)
        {
            $title = array();
            if ($product = $this->getProductData())
            {
                $title[] = $product->getName() . ' Review';
            }

            if ($review = $this->getReviewData())
            {
                $title[] = $review->getTitle();
            }

            $title = implode(' - ', $title);
            $headBlock->setTitle($title);
        }
        $this->loadLayout();
        $this->_initLayoutMessages('review/session');
        $this->_initLayoutMessages('catalog/session');
        $this->renderLayout();
    }

Do not edit the Core file( you should never do it) , override it then make the changes I have not tried it , this i the place it should be you might have to tweak a code a little

  • Parse error: syntax error, unexpected 'protected' (T_PROTECTED) in /home/x/public_html/app/code/core/Mage/Review/controllers/ProductController.php on line 315 That line: protected function _initProductLayout($product) – Vygantas Oct 13 '15 at 13:01
  • Just add $headBlock = $this->getLayout()->getBlock('head'); if ($headBlock) { $title = array(); if ($product = $this->getProductData()) { $title[] = $product->getName() . ' Review'; } if ($review = $this->getReviewData()) { $title[] = $review->getTitle(); } $title = implode(' - ', $title); $headBlock->setTitle($title); } not the whole function before $this->loadLayout(); See my edit in answer – Vishwas Bhatnagar Oct 13 '15 at 13:05
  • Thanks! While I no longer get any errors, title still goes to magento default – Vygantas Oct 13 '15 at 13:17
  • @try debugging the code is flow is going in if block or is product object is loaded , it will show the the default page only title will be changed – Vishwas Bhatnagar Oct 13 '15 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.