1

I want to redirect on specific product page when i click on detail view link.

For ex. :- In grid , I click on first product detail. After I want to redirect on that specific product view page.

How to do it..?

In this image d1 is product sku . I want to do it when I clicked on view then it will redirect on d1 product view page .

enter image description here

0

May be you want product Url by using sku

==================

<?php
namespace Company1\Module1\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    protected $_productRepository;
    public function __construct(
         \Magento\Framework\App\Helper\Context$context
        \Magento\Catalog\Model\ProductRepository $productRepository,
    )
    {
        $this->_productRepository = $productRepository;
        parent::__construct($context);
    } 
    public function getProductBySku($sku)
    {
        $_product = $this->_productRepository->get($sku);
        if(!$_product){
            return false;
        }
        return $_product->getProductUrl();

    }   

}

Then add at phtml

$_helper = $this->helper('Company1\Module1\Helper\Data');
$producturl = $_helper->getProductBySku([sku]); 

at view for getting product URL

1
  • 1
    when i don't set value of sku.. still product redirect on product view page.. how is it possible? – Rohan Hapani Jun 1 '17 at 8:52

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.