Navigation block is rendered twice? - magento

i try to include a custom category-navigation in the left column of a custom magento layout template. there fore i placed the following code in my local.xml
<!--Category View-->
<catalog_category_view>
<!--Set Page Template-->
<reference name="root">
<action method="setTemplate">
<template>page/hew_layout_2cl.phtml</template>
</action>
</reference>
<reference name="left">
<block type="catalog/navigation" name="catalog.catleftnav" template="catalog/category/navigation/left.phtml" />
</reference>
</catalog_category_view>
my layout file is placed in design/frontend/###CUSTOM###/default/template/page/layout_2cl.phtml and includes the following line for the left column
<div class="col-left sidebar"><?php echo $this->getChildHtml('left') ?></div>
the left.phtml navigation file is placed in design/frontend/###CUSTOM###/default/template/catalog/category/navigation/left.phtml and looks like this
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<?php if ($currentCategory && $currentCategory->getId() == $_category->getId()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
the only problem here is, that the left block is rendered twice. i also followed the bugfix of the following thread, but it didn't help.
any advice on this? thanks!

Related

Show categories on left and not on top navigation

I tried implemented a code in my Navigation/left.phtml
The code is as follows
<!-- subcategory code -->
<?php
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
if(!$category->getChildren()){
//$parentcat_id = $category->getParentCategory()->getId();
//$category = Mage::getSingleton('catalog/category')->load($parentcat_id);
$category = $category->getParentCategory();
}
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren());
?>
<div class="block">
<div class="block-title">
<span><?php echo $category->getName() ?></span>
</div>
<div class="block-content clearfix">
<ul class="subcategories">
<?php foreach ($categories as $category): ?>
<li>
<a href="<?php echo $category->getUrl() ?>"><!--<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />-->
<span><?php echo $category->getName() ?>
<?php $collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($category);
echo "(".count($collection).")"; ?></span>
</a>
</li>
<?php endforeach; ?>
</ul></div>
</div>
<!-- subcategory code -->
<!-- List all categories and their second level subcategories -->
<div class="block block-list block-categories">
<div id="block-categories" class="block-title active">
<strong><span>Categories </span></strong>
</div>
<div id="leftnav" class="block-content" style="display:block">
<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<?php if (count($categories) > 0): ?>
<ul id="leftnav-tree" class="level0">
<?php foreach($categories as $category): ?>
<li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">
<?php //if ($this->isCategoryActive($category)): ?>
<?php $subcategories = $category->getChildren() ?>
<?php if (count($subcategories) > 0): ?>
<ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
<?php foreach($subcategories as $subcategory): ?>
<li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?>
<?php $secondLevelSubcategories = $subcategory->getChildren() ?>
<?php if (count($secondLevelSubcategories ) > 0): ?>
<ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2">
<?php foreach($secondLevelSubcategories as $secondLevelSubcategory ): ?>
<li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory )): ?> active<?php endif; ?>">
<?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
<?php endif; ?>
<?php //endif; ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
<?php endif; ?>
</div>
</div>
But when i set Include in Navigation Menu to No it also disappears from here.
Is there any way I can hide from top menu and show in my side menu?
Demo link is http://infigic.com/ds4u/
If you don't have local.xml file just create one in the layout folder of your theme and populate it with this content:
<?xml version="1.0"?>
<layout>
<default>
<reference name="header">
<action method="unsetChild"><name>top.menu</name></action>
</reference>
<reference name="left">
<action method="insert"><child>top.menu</child></action>
</reference>
</default>
</layout>
Changing your collection request to this should work :
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addAttributeToFilter('include_in_menu', 1) // there is the 'magic'
->addIdFilter($category->getChildren());
Although, I do not recommend you to do it like this.
Because:
You are breaking the MVC pattern of Magento when requesting a model from a view
You are doing over complicated things that you may probably achieve easier by doing a block which extends Mage_Catalog_Block_Navigation, where the category may already be filtered the right way, but not rendered as you would like.
Please have a look at base Magento template (well not only the one in /app/design/frontend/base, but the one coming with a fresh install of Magento) and you'll see that never ever are there going to be a direct call in a view to a model instance.
For Magento good practice, please refer to the perfect blog of Alan Storm (who also is a SO member) here and maybe more specifically to this chart showing how templates (view) should interact with blocks to render models.

