Sometimes you may require to change the default Magento URLs of some of the pages in order to handle and recognize them in a better way. The use of fancy URL leads you to initiate rewrite for them.
Here we have come up with a quick solution to change URL of checkout page. From this, you can change URLs of wishlist page and customers’ my account page as well.
Basic checkout page URL is something like:
domain.com/checkout
domain.com/checkout/#shipping
domain.com/checkout/#payment
Step 1: First, we need to create “module.xml” file inside extension the below directory.
app\code\Vendor\Extension\etc
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Vendor_Extension" setup_version="1.0.0" Schema_version="1.0.0"> <sequence> <module name="Magento_Catalog"/> </sequence> </module> </config>
Step 2: after that, we need to create “routes.xml” file inside extension the below directory.
app\code\Vendor\Extension\etc\frontend
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd"> <router id="standard"> <route id="customcheckout" frontName="customcheckout"> <module name="Vendor_Extension" /> </route> </router> </config>
Sometimes you may face issue with mini cart update or with AJAX cart extension as you have made changes in route file of Magento. This will require you to fix up the section reloading while using AJAX.
Easily create Custom URL for checkout page in #magento2 https://t.co/fWDH05u5Xi
— MageComp (@theMageComp) February 15, 2016
Step 3: After that, we need to create “sections.xml” file inside extension the below directory.
app\code\Vendor\Extension\etc\frontend
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd"> <action name="customcheckout/index/index"> <section name="cart"/> <section name="customer"/> <section name="wishlist"/> </action> </config>
Step 4 : lastly, we need to create “Index.php” file inside extension the below directory.
app\code\Vendor\Extension\Controller\Index
<?php namespace Vendor\Extension\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; class Index extends Action { public function execute() { // Redirect to Magento's default checkout return $this->_redirect('checkout'); } }
Hope you have found this effective rewrite trick useful and it will definitely help you creating fancy URLs in Magento.
Feel free to contact if you have any queries regarding. We would appreciate your comments and suggestions.
Hi,
I create a order programmability but my mini-cart cache not showing item in this and when i click on this showing cart is empty.
So how can i refresh mini-cart cache?
Hi Prince Yadav,
Generally in Magento 1, mini cart can be updated using following code. You can try implementing it in your script.
$miniCart = $this->getLayout()
->createBlock('checkout/cart_sidebar')
->addItemRender('simple', 'checkout/cart_item_renderer', 'checkout/cart/sidebar/default.phtml')
->addItemRender('configurable', 'checkout/cart_item_renderer_configurable', 'checkout/cart/sidebar/default.phtml')
->setTemplate('checkout/cart/cartheader.phtml')
->toHtml();
And if you are using AJAX mini cart, use following code:
if (typeof extendFunctions !== "undefined" && typeof extendFunctions.showMiniCart !== "undefined") {
extendFunctions.showMiniCart.each(function(item_function, index) {
if(jQuery.isFunction(item_function)) {
item_function(data);
}
})
}
Drop us again if you need more help.
Hello How to update mini cart in magento 2 actually we created quick view when tou added product to cart then
mini cart is not updated after page refresh it shows can you tell how do it in jquery or code
Try placing this code in ajax success method,
if (typeof extendFunctions !== "undefined" && typeof extendFunctions.showMiniCart !== "undefined") {
extendFunctions.showMiniCart.each(function(item_function, index) {
if(jQuery.isFunction(item_function)) {
item_function(data);
}
})
}
if(mobilecheck()) {
jQuery('html, body').animate({ scrollTop: 0 }, 'slow');
}
Hello guys,
I got that answer
https://magento.stackexchange.com/questions/100615/magento-2-how-can-refresh-minicart-cache-after-clear-cart-session-and-place-orde
Glad to hear 🙂
its not working can exaplin in details?
Would it be possible to update snippets, since they appear to be empty ?
I need to make
domain.com/checkout/#shipping -> domain.com/checkout/step/shipping or something in that direction