How to set redirect url in Magento 2?

In Magento 2, You can redirect to any link or forcefully redirect to any link by Magento\Framework\Controller\Result\RedirectFactory object.

You can redirect from plugin or controller file to any link on the site by setPath() or setUrl() function.

Using setUrl($url) -> You need to pass link as parameter for redirect
Using setPath($path) -> You need to pass path(action URL) as parameter Continue reading “How to set redirect url in Magento 2?”

How to get Product URL from product object Magento 2?

Magento 2, You can get Product URL from Product object. You can be assigned Product URL to any page in store for a redirect to Product page.

I hope you have Product Object, Get Product Object by SKU

If you want to get Only Url Key value, You can access by $product->getUrlKey() method.

You can product full URL by getProductUrl() method.

 

How to get Base Url and Current Url Magento 2?

In Magento 2, You can get Base Url, Current Url, get Media URL, get static page URL and custom URL using Magento\Store\Model\StoreManagerInterface and Magento\Framework\UrlInterface Object.

Using StoreManager Object,
Create PHP file and Passed Dependency injection Magento\Store\Model\StoreManagerInterface, Continue reading “How to get Base Url and Current Url Magento 2?”