Hiding or Showing Filters In Certain Categories in magento

on our highest level category there are about 50 shop-by options, i m trying to hide attribute filter with xml code in custom layout of categories. with this code
<reference name="em.catalog.leftnav">
<action method="setData">
<instruction>hide_attribute_code</instruction>
<value>1</value>
</action>
But not hide filter attribute in that category, check it on image
in catalog.xml
<catalog_category_layered translate="label">
<label>Catalog Category (Anchor)</label>
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
<catalog_category_layered translate="label">
follow the template ... catalog/layer/view.phtml
Open this file and made there conditions for filters to appear on frontend, by name or id
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getName() == 'Price' || $_filter->getName() == 'Category' || $_filter->getName() == 'Manufacturer' ): ?>
<?php if($_filter->getItemsCount()): ?>
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>
<?php endif; ?>
<?php endforeach; ?>
I do not know your extension that is reliable for layered navigation, but this should work:
<reference name="em.catalog.leftnav">
<action method="hideAttributes">
<code>hide_attribute_code</code>
</action>
</reference>
Go to the file in app/code/POOL/YOUR/MODULE/Blocks/... that builds your filter. If your template has something like getFilters() you can try echo get_class($this) to get the correct class/file. There you have to do two things:
1.) add a new method (in this case you can set comma seperate the attribute codes)
public function hideAttributes($attributeCodes)
{
$attributeCodes = array_map('trim', explode(',', $attributeCodes));
$this->setData('hide_attributes', $attributeCodes);
}
2.) search for the function that collects the filters, e.g. getFilters() and add
$filterableAttributes = // some code
foreach ($filterableAttributes as $attribute) {
if (!in_array($attribute->getAttributeCode(), $this->getHideAttributes())) {
...
}
}
You will need to unset the attribute name on view layer, so find this file:
magento/app/design/frontend/base/default/template/catalog/layer/view.phtml
edit:
<?php if($this->canShowBlock()): ?>
<div class="block block-layered-nav">
<div class="block-title">
<strong><span><?php echo $this->__('Shop By') ?></span></strong>
</div>
<div class="block-content">
<?php echo $this->getStateHtml() ?>
<?php if($this->canShowOptions()): ?>
<p class="block-subtitle"><?php echo $this->__('Shopping Options') ?></p>
<dl id="narrow-by-list">
<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
<?php if($_filter->getItemsCount()): ?>
<!-- add this line start-->
<?php if($_filter->getName() != "Color"): ?>
<!-- add this line end-->
<dt><?php echo $this->__($_filter->getName()) ?></dt>
<dd>
<?php echo $_filter->getHtml() ?>
</dd>
<!-- add this line start-->
<?php endif; ?>
<!-- add this line end-->
<?php endif; ?>
<?php endforeach; ?>
</dl>
<script type="text/javascript">decorateDataList('narrow-by-list')</script>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
Hope you can get working now !

Magento Category Layout - Spliting catalog/category/view.pthml

