Magento- add new menu item inside the module - magento

currently I want to add a new menu link on the menu tab, but can it be done without changing other module template, but just add inside my module? The reason I want to do like this is because I hope when I disable my module the menu link also will be gone.
page.xml(other module layout file )
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
</block>
<block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
<label>Page Header</label>
<action method="setElementClass"><value>top-container</value></action>
</block>
</block>
referral.xml(my module)
???
What should I do?
topmenu.phtml
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php $active = is_numeric(stripos($_SERVER['REQUEST_URI'], 'aboutus')) ? 'active' : ''; ?>
<li class="level0 nav-2 last level-top <?php echo $active; ?>">
<a class="level-top" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>aboutus">
<span>About Us</span>
</a>
</li>
<?php echo $_menu ?>
<?php $active = is_numeric(stripos($_SERVER['REQUEST_URI'], 'redemption/store')) ? 'active' : ''; ?>
<li class="level0 nav-2 last level-top <?php echo $active; ?>">
<a class="level-top" href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>redemption/store">
<span>Redemption Store</span>
</a>
</li>

That looks like a custom navigation to me, there's no way out of the box to add items to the main navigation (none category items anyway).
by default it will only show categories, so yours looks like it's probably hard coded into the template.
Having worked with a lot of modules and themes I would be VERY surprised if it's a custom theme with the added ability to add links through either XML config, or admin options.
can you post some code from your topmenu.phtml file for me and then I can adivse the best action for you.

for this you have to write Navigation class in your custom module that will extends Mage_Catalog_Block_Navigation in that class is a function (renderCategoriesMenuHtml) that you need to override in your local navigation class.
but the problem is, in real time users mostly have different themes and they change classes etc this can conflict in design implementation.

Related

Magento: No navbar

I am new to Magento. I want to create a menu with different pages, but I don't have a navigation bar on top. How do I add a navigationbar?
This is my topmenu.phtml:
<?php $_menu = $this->getHtml('level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('top-navbar-before')->toHtml() ?>
<?php echo $_menu ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('top-navbar-after')->toHtml() ?>
</ul>
</div>
<?php endif ?>
Here is the static block:
Still no navbar. The page.xml has these lines:
<block type="core/text_list" name="top.menu" as="topMenu" translate="label">
<label>Navigation Bar</label>
<block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml">
<block type="page/html_topmenu_renderer" name="catalog.topnav.renderer" template="page/html/topmenu/renderer.phtml"/>
</block>
</block>
This should be a simple task. Anyone here with ideas?
you can also see the navigation menu bar into the navigation.php file
app\code\core\Mage\Catalog\Block\navigation.php
this file also need to display navigation menubar.
You should override the _getHtml() method in Mage_Page_Block_Html_Topmenu class.
Here are the steps:
create your app/code/local/Mage/Page/Block/Html/Topmenu/Custom.php
put inside class Mage_Page_Block_Html_Topmenu_Custom extends Mage_Page_Block_Html_Topmenu
copy the _getHtml() method from app/code/code/Mage/Page/Block/Html/Topmenu.php and customize it as needed
edit your app/design/frontend/your_theme/default/layout/page.xml and
replace <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/> with <block type="page/html_topmenu_custom" name="catalog.topnav" template="page/html/topmenu.phtml"/>

Product thumbnail in sales email

I want to add products image in my sales template. Do I need to add some code or is it an option in magento.
Yes we need to customize our email templates, based on the themes email template style were differed. For your question refer the sales.xml layout file under the layout folder of current theme and notice the Email layouts section from there we can know which files are play the role. Now come to your answer.
<sales_email_order_items>
<block type="sales/order_email_items" name="items" template="email/order/items.phtml">
<action method="addItemRender"><type>default</type><block>sales/order_email_items_order_default</block><template>email/order/items/order/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>sales/order_email_items_order_grouped</block><template>email/order/items/order/default.phtml</template></action>
<block type="core/template" name="order_totals_wrapper" as="order_totals" template="email/order/totals/wrapper.phtml">
<block type="sales/order_totals" name="order_totals" template="sales/order/totals.phtml">
<action method="setLabelProperties"><value>colspan="3" align="right" style="padding:3px 9px"</value></action>
<action method="setValueProperties"><value>align="right" style="padding:3px 9px"</value></action>
<block type="tax/sales_order_tax" name="tax" template="tax/order/tax.phtml">
<action method="setIsPlaneMode"><value>1</value></action>
</block>
</block>
</block>
</block>
<block type="core/text_list" name="additional.product.info" />
</sales_email_order_items>
This is sample layout section for a email template
sales_email_order_items node have the wrapper for items email/order/items.phtml. In this file you can add the below lines for show thumbnail header.
<th>Tumbnail</th>
And for render the items used the email/order/items/order/default.phtml
Open this default.phtml file and add the below lines under the
<tbody><tr>
tag
<td>
<?php if ($_item->hasProductUrl()):?>
<a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getProductName()) ?>" class="product-image">
<?php endif;?>
<img src="<?php echo $_item->getProductThumbnail()->resize(180); ?>" alt="<?php echo $this->escapeHtml($_item->getProductName()) ?>" />
<?php if ($_item->hasProductUrl()):?>
</a>
<?php endif;?>
</td>
Now the sales order email will send with product image.
For better solution make a duplicate copy of these files and give these file names in layout file. Because do not editing core files.

