Magento 2 Add Anchor link to Success or Error Message.

You can add anchor tag link in success message, an error message or any notification message in Magento 2 by addSuccess( ), addError( ) and addNotice( ) respectively.

Let’s we add a link to Shopping cart of a product successfully added to cart. Continue reading “Magento 2 Add Anchor link to Success or Error Message.”

Customer Logout programmatically in Magento 2.

Magento 2, You can log out customer programmatically by getting current customer session using the Model file, Magento\Customer\Model\Session

You need to call logout() function from above class dependency.
Call below dependency in __construct function,

Call customerLogout() function from above file to programmatically log out a customer from the current session.

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?”