Изменение Заголовков Страниц Обзора продуктов Magento


Я нашел учебник, который, похоже, работает только на очень старой версии Magento, яt меняет название с НАЗВАНИЯ ПРОДУКТА на.

( Название продукта) Отзыв - (Название отзыва)

Вместо этого он просто отображает старый URL-адрес по умолчанию.

<?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(),

Ложь, Маг::приложение()->getStore()->getId())); } верните $это->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

Кто-нибудь когда-нибудь придумывал способ отображения "(Название продукта) Отзыв - (Название отзыва)" для каждого отзыва в мета-заголовке на Magento 1.9.?

Author: Amit Bera, 2015-10-13

2 answers

Согласно as, ваш вопрос. вы хотите установить review page title в ( Название продукта) Отзыв - (Название отзыва)`.

Во-первых, вы работаете над неправильным классом для задания заголовка страницы обзора. Это должно быть Mage_Review_Block_Product_View

Этого можно легко достичь с помощью двух процессов.

  • Использование события magento core_block_abstract_to_html_before/review_product_list
  • Использование класса перезаписи Mage_Review_Block_Product_View

Затем с помощью Mage::app()->getLayout()->getBlock('head')->setTitle($title); Вы зададите заголовок страницы.

Выпуск:

Но вы получите логическую проблему всякий раз, когда у продукта будет более одного отзыва. В тот раз ты can use first review title

Если вы хотите достичь с помощью класса перезаписи класса, то вы можете попробовать

<?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();
    }
}
 1
Author: Amit Bera, 2015-10-13 14:06:28

Попробуйте добавить приведенный выше код в viewAction() в

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

Изменить: заменить это

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();
    }

С

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();
    }

Не редактируйте основной файл (вы никогда не должны этого делать), переопределите его, а затем внесите изменения Я не пробовал, это то место, где оно должно быть, возможно, вам придется немного подправить код

 0
Author: Vishwas Bhatnagar, 2015-10-13 13:08:06