My Account display only after login - magento

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

Related

Magento 1.9 breadcrumbs always empty

I'm working on a magento ecommerce, I'm not the one who configured it or anything, I'm just doing his CSS, however, the site does not display the breadcrumbs.
Inside the "page / html / breadcrumbs.phtml" file I made a var_dump in the $ crumbs variable and it is always empty.
In the XML only in one situation the breadcrumbs is displayed in the frontend, when I enter the code inside the "default" tag if I put this code inside "customer_account_login" nothing will be displayed on the front.
Code of breadcrumbs.phtml:
<?php if($crumbs && is_array($crumbs)): ?>
<div class="breadcrumbs">
<ul>
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<li class="<?php echo $_crumbName ?>">
<?php if($_crumbInfo['link']): ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
Here part of code of "customer.xml"
<?xml version="1.0"?>
<layout version="0.1.0">
<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>
<!-- HERE BREADCRUMBS DISPLAYS ON ALL PAGES THE SAME CONTENT "HOME / MY ACCOUNT" -->
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>My Account</crumbName>
<crumbInfo><label>My Account</label><title>My Account</title><link>/customer/account/</link></crumbInfo>
</action>
</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>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
</reference>
</customer_logged_in>
<!-- Load this update on every page when customer is logged out -->
<customer_logged_out>
<reference name="top.links">
<action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
</reference>
<remove name="reorder"></remove>
</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="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>
If I move the breadcrumbs code from "< default >" to the "< customer_account_login translate="label" >" for example, all screens returns the breadcrumbs as null.
I have no idea what's going on. I just wish all the screens had their breadcrumbs being displayed.
Check that breadcrumbs are actually enabled in the back end admin panel like below.

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

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

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

Custom options doesnt appear on view.phtml for custom product type

I have maden custom product type (hotel). It has custom options tab in the backend.
I have added some custom options in the certain product(hotel). I have added html to view.phtml of my custom theme to output custom options.
<?php if ($this->hasOptions()):?> <?php echo $this->getChildHtml('container1','', true, true) ?> <?php endif;?>
Also I have added block to my layout.
<block type="core/template_facade" name="product.info.container1" as="container1">
<action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
<action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
<action method="append"><block>product.info.options.wrapper</block></action>
<action method="append"><block>product.info.options.wrapper.bottom</block></action>
</block>
<block type="core/template_facade" name="product.info.container2" as="container2">
<action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
<action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
<action method="append"><block>product.info.options.wrapper</block></action>
<action method="append"><block>product.info.options.wrapper.bottom</block></action>
</block>
<action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if> <key>alias_in_layout</key><key>options_container</key></action>
<action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action>
But <?php echo $this->getChildHtml('container1','', true, true) ?> return empty.
How can I show options block?
I have solved this issue and created function in helper to render custom options. Code goes below:
public function getHotelCustomOptionsHtml(Mage_Catalog_Model_Product $product)
{
$blockOption = Mage::app()->getLayout()->createBlock("Mage_Catalog_Block_Product_View_Options");
$blockOption->addOptionRenderer("default","catalog/product_view_options_type_default","catalog/product/view/options/type/default.phtml");
$blockOption->addOptionRenderer("text","catalog/product_view_options_type_text","inchoo_catalog/product/view/options/type/text.phtml");
$blockOption->addOptionRenderer("file","catalog/product_view_options_type_file","catalog/product/view/options/type/file.phtml");
$blockOption->addOptionRenderer("select","catalog/product_view_options_type_select","catalog/product/view/options/type/select.phtml");
$blockOption->addOptionRenderer("date","catalog/product_view_options_type_date","catalog/product/view/options/type/date.phtml") ;
$blockOptionsHtml = null;
if($product->getTypeId() =="hotel")
{
$blockOption->setProduct($product);
if($product->getOptions())
{
foreach ($product->getOptions() as $o)
{
$blockOptionsHtml .= $blockOption->getOptionHtml($o);
};
}
}
return $blockOptionsHtml;
}

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.

Resources