3

What would be the proper way to rewrite/translate Magento 2 checkout and user account URL's to make them localized for my language?

1. Checkout

Current checkout URL's are:

domain.com/checkout

domain.com/checkout/#shipping

domain.com/checkout/#payment

2. User account

Current user account url's are:

domain.com/customer

domain.com/checkout/account/login

domain.com/checkout/account/edit

other similar user account URL's...

5

You can do this by redefining the route. Create a new module that has a module.xml like so...

<?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]_[ModuleName]" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Checkout"/>
        </sequence>
    </module>
</config>

Then in your etc/frontend/routes.xml...

<?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="checkout" frontName="custom-checkout-url">
            <module name="Magento_Checkout" />
        </route>
    </router>
</config>

I have not looked in to other ways to do it so not sure if it is the best way but i have tested it and it worked just fine.

EDIT

Because the route has now changed you need to fix up the section reloading when doing ajax. You do this with a "sections.xml" located in etc/frontend that will look something like...

<?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="custom-checkout-url/cart/add">
        <section name="cart"/>
    </action>
</config>

Take a look in the Magento/Catalog/etc/frontend/sections.xml for all the actions you will need to override.

  • Great, that works for /checkout. What about #payment and #shipping hash? – g5wx Jan 26 '16 at 10:07
  • Note: with this solution checkout works but minicart doesn't update. – g5wx Jan 27 '16 at 10:23
  • So i create another xml (sections.xml) within the same etc/frontend of the module as where the routes.xml is located? – g5wx Jan 27 '16 at 12:37
  • Never mind, it's working. I'm also updating other url's via this solution (customer, wishilist) and so far so good. Thanks :) – g5wx Jan 28 '16 at 9:09
1

The easiest way is to use Magento's URL rewrite feature from your store admin section.

Here are the steps to do so for the domain.com/checkout url:

  1. In the admin menu go to Marketing -> URL Rewrites.
  2. Click the Add URL rewrite button.
  3. Select the "Custom" URL rewrite type
  4. Select the store/language for which you want to create the custom url (which will replace domain.com/checkout etc.)
  5. In the requested path field enter your new custom url, e.g. new-checkout-url (without leading slahes)
  6. In the target path field enter the current/default checkout url: checkout
  7. Clear the cache and you're done (maybe also wait for cron to reindex the urls)

The same can be done for any other in-built Magento urls (like domain.com/contact or domain.com/cart).

This is a multi-store and multi-language friendly solution and is better and easier than the accepted answer in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.