Skip to content

Redirect to product page when attempting to add a specific product to cart (M2.4.3)

I have a custom Gift Card product that you need to fill out some data to be able to add to the cart. Currently, when a customer attempts to add the product from the search/category page it shows an error as it is missing data.

I have developed a plugin before the Magento/Checkout/Cart/Controller/Add controller. My idea is to check if the productId on request params matches, if so perform a redirect to the gift card product page.

I have tried several ways but it’s not working, when using the redirectFactory it just refreshes the page instead of redirecting and I have no idea why, maybe is there something I’m missing?

Anyone has ever tried anything like this?