TransWikia.com

How to redirect on specific product page in magento2

Magento Asked by Rohan Hapani on December 2, 2021

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

One Answer

May be you want product Url by using sku

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

<?php
namespace Company1Module1Helper;
class Data extends MagentoFrameworkAppHelperAbstractHelper
{
    protected $_productRepository;
    public function __construct(
         MagentoFrameworkAppHelperContext$context
        MagentoCatalogModelProductRepository $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('Company1Module1HelperData');
$producturl = $_helper->getProductBySku([sku]); 

at view for getting product URL

Answered by Amit Bera on December 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP