how to redirect to shopping cart page by clicking proceed to checkout button in magento2 . And which file need to add in our custom module
1 Answer
To redirect to the shopping cart by clicking on 'proceed-to-checkout button' in the minicart you can edit 'Magento/Checkout/Block/Cart/Sidebar.php' function 'getConfig' and edit 'checkoutUrl'
Here is the way to do it in your custom module
1. In your di.xml
Add a plugin
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Block\Cart\Sidebar">
<plugin name="UpdateMinicartCheckoutLInk"
type="Connector\Integration\Plugin\UpdateMinicartCheckoutLInk"/>
</type>
</config>
2. Create the plugin file
In the folder Plugin create UpdateMinicartCheckoutLink.php
<?php
namespace Vendor\Magento\Plugin;
use Magento\Checkout\Block\Cart\Sidebar;
class UpdateMinicartCheckoutLink
{
/**
* @param Sidebar $subject
* @param array $result
* @return array
*/
public function afterGetConfig(Sidebar $subject, array $result): array
{
$result['checkoutUrl'] = $subject->getShoppingCartUrl();
return $result;
}
}
3. Flush magento cache
bin/magento c:f