how to add another HTML element in top.links after list element? NOT adding link - magento

How can i add another element after <li>
So i can get this tree structure <ul><li><span><a>Logout</a></span></li></ul>
Currently my rendered html is looking like this. I want to have span element to do bit more with logout. I have tried a lot but no luck. Please help. Thank you
<ul class="links">
<li class="first last">
Logout
</li>
</ul>
layout to top.links is
<customer_logged_in>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer">
<label>Logout</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title>
<prepare/>
<urlParams/>
<position>2</position>
<liParams></liParams>
<aParams>class="logout-link"</aParams>
</action>
<action method="removeLinkByUrl">
<url helper="customer/getRegisterUrl" />
</action>
</reference>
If i am changing the links.phtml then change will apply for all the links or else i need to put if else in there but i needed it only for logout. so what is the best way to do that?
Is this achievable using addLinks method?

You can do this using the beforeText and afterText parameters, like this:
<action method="addLink" translate="label title" module="customer">
<label>Logout</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title>
<prepare/>
<urlParams/>
<position>2</position>
<liParams></liParams>
<aParams>class="logout-link"</aParams>
<beforeText><![CDATA[<span>]]></beforeText>
<afterText><![CDATA[</span>]]></afterText>
</action>
Which will modify your link to look something like this:
<li class="first last">
<span>Logout</span>
</li>

You can create your own template (a copy of links.phtml) and apply it only for Top Links.
Do it like this in your theme's local.xml:
<default>
<reference name="top.links">
<action method="setTemplate">
<template>page/template/my_links.phtml</template>
</action>
</reference>
<default>
Then copy page/template/links.phtml and rename it to page/template/my_links.phtml and do whatever you need inside that new template file. It will be only used to render Top Links, not for any other links

Related

Cant find footer links in Magento

I am trying to change the links in the footer of a Magento page.
In the footer there is the following HTML:
<div class="col1 gapRight floatLeft">
<h2>Customer Service</h2>
<ul>
<li>About Us</li>
<li>Customer Service</li>
<li class="last privacy">Privacy Policy</li>
<li class="last privacy">Contact Us</li>
</ul>
<ul class="links">
<li class="first" ><a href="/index.php/catalog/seo_sitemap/category/" title="Site Map" >Site Map</a></li>
<li ><a href="/index.php/catalogsearch/term/popular/" title="Search Terms" >Search Terms</a></li>
<li ><a href="/index.php/catalogsearch/advanced/" title="Advanced Search" >Advanced Search</a></li>
<li ><a href="/index.php/sales/guest/form/" title="Orders and Returns" >Orders and Returns</a></li>
<li class=" last" ><a href="/index.php/contacts/" title="Contact Us" >Contact Us</a></li>
</ul>
</div>
The first ul list is defined as a CMS Static Block called footer_links.
Can anyone tell me where I can find the second ul list?
Ive googled about and I keep getting reffered back to the Static Blocks. This second ul list is definitely not a Static Block (Ive gone as far as removing all the static blocks and this list is still there). Where else could it be defined?
Your template is using the core footer links, stored in XML files.
Open your Magento folder, go to app/design/frontend/. When you are in your template folder open the Layout folder. You may need to create and overwrite if they don't exist.
Site Map
In catalog.xml file:
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalog" ifconfig="catalog/seo/site_map">
<label>Site Map</label><url helper="catalog/map/getCategoryUrl" />
<title>Site Map</title>
</action>
</reference><br>
Search Terms and Advanced Search
In catalogsearch.xml:
<reference name="footer_links">
<action method="addLink" translate="label title" module="catalogsearch" ifconfig="catalog/seo/search_terms">
<label>Search Terms</label><url helper="catalogsearch/getSearchTermUrl" />
<title>Search Terms</title>
</action>
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</reference>
Contact Us
In contacts.xml file:
<reference name="footer_links">
<action method="addLink" translate="label title" module="contacts" ifconfig="contacts/contacts/enabled">
<label>Contact Us</label>
<url>contacts</url>
<title>Contact Us</title>
<prepare>true</prepare>
</action>
</reference>

My Account display only after login