Magento 1.7.0.2
I have Easy Catalogue Images installed by Templates Master. I would like to have the title, RSS Link, description etc. appear above this module and the products listed below.
I have therefore split view.phtml into title.ptmhl and view.phtml and would like the following layout.
title.phtml
Easy Catalogue image
view.phtml
My title.phtml is located at catalog/category/title.phtml as follows:
<?php
$_helper = $this->helper('catalog/output');
$_category = $this->getCurrentCategory();
$categoryName = $this->htmlEscape($_category->getName());
$_imgHtml = '';
if ($_imageUrl = $_category->getImageUrl()) {
$_imgHtml = '<img src="'.$_imageUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" />';
$_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
}?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<div class="page-title category-title">
<?php if($this->IsRssCatalogEnable() && $this->IsTopCategory()): ?>
<?php echo sprintf($this->__('Subscribe to %s RSS Feed'), $categoryName) ?>
<?php endif; ?>
<h2><?php echo $_helper->categoryAttribute($_category, $this->htmlEscape($_category->getName()), 'name') ?></h2>
</div>
<?php if($_imgHtml): ?>
<p><?php echo $_imgHtml?></p>
<?php endif; ?>
<?php if($_description=$_category->getDescription()): ?>
<p class="category-description std"><?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?></p>
<?php endif; ?>
</div>
view.phtml has been altered to exclude all instances of class 'page-title category-title' as above.
I have tried referencing title.phtml in catalog.xml as follows
<reference name="content">
<block type="catalog/category_title" name="category.title" template="catalog/category/title.phtml">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
title.phtml does not show.

I want to display the category and its child category structure on my page like below in magento 1.7

I'm new in magento and having problem with the category and its child category and their products structure .
plz can anyone give me the code to implement exactly the same structure .
I want structure like this on the content area ,not in the any side bar or header navigation :-
Main Category Name
Subcategory1 Name
Product 1
Product 2
.
.
Subcategory2 Name
Product 1
Product 2
.
.
and this should be work for every category.
Can anyone solve this ?
Thanks in advance :)
Here is some code I have used to display sub category tiles on a category page.
https://www.evernote.com/shard/s4/sh/cc805407-a0d5-4d74-8cd2-b2d7513262f1/9934b5a9f09962b90fe5ecf76f06deb5
I would suggests not to ask the for code better you try this people here can give idea.
Then also...
Go to following path in your magento(Note: Here I am using base/default/default you have to use in your template file).
/app/design/frontend/base/default/template/catalog/navigation
Create New file vert-navigation.phtml
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<div class="vertical-nav">
<div class="navi-title"><h2>BROWSE BY CATEGORY</h2></div>
<?php echo $this->getChildHtml('topSearch') ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php //if ($currentCategory->getName() == $_category->getName()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories();
//$count=0; ?>
<?php if (count($_subcategories) > 0): ?>
<!--li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a-->
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php //$count++; ?>
<?php //if($count==4) break; ?>
<?php endforeach; ?>
</ul>
<?php //endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Then go to /app/design/frontend/base/default/layout/catalog.xml place the below code
<reference name="content">
<!--block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml"/-->
<block type="catalog/navigation" before="-" name="catalog.vertnav" template="catalog/navigation/vert-navigation.phtml"/>
</reference>
You will see the full listing of Category do style as you requirement.

Set breadcrumb for one of the pages of Magento?

I have this page for instance that doesn't have a proper breadcrumb set: http://www.princessly.com/checkout/cart/
It's just "Home >>" and that's it.
How can I make it "Home >> Shopping Cart"?
Thus far I can only find the breadcrumb template which is template/page/html/breadcrumbs.phtml but I have no idea how to make this change.
I suppose I should add a line in the shopping cart page template?
Try adding the following code to local.xml of your theme:
<checkout_cart_index>
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbName>Home</crumbName>
<crumbInfo><label>Home</label><title>Home</title><link>/home</link></crumbInfo>
</action>
<action method="addCrumb">
<crumbName>Shopping Cart</crumbName>
<crumbInfo><label>Shopping Cart</label><title>Shopping Cart</title><link>/checkout/cart</link></crumbInfo>
</action>
</reference>
</checkout_cart_index>
For some reason sometimes we need to touch the template on code>page>html>breadcrumbs.phtml. Just remember to move before to your template.
<?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->__($this->htmlEscape($_crumbInfo['label'])) ?>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->__($this->htmlEscape($_crumbInfo['label'])) ?></strong>
<?php else: ?>
<?php echo $this->__($this->htmlEscape($_crumbInfo['label'])) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>/ </span>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
The translate is performed by
$this->__("someText");

Resources