Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento 2, Magento Development, Customization, Extension Development and Integration, Optimization, SEO and Responsive Design

Magento rel=prev and rel=next issue solved on pagination

In my previous post there is a simple code for adding rel=prev and rel=next on magento product listing page. After long time i see there is a problem when we filter product. So suppose there is 50 products this code add rel="next" but after filtering the result if there is only 5 product in listing, it will also add rel="next". So i changed my code as following and now it is working fine. May be help someone else.

step1: Go to my previous post if you haven't added code.
Step2: Replace following code in my old post

$prodCol = $category->getProductCollection()->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', array('in' => array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));

with

$prodCol = "";
if ($layer = Mage::getSingleton('catalog/layer')) {
    $prodCol = $layer->getProductCollection();
}
else
{
    $prodCol = $category->getProductCollection()->addAttributeToFilter('status', 1)->addAttributeToFilter('visibility', array('in' => array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)));
}


Please support us, Like us on Facebook.

0 comments:

Post a Comment

 

Copyright @ 2017 HKBlog.