I would like to change top links
in the default set magento display
My Account | My Wishlist | My Cart | Checkout | Log in
i need to change top link that to show My Account link only after when user is LogIn
thx for help
in customer.xml at your theme before it is look like
<default>
<!-- Mage_Customer -->
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
</reference>
</default>
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
Remove my account link from default tag to Customer_logged_in
Change it with
After change at customer.xml
<default>
<!-- Mage_Customer -->
<reference name="top.links">
</reference>
</default>
<!--
Load this update on every page when customer is logged in
-->
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
hope this will sure help you.
<customer_logged_in>
<reference name="top.links">
<action method="addLink" translate="label title">
<label>Your Account</label>
<url helper="customer/getAccountUrl" />
<prepare/>
<urlParams/>
<liParams>
<id>header-account-link</id>
</liParams>
<aParams/>
<beforeText/>
<afterText/>
</action>
</reference>
We can do that easily Suppose We need to show only My-Account link after sign In,
we have to override the authorization.phtml file in custom theme and we can put our logic based on our requirement.
app/design/frontend/Namespace/Custom theme/Magento_Customer/templates/account/link/ authorization.phtml
After overriding this file we can put our login -
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** #var \Magento\Customer\Block\Account\AuthorizationLink $block */
$objectManagerlogin = \Magento\Framework\App\ObjectManager::getInstance();
$baseurl = $objectManagerlogin->get('Magento\Store\Model\StoreManagerInterface')->getStore(0)->getBaseUrl();
$dataPostParam = '';
if ($block->isLoggedIn()) {
$dataPostParam = sprintf(" data-post='%s'", $block->getPostParams());
}
?>
<?php if($block->isLoggedIn() && $baseurl || $block->isLoggedIn() ) : ?>
<li class="authorization-link" >
Sign Out
</li>
<li class="authorization-link custom-top-link-myaccount-mobile" >
My Account
</li>
<?php else : ?>
<li class="authorization-link" data-label="<?= $block->escapeHtmlAttr(__('or')) ?>">
<a <?= /* #noEscape */ $block->getLinkAttributes() ?><?= /* #noEscape */ $dataPostParam ?>>
<?= $block->escapeHtml($block->getLabel()) ?>
</a>
</li>
<?php endif; ?>
I hope this will help you in Magento2, for managing my account section based own need

How to add css to login,register and logout link separately?

I am trying to have different css for login register and login links. But as they are being added using template_links block and they are automatically rendered and no template file for specific one, I am unable to achieve this.
<block type="page/template_links" name="account.links" as="accountLinks"/>
At the moment I tried changing the css but obviously css rules are getting assigned to all of it at the same time.
How can I achieve this please suggest something. Thank you
can I do that using layout?
<customer_logged_in>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>2</position></action>
<action method="removeLinkByUrl"><url helper="customer/getRegisterUrl" /></action>
</reference>
</customer_logged_in>
<!--
Load this update on every page when customer is logged out
-->
<customer_logged_out>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer"><label>Login</label><url helper="customer/getLoginUrl"/><title>Login</title><prepare/><urlParams/><position>1</position></action>
<action method="removeLinkByUrl" ifconfig="enterprise_invitation/general/registration_required_invitation"><url helper="customer/getRegisterUrl" /></action>
<!-- <action method="addLink" translate="label title" module="customer"><label>register</label><url helper="customer/getRegisterUrl" /><title>register</title><prepare/><urlParams/><position>100</position><li/><a/><before_text> or </before_text><after_text>.</after_text></action> -->
</reference>
<remove name="wishlist_sidebar"></remove>
<remove name="reorder"></remove>
<remove name="top.menu" />
</customer_logged_out>
<!--
Layout for customer login page
-->
<customer_account_login translate="label">
<label>Customer Account Login Form</label>
<!-- Mage_Customer -->
<remove name="right"/>
<remove name="left"/>
<reference name="head">
<action method="addJs"><script>jquery/jquery.js</script></action>
</reference>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml"/>
</reference>
</customer_account_login>
current theme links look like this
------EDIT-----
After placing class in aparam It is still applying same old css rules as in the html showing no class element. I have place the .logout-link class in the same theme in custom and style.css but still no luck. It is not finding this class and not even it is showing in chrome developer tools.
<customer_logged_in>
<reference name="account.links">
<action method="addLink" translate="label title" module="customer">
<label>Log Out</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title>
<prepare/>
<urlParams/>
<position>2</position>
<aParams>class="logout-link"</aParams>
</action>
<action method="removeLinkByUrl"><url helper="customer/getRegisterUrl" /></action>
</reference>
<div class="header-links-wrapper">
<ul class="links">
<li class="first last">Log Out</li>
</ul>
</div>
You can apply a class with the addLink method using the following:
<liParams/>
<aParams>class="My Class Name"</aParams>
<beforeText/>
<afterText/>
So for example, to add a class to your logout link, you can do this:
<action method="addLink" translate="label title" module="customer">
<label>Log Out</label>
<url helper="customer/getLogoutUrl"/>
<title>Log Out</title><prepare/>
<urlParams/>
<position>2</position>
<liParams/>
<aParams>class="logout-link"</aParams>
<beforeText/>
<afterText/>
</action>
Then you just add a css definition for logout-link

