0

I need Rewrites URL in Magento 2 by query. I tried below code.

<?php
namespace Dev\Core\Helper;

use Magento\Framework\App\Helper\Context;
use Magento\Framework\App\ResourceConnection;

class Cart extends \Magento\Framework\Url\Helper\Data {
    public function getRewritedUrl($productId) 
    {
        $select = $this->_connection->select()
             ->from('url_rewrite', 'request_path')->where('entity_id = ?', $productId);
        try 
        {
            $res = $this->_connection->fetchAll($select);
            return $res[1]['request_path'];
        } catch (Exception $e) 
        {
            //log or handle exception
        }
    }
}

But i m not getting rewrites URL. I need only by query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.