Magento 2 Redirect shopping cart link on message notification in iframe
-
06-02-2021 - |
Solution
If you can manage the iframe content, you should change the link redirection and manage the parent location with it.
The way to do it is: window.top.location.href = "/your-url-link-redirect";
Check: https://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action
OTHER TIPS
I had a same issue while I was working. I checked and found that there is template file for displaying message for product is added successfully.
Message is:
You added PRODUCT_NAME to your shopping cart.
File: vendor/magento/module-checkout/view/frontend/templates/messages/addCartSuccessMessage.phtml
I have checked code it's as below:
<?= $block->escapeHtml(__(
'You added %1 to your <a href="%2">shopping cart</a>.',
$block->getData('product_name'),
$block->getData('cart_url')
), ['a']);
I have copied that file into custom theme:
app/design/frontend/VENDOR/THEME_NAME/Magento_Checkout/templates/messages/addCartSuccessMessage.phtml
Changed code as below:
<?= $block->escapeHtml(__(
'You added %1 to your <a href="%2" target="_top">shopping cart</a>.',
$block->getData('product_name'),
$block->getData('cart_url')
), ['a']);
After that I have checked that it's working as expected. Clicking on the shopping cart link, page redirects to cart page in the browser rather then in the iframe.