Remove navigation links from My Account

I am running Mage 1.5.0.1 and I am trying to remove the navigation links from the My Account section.
My local.xml has the following which works fine:
<customer_account>
<reference name="root">
<action method="setTemplate"><template>page/staticpage.phtml</template></action>
</reference>
<reference name="left">
<remove name="cart_sidebar" />
<remove name="catalog.compare.sidebar" />
</reference>
</customer_account>
When I try to add the following code the system throws and error:
<reference name="customer_account_navigation">
<action method="removeLinkByName"><name>recurring_profiles</name></action>
<action method="removeLinkByName"><name>billing_agreements</name></action>
</reference>
Error
Invalid method Mage_Customer_Block_Account_Navigation::removeLinkByName
I saw this function in 1.4, is it not supported anymore or am I doing something wrong?
I had a similar problem, and I didn't want to comment out addLink node because we want to implement our changes in local.xml only. Ended up writing a small module to do it:
app\etc\modules\Stackoverflow_Customerlinks.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Stackoverflow_Customerlinks>
<active>true</active>
<codePool>local</codePool>
</Stackoverflow_Customerlinks>
</modules>
</config>
app\code\local\Stackoverflow\Customerlinks\Block\Account\Navigation.php:
<?php
class Stackoverflow_Customerlinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation {
public function removeLinkByName($name) {
unset($this->_links[$name]);
}
}
app\code\local\Stackoverflow\Customerlinks\etc\config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<global>
<blocks>
<customer>
<rewrite>
<account_navigation>Stackoverflow_Customerlinks_Block_Account_Navigation</account_navigation>
</rewrite>
</customer>
</blocks>
</global>
</config>
After that, you can simply make the changes through local.xml:
<customer_account>
<reference name="customer_account_navigation">
<action method="removeLinkByName"><name>recurring_profiles</name></action>
<action method="removeLinkByName"><name>billing_agreements</name></action>
</reference>
</customer_account>
Have fun :)
By default, we don't have such method as "removeLink". Therefore, the trick is to remove the whole block using "unsetChild" approach and add the needed links block back with our own links added to it in local.xml
<customer_account translate="label">
<reference name="left">
<!--Unset the whole block then add back later-->
<action method="unsetChild"><name>customer_account_navigation</name></action>
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
<action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
<action method="addLink" translate="label" module="sales"><name>orders</name><path>sales/order/history/</path><label>My Orders</label></action>
<action method="addLink" translate="label" module="review"><name>reviews</name><path>review/customer</path><label>My Product Reviews</label></action>
<action method="addLink" translate="label" module="wishlist" ifconfig="wishlist/general/active"><name>wishlist</name><path>wishlist/</path><label>My Favorite</label></action>
<action method="addLink" translate="label" module="newsletter"><name>newsletter</name><path>newsletter/manage/</path><label>Newsletter Subscriptions</label></action>
</block>
<remove name="catalog.compare.sidebar"/>
</reference>
</customer_account>
Just to inform you guys about all the links in the navigation menu.
To remove all links in local.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<customer_account>
<reference name="customer_account_navigation" >
<!-- remove the link using your custom method -->
<action method="removeLinkByName"><name>recurring_profiles</name></action>
<action method="removeLinkByName"><name>billing_agreements</name></action>
<action method="removeLinkByName"><name>reviews</name></action>
<action method="removeLinkByName"><name>downloadable_products</name></action>
<action method="removeLinkByName"><name>OAuth Customer Tokens</name></action>
<action method="removeLinkByName"><name>account</name></action>
<action method="removeLinkByName"><name>account_edit</name></action>
<action method="removeLinkByName"><name>address_book</name></action>
<action method="removeLinkByName"><name>orders</name></action>
<action method="removeLinkByName"><name>tags</name></action>
<action method="removeLinkByName"><name>wishlist</name></action>
<action method="removeLinkByName"><name>newsletter</name></action>
</reference>
</customer_account>
</layout>
Thanks for your answer Daniel Sloof
You can use that:
<customer_account>
<action method="unsetChild"><name>customer_account_navigation</name></action>
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
...
</block>
</customer_account>
Rewriting is not solution...
I just refactored account dashboard links and removed CSS nth-child selectors as I had before and instead changed app/design/frontend/default/your_theme/template/customer/account/navigation.phtml to this
<div class="block block-account">
<div class="block-title">
<strong><span><?php echo $this->__('My Account'); ?></span></strong>
</div>
<div class="block-content">
<ul>
<?php $_links = $this->getLinks(); ?>
<?php $_index = 1; ?>
<?php $_count = count($_links);
unset($_links['recurring_profiles']);
unset($_links['billing_agreements']);
unset($_links['reviews']);
unset($_links['tags']);
unset($_links['OAuth Customer Tokens']);
unset($_links['downloadable_products']);
?>
<?php foreach ($_links as $_link): ?>
<?php $_last = ($_index++ >= $_count); ?>
<?php if ($this->isActive($_link)): ?>
<li class="current<?php echo ($_last ? ' last' : '') ?>"><strong><?php echo $_link->getLabel() ?></strong></li>
<?php else: ?>
<li<?php echo ($_last ? ' class="last"' : '') ?>><?php echo $_link->getLabel() ?></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
basically unset any unwanted links.
There are other various xml file that refer to <reference name="customer_account_navigation"> where you can copy the xml file to your layout directory and comment out the addLink node other than that, I see a removeLinkByUrl that you might try instead.
You can also, override declaration by empty link - without define 'path' and 'label', direcly in local.xml:
<customer_account>
<reference name="customer_account_navigation">
<action method="addLink"><name>tags</name></action>
<action method="addLink"><name>newsletter</name></action>
</reference>
</customer_account>
Go to app/design/frontend/YourPackageName/YourThemeName/layout/, create a sales/ directory if there isn't one, and create an empty file or directory named billing_agreement.xml and recurring_profile.xml.
Cleanest method ever, no custom functions, no CSS hacking, no logic in template files.
This completely hides the Billing Agreements and Recurring Profiles features from the user.
This module makes functionality ordering or show the links of my own, does not make for layout and phtml overwrites the block and makes all the logic there.
http://www.magentocommerce.com/magento-connect/customer-navigation.html
The cleanest solution would be to make an overwrite of the box and add a method to remove links from layout.
My Account Navigation links comes from customer.xml file.
<block type="customer/account_navigation" name="customer_account_navigation" before="-" template="customer/account/navigation.phtml">
<action method="addLink" translate="label" module="customer"><name>account</name><path>customer/account/</path><label>Account Dashboard</label></action>
<action method="addLink" translate="label" module="customer"><name>account_edit</name><path>customer/account/edit/</path><label>Account Information</label></action>
<action method="addLink" translate="label" module="customer"><name>address_book</name><path>customer/address/</path><label>Address Book</label></action>
</block>
My apperoach is to bring power of css and avoid hevy code modifications.
E.G.
/* CUSTOMER ACCOUNT LEFT NAV DISABLER */
.block-content li:nth-child(4),
.block-content li:nth-child(5),
.block-content li:nth-child(6),
.block-content li:nth-child(8){display: none;}
Obviously change selectors to your themes customer navigation li, and use li:nth-child() sudo with number between parenthesis which you want to remove.
Use comments in customer.xml as well just in case u don't forget what you did 6 month down the line.

magento Baseurl from helper function

I want to get custom URL from magento helper in this way:
<action
method="addLink"
translate="label title"
module="customer">
<label>About Us</label>
<url
helper="customer/getAboutUsUrl">
about
</url>
<title>About Us</title>
<prepare/>
<urlParams/>
<position>1</position>
</action>
So what I did is define a function getAboutUsUrl() under local directory within Customer Helper Directory. But it does not return the base url as I expected.
What do I have to do to get the baseurl with about us link?
Thanks
You should use cms/page/getPageUrl helper method and pass CMS-page identifier as its parameter like in the following example:
<action
method="addLink"
translate="label title"
module="customer">
<label>About Us</label>
<url helper="cms/page/getPageUrl"><pageId>about</pageId></url>
<title>About Us</title>
<prepare/>
<position>1</position>
</action>

Resources