Domanda

I'd like to implement custom URL for our Magento's basket. Magento out-of-the-box url paht is /checkout/cart but client request /checkout/bag.

I tried to somehow * URL rewrite management in backend - it works, but I need to update all occurences in code to new url, because $this->getUrl('checkout/cart') doesnt translate into checkout/bag * also I tried to follow some advices from http://alanstorm.com/magento_dispatch_rewrites_intro but basicaly it doesnt help me too. * also I tried example from this post http://phprelated.myworks.ro/two-add-to-cart-buttons-with-different-redirect-actions-at-once-in-magnto/

So, is there any way how can I rewrite translation from path 'checkout/cart' into checkout/bag without updating all ocurrences in our templates and classes $this->getUrl('checkout/cart')

Any solution depending on web server architecture are not the ultimate solution.

È stato utile?

Soluzione

I found solution

1) I rewrited model core/url to have desired output

EDIT 1 - sample implementation https://gist.github.com/jaromirmuller/132cdd9378e5b1018170

2) Added url rewrite into config.xml which rewrites url path from /checkout/bag to /checkout/cart

    <global>
      <rewrite>
        <mynamespace_mymodule_checkout_cart>
            <from><![CDATA[#^/checkout/bag#]]></from>
            <to>/checkout/cart</to>
        </mynamespace_mymodule_checkout_cart>
         </rewrite>
    </global>

3) Added url rewrite into Catalog > URL rewrite management which handles if anyone comes to /checkout/cart then he's redirected to /checkout/bag paht which is correct.

These 3 points makes site consisten and working without any issues. That's the easises way without rewriting tons of templates and classes.

Altri suggerimenti

The way Url Rewrites work means that you have some url test.com/some on the page and when you click on it, you'll get test.com/some2 instead. So Rewrites do not change the actual anchor link - they change the destination of that link to the new recipient.

There is no easy solution which will change all of the anchor links to the new ones (aside from parsing and replacing links on each page - which is not preferable).

So if you want to leave anchor links as they are and get the new Url after user clicks on the link, you should go with Url Rewrites. Though if you want to change the actual links on the page, you need to search for all occurrences and change them manually.

Mage::getUrl() is not a fabric which operates with aliases (like Mage::getModel()) - you'll get from it what you have inserted, and the only way to change the outcome Url is to change income parameters.

You can do it using apache url rewrites. Something like

RewriteRule ^/checkout/cart(.*)$ /checkout/bag$1 [R=301,NC,L]

This answer works for changing the wishlist name by changing the frontend routers in app/etc/local.xml. Maybe it can be adapted for your uses?

Change wishlist url in magento

To manage more url translation You can use this module: http://www.magentocommerce.com/magento-connect/catalog/product/view/id/18160/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top