Changing the Wishlist Toplink URL in Magento
The wishlist functionality is a core feature of Magento that allows customers to save products for later purchase. By default, Magento generates the wishlist link using the wishlist.xml layout reference:
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link" />
<action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
</reference>
This references the wishlist/links block, which is responsible for rendering the wishlist link. However, if you want to redirect this link to a different URL, such as /guestwishlist/, you need to modify the block’s configuration.
Understanding the Wishlist Link Block
The wishlist link block is rendered using the top.links.phtml template file located under app/code/core/Mage/Cms/Block/Page. The relevant part of this file is as follows:
<?php foreach($toplinks as $_toplink): ?>
<li<?php if($_toplink['first'] || $_toplink['last']): ?> class="<%= $_toplink['first'] ? 'first' : '' %><%= $_toplink['last'] ? ' last' : '' %>"
<?php echo $_toplink['liParams'] ?>>
<?php echo $_toplink['beforeText'] ?>
<a href="<?php echo $this->getUrl($_toplink['url']) ?>" <?php echo $_toplink['aParams'] ?>>
<?php echo $_toplink['innerText'] ?>
</a>
<?php echo $_toplink['afterText'] ?>
</li>
<?php endforeach; ?>
As you can see, the href attribute of the wishlist link is generated using $this->getUrl($_toplink['url']). This means that the actual URL for the wishlist link comes from the url property of the top link.
Modifying the Wishlist Link URL
To change the URL of the wishlist link, you need to modify the url property of the wishlist top link. In Magento 1.x, this is stored in the core_config_data table and can be updated via an SQL query:
UPDATE core_config_data SET value = 'guestwishlist/' WHERE path = 'catalog/wishlist/links';
Alternatively, you can modify it programmatically using a module or observer event. Here’s how you might do this in a module configuration file:
<config>
<global>
<catalog>
<WishListOptions>
<linkUrl>guestwishlist/</linkUrl>
</WishListOptions>
</catalog>
</global>
</config>
This changes the linkUrl property of the wishlist configuration, which is the URL for the wishlist link.
Conclusion
Changing the URL of the Magento wishlist toplink involves modifying the core_config_data table or configuring your module to set a new value for the url property. Be sure to thoroughly test your changes after updating the database or module configuration.
Remember, altering core files is not recommended as it can cause issues with future upgrades. If possible, use Magento’s module system to override and extend core functionality.
For more advanced customizations and a deeper understanding of the wishlist component, I recommend checking out Laravel Company’s guide on extending Magento functionality.
Resources