Get Base Url in Model or Plugin file Magento 2.

You can get the base URL of the store in the controller file using Store Manager Interface.

To Retrieve the Base URL of the current store, You need to instantiate constructor in your controller file,

Check below code snippet for getting base URL, Continue reading “Get Base Url in Model or Plugin file Magento 2.”

Get Product URL by product SKU Magento 2.

You can get the product URL by SKU in Magento 2 using ProductRepositoryInterface.

Using Magento\Catalog\Api\ProductRepositoryInterface you need to call the get($sku) method of the interface.

You can get product URL by store view level from Product URL by specific store view in Magento

If Product SKU not found, throws an error, Continue reading “Get Product URL by product SKU Magento 2.”

Url Encode and Decode using Magento 2.

You can encode and decode the URL using Magento 2 with native functionality.

Using Url Encode, they encode the base64_encode() for URLs encoding using encode() function.

Using Url Decode, they decode the base64_decode() for URLs decoding. Continue reading “Url Encode and Decode using Magento 2.”