How to navigate NEXT and PREVIOUS products in product detail page. I tried with below code, it's showing the NEXT and PREVIOUS product's link but it's not changing the product.
Please do the needful.
I refered this code from arun
function getNextProductUrl($category, $currentProduct) {
$productPositions = $category->getProductsPosition();
asort($productPositions);
$sortedCatProductIds = array_keys($productPositions);
$currentProductCategoryIndex = @array_search($currentProduct->getId(), $sortedCatProductIds);
$nextProductIds = array_slice($sortedCatProductIds, $currentProductCategoryIndex + 1, count($sortedCatProductIds)); //+1 for next product, -1 for previous product
foreach ($nextProductIds as $productId) {
$product = Mage::getModel('catalog/product')->load($productId);
if ($product && $product->getId() && $product->isVisibleInCatalog() && $product->isVisibleInSiteVisibility()) {
return $product->getProductUrl();
}
}
return false;
}
This is how I am calling the url.
<a href="<?php $this->helper('Company1\Module1\Helper\Data')->getPreviousProduct() ?>">Previouse</a>
<a href="<?php $this->helper('Company1\Module1\Helper\Data')->getNextProduct() ?>">Next</a>