how to remove the 'home' link from top menu in magento?

I have a website where i don't want the 'home' link in top menu, I just want to remove or disable it...I have tried this link
http://www.magentocommerce.com/boards/viewthread/60059/
but it didn't find any code in top.phtml (app > design > frontend > default (or whatever theme you have) > catalog > navigation > top.phtml ) like-
<li> yada /home statement </li>
or
<li><?php echo $this->__('Home') ?></li>
I have only
<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?>
<?php if($_menu): ?>
<div class="nav-container">
<ul id="nav">
<?php echo $_menu ?>
</ul>
</div>
<?php endif ?>
Please give a solution.
I already tried using xml in customer.xml file but may be I didn't use it in proper xml file or proper code.
<reference name="top.links">
<action method="removeLinkByUrl">
<url helper="core/url/getHomeUrl" />
</action>
</reference>
Try this in the local.xml file of your active theme.
<default>
<reference name="root">
<reference name="top.links">
<action method="removeLinkByUrl"><url helper="core/url/getHomeUrl"/></action>
</reference>
</reference>
</default>
As a hack you can hide it using css
find the class and add .class { display:none }
At last, I figured it out.The Home link is there because of the menu plugin(custom responsive menu'). I disabled it from backend.

Magento calling a catalog/product_list type block from product page

I'm using a simple custom block to list products from a given category in the side bar. It works fine when called as
<block type="catalog/product_list" before="-" name="product.leftnav" as="product.leftnav" template="catalog/product/training_leftlist.phtml" />
On all pages except the product pages, where it causes an error (I get the item page with the 404 page below it).
Is there a better block type I should be using, or a different way of calling it on the product page?
Template file is:
<?php
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',1)
->addStoreFilter()
->addCategoryFilter(Mage::getModel('catalog/category')->load(12));
$products->setPageSize(4)->setCurPage(1);
$_helper = $this->helper('catalog/output');
Then print the items with something like
if(count($products>0)) echo "<ul>";
foreach($products as $_product):?>
<li>
<h2 class="product-name"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h2>
</li>
<?php endforeach;?>
<?php if(count($products>0)) echo "</ul>";?>
The answer turned out to use a different block type for each place.
For the non-product pages
<block type="catalog/product_list" before="-" name="product.leftnav" as="product.leftnav" template="catalog/product/training_leftlist.phtml" />
Then for the Product pages use type="catalog/product_list_related". Remembering to remove the above too, e.g:
<catalog_product_view>
<remove name="product.leftnav" />
<!-- Left bar product list-->
<reference name="left">
<block type="catalog/product_list_related" before="-" name="product.leftnav.view" as="product.leftnav.view" template="catalog/product/training_leftlist.phtml" />
</reference>
</catalog_product_view>

Moving Magento Advanced Search Link From Footer To Beneath Search Bar

I'm trying to move magentos advanced search link from the footer links right beneath the search bar.
I know that the origins of the link are in layout/catalogsearch.xml under
reference name="footer_links" and appear in the footer because of getChildHtml('footer_links') in footer.phtml
And i know that the search bar originates from template/catalogsearch/form.mini.phtml and appears though catalogsearch.xml under reference name="top.menu"
Any ideas on how to proceed here?
thank you for the quick answer!
But it is not exactly what I was looking for as it would display the entire footer links block beneath the searchbar.
Nevertheless thank you for showing me the method you used for that!
Anyways, I figured out a solution on my own:
I modified catalogsearch.xml:
<default>
<reference name="top.menu">
<block type="core/template" name="top.search" as="topSearch" template="catalogsearch/form.mini.phtml"/>
</reference>
<!-- add a new reference to top.search including my new adv.search block -->
<reference name="top.search">
<block type="page/template_links" name="adv.search" as="adv.search" >
<action method="addLink" translate="label title" module="catalogsearch">
<label>Advanced Search</label>
<url helper="catalogsearch/getAdvancedSearchUrl" />
<title>Advanced Search</title>
</action>
</block>
</reference>
<!-- the reference to the footer i commented out as its not longer needed; it includes advanced search and popular search terms-->
</default>
In form.mini.phtml I added a new div that calls adv.search:
</script>
<div class="adv-search"> <?php echo $this->getChildHtml('adv.search') ?> </div>
</div>
And last, in styles.css, I added some code to controll the looks of that div:
.adv-search {width:100px; height:15px; margin-top:24px; margin-left: 120px;}
.adv-search a { color:#fff; font-weight:bold; }
any additional advice is more than welcome
Cheers!
In order for this to work, you must:
1) Update your app/design/frontend/[yourtheme]/default/layout/local.xml file
2) Call the new blocks in app/design/frontend/[yourtheme]/default/template/page/html/header.phtml - this is needed because header.phtml is not a "core/text_list" block type which automatically renders its nested blocks. So we must explicitly tell Magento to render those child blocks
Your app/design/frontend/[yourtheme]/default/layout/local.xml should contain this:
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="header">
<!-- Insert cms links. No need to use <action method="insert"> as this block is not used elsewhere in layout -->
<block type="cms/block" name="top_links_cms" as="top_links_cms" before="top_links_other">
<action method="setBlockId"><block_id>footer_links</block_id></action>
</block>
<!-- Insert former footer links. -->
<action method="insert">
<!-- We must keep block name "footer_links" as it is used as a reference for adding links by other modules -->
<blockName>footer_links</blockName>
<!-- Name of the block we want to have as sibling (in order to get its position and place our block after it. See next node <after> -->
<siblingName>topSearch</siblingName>
<!-- $after param from Mage_Core_Block_Abstract::insert() is a boolean type, so its value in the XML node is [empty], 0 or 1 -->
<after>1</after>
<alias>top_links_other</alias>
</action>
</reference>
<reference name="footer">
<action method="unsetChild"><name>footer_links</name></action>
<action method="unsetChild"><name>cms_footer_links</name></action>
</reference>
</default>
</layout>
This is an updated header.phtml you can get inspiration from for your app/design/frontend/[yourtheme]/default/template/page/html/header.phtml file:
<div class="header-container">
<div class="header">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></h1>
<?php else:?>
<strong><?php echo $this->getLogoAlt() ?></strong><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" />
<?php endif?>
<div class="quick-access">
<?php echo $this->getChildHtml('topSearch') ?>
<?php
/**
* Add other top links (footer and cms links)
*/
?>
<?php echo $this->getChildHtml('top_links_cms') ?>
<?php echo $this->getChildHtml('top_links_other') ?>
<p class="welcome-msg"><?php echo $this->getWelcome() ?> <?php echo $this->getAdditionalHtml() ?></p>
<?php echo $this->getChildHtml('topLinks') ?>
<?php echo $this->getChildHtml('store_language') ?>
</div>
<?php echo $this->getChildHtml('topContainer'); ?>
</div>
</div>
<?php echo $this->getChildHtml('topMenu') ?>

Resources