Reputation: 61
I am trying to change Magento toplink wishlist button url.
At the moment it is generated in wishlist.xml
with
<reference name="top.links">
<block type="wishlist/links" name="wishlist_link" />
<action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
</reference>
This leads me to merry chase in core files with no result.
What I want to do is for the button to direct to /guestwishlist/
instead of /wishlist/
(which in addition atm, for some reason leads to wishlist/index/share).
I've read most of the relevant guides and answers since worked on it for hours.
Just need to change that single button url to go to /guestwishlist/
.
EDIT> This is how my top.links.phtml looks like
<?php if($toplinks && is_array($toplinks)): ?>
<ul class="links">
<?php echo $this->getChildHtml() ?>
<?php foreach($toplinks as $_toplink): ?>
<li<?php if($_toplink['first']||$_toplink['last']): ?> class="<?php if($_toplink['first']): ?>first<?php endif; ?><?php if($_toplink['last']): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_toplink['liParams'] ?>><?php echo $_toplink['beforeText'] ?><a <?php echo $_toplink['aParams'] ?>><?php echo $_toplink['innerText'] ?></a><?php echo $_toplink['afterText'] ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Upvotes: 0
Views: 4018
Reputation: 61
The core solution works yeah but I had to keep in mind that I only want to change the link for guests, for customers the link had to stay the same.
Specifics to my site used the template/page/links.phtml
file instead of top.links.phtml
mentioned by Blastfreak so I had to two everything twice :P
I used the solution of checking for the current item in loop.
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php if ($_link->gettype() == 'wishlist/links' && (!$this->helper('customer')->isLoggedIn())): ?>
<?php echo '<li class="first last"><a href="/guestwishlist" title="My Wishlist">My Wishlist</a></li>' ?>
<?php else: ?>
<?php echo $_link->toHtml() ?>
<?php endif;?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php endforeach; ?>
</ul>
Had to echo some extra classes for style.
Upvotes: 0
Reputation: 2214
To change wishlist url in proper magento way you need to override:
app/code/core/Mage/Wishlist/Block/Links.php
in local or community codePool.
In this file you will find code like this:
protected function _toHtml()
{
if ($this->helper('wishlist')->isAllow()) {
$text = $this->_createLabel($this->_getItemCount());
$this->_label = $text;
$this->_title = $text;
$this->_url = $this->getUrl('wishlist');
return parent::_toHtml();
}
return '';
}
Change
$this->_url = $this->getUrl('wishlist');
to
$this->_url = $this->getUrl('guestwishlist');
and you are done.. :)
Now you must create or have a module for guestwishlist.
Upvotes: 1
Reputation: 9045
You can change the wishlist url to custom url by editing template/page/html/top.links.phtml
There is a foreach in which you can check if current looping item is wishlist, change the default url to your custom URL.
This will make sure whatever changes you are making are only limited to frontend rendering of content and also no need to override any core files.
Upvotes: 1