Magento Redirect To Checkout After Adding To Cart An Easy How-To Guide

Magento Redirect To Checkout After Adding To Cart: An Easy How-To Guide

by Van Nguyen

“How to set up a quick buying process for customers to increase conversion rates and reduce abandoned rate”  is always an issue most of Magento store owners take much concern.

When customers add products to their cart by clicking “Add to Cart,” they will be redirected to the shopping cart page to view their selected products. There’s an option by Magento default for admins to choose to send the user to the cart or leave them on the page. However, this step takes time, and there is also a list of selected items displayed on the checkout page.

Therefore, to save time for customers, some shop Magento owners consider skipping the shopping cart page and directly redirecting customers to the checkout page. This makes customers buy products faster without waiting for loading the shopping cart page which can cause them to abandon their carts.

alt=“abandoned-cart-magento-sites-before-redirect-cart-to-checkout”

High abandoned cart rate due to long purchase process on Magento websites

In this blog post, we will introduce you (especially administrators of Magento online stores and developers) the way we can disable the shopping cart page to improve the buying process in your site.

Create a Magento redirect to checkout by using Event observer method

After products are added to carts,  it is a default process that the site will redirect to the shopping cart page. So how to disable loading the shopping cart page and redirect to Magento checkout page after “Add to cart” even when they access intentionally to the URL of the shopping cart?

The easiest way is by using the event observer method. It means that you take the “controller_action_predispatch_checkout_cart_index” event to redirect 301 from the cart page to the checkout page. This is the “fired” event before loading the “checkout_cart_index” page.

This following code is added to the declaration of event observer in the configuration file:

frontend>
<events>
 <controller_action_predispatch_checkout_cart_index>
 <observers>
<customRedir>
<class>disablecart/observer</class>
 <method>disableCart</method>
 </customRedir>
</observers>
</controller_action_predispatch_checkout_cart_index>
</events>
</frontend>

Enable or Disable module

You may want to enable or disable module in some cases, so you can add a Store Config in the backend to easily use. You create the config/system.xml file:

<?xml version="1.0"?>
<config>
<sections>
<gotocheckout  translate="label" module="disablecart">                    
<label>Redirect Cart To Checkout</label>
<tab>general</tab>
<frontend_type>text</frontend_type>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>        
<groups>
<general translate="label">
<label>General</label>
<frontend_type>text</frontend_type>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
<fields>
<enable translate="label">
<label>Enable</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_yesno</source_model>
<sort_order>0</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</enable>
</fields>
</general>
</groups>
</gotocheckout>
</sections>
</config>

Results

After finishing these code, you can see “Redirect Cart To Checkout” in the Configuration and then you can choose Yes or No to enable or disable it.

alt=“magento-redirect-cart-to-checkout”

Redirect cart to checkout page in Magento sites

In the Model/Observer.php file, we declare disableCart

   public function disableCart(Varien_Event_Observer $observer){
   $storeId = Mage::app()->getStore()->getId();
   if(Mage::getStoreConfig('gotocheckout/general/enable', $storeId)){
    $controller = $observer->getControllerAction();
    $controller->getResponse()
    ->setRedirect(Mage::getUrl('checkout/onepage'),301)
    ->sendResponse();
     }
     return;
     }

Tips: If the website uses the One Step Check Out module, it may have to redirect to the other URL of the checkout: ->setRedirect(Mage::getUrl(‘one step checkout’),301)

Finally, when you finish the setup, you need to clear out the cache and reload the page to test.

If you do not want to take much time for carrying out these things, you can quickly get the full functions by downloading the full version of the Disable cart module [DOWNLOAD HERE]Our module will provide you with all tasks without any efforts.

If our blog has brought you valuable knowledge, please Like and Subscribe to our blog to get the latest shares for your Magento site.

Moreover, let’s check out more latest Magento 2 extensions by BSS Commerce to install for your website and improve shopping experience as well as increase sales effectively!

Next Reading Suggestions

© 2019 BSS Commerce owned by THANH CONG INTER ., JSC. All Rights Reserved.
Business registration certificate no. 0106064469 issued by Hanoi Department of Planning and Investment on 19 December 2019.
Legal Representative: Mr. Nguyen Quang Trung.