how to give link to each attributes of a manufacturer - magento

I have added 4 to 5 attributes in manufacture and shown in right column of front end.Now i want to link the each attributes of manufacture. if i will click an attribute of a manufacturer, it will show all the products which contain that arribute/brand.
if anyone knows this, please help me out.
thanks!
I have shown the attribute name in front end by the below code
<?php
$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'Manufacturer');
if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
if(count( $options)>0){
?>
<div class="title_box">Manufacturers</div>
<?php $i=1;?>
<ul class="left_menu">
<?php
foreach($options as $eachval){
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
<?php } } ?>
I have made one page manu.phtml in catalog/product page and put the following above code now how to give link to that arribute...........please describe briefly
in href link,what i have to write so that when i will click on any attribute it will show all products associated to that attribute/brand.

There is always the option of creating a new module with a custom controller that would list the products from a specified brand, but that is a painful process even if it's the clean way.
Here is a simple version if you don't mind the ugly urls.
The main idea is to link your brand names to the advanced search page with a specific brand filled in.
You can get the url like this:
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'brand='.$value->getId()))
You just need now to get the id of the specific brand ($value->getId()), but if you can get the name you can get the id also.
And don't forget to specify that the brand attribute is used in advanced search. You can do that by editing the attribute in the backend.
[EDIT]
Make your ul element look like this:
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<?php if($i%2==0){ ?>
<li class="even"><?php echo $eachval['label']?></li>
<?php } else { ?>
<li class="odd"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>
Small tip off topic. You can avoid duplication of the li elements in your code like this
<ul class="left_menu">
<?php
foreach($options as $eachval){
$url = Mage::getUrl('catalogsearch/advanced/result', array('_query'=>'Manufacturer='.$eachval['value']));
?>
<li class="<?php echo ($i%2 == 0) ? 'even':'odd';?>"><?php echo $eachval['label']?></li>
<?php } $i++; ?>
<?php } ?>
</ul>

Related

sort collection of category by name

I have custom links in menu that shows categories in drop-down.
For that I made a file in catalog/navigation->mainmenu.phtml
(a custom file)
Now, I want to show categories after sorting it by name. please help me how can I sort collection of categories by name. I already set order of category in admin. But in front-end it show unsorted.
Code is:-
<?php $defaultcategory= Mage::app()->getStore()->getRootCategoryId();?>
<?php $mainchildren = Mage::getModel('catalog/category')->getCategories($defaultcategory);?>
<ul>
<?php foreach ($mainchildren as $subcategory) : ?> <?php // 2 level ?>
<?php if($subcategory->getIsActive()):?>
<li id="show_subcat" class="<?php if($i==1): echo 'first'; endif; ?>" >
<?php $childid=$subcategory->getId();?>
<?php $subchild = Mage::getModel('catalog/category')->getCategories($childid);?>
<?php foreach ($subchild as $subchildcategory) : ?>
<?php $path=$subchildcategory->getRequestPath()?>
<?php break;?>
<?php endforeach ?>
<a href="<?php echo $this->getUrl().$path; ?>">
<?php echo $name= $subcategory->getName().$subcategory->getEnable() ?>
</a>
</li>
<?php endif;?>
<?php endforeach; ?>
</ul>
You can try :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->addAttributeToSort('name', 'ASC');
or :
children = Mage::getModel('catalog/category')->getCategories($defaultcategory)
->setOrder('name','ASC);
$categories = Mage::helper('catalog/category');
$collection = $categories->getStoreCategories(false,true,false);
foreach($collection as $_category)
{
//Do something
echo $_category->getName();
}
use this code to get collection and follow this link for more detailIn magento - same code for getting all categories running well with sorted in localhost but not in web server

Magento - Adding layered navigation to custom page

I'm working on a magento module that shows particular product collections under a new controller and front-name.
Some of these collections get big, so I'd like to add layered navigation to the side of the page. (And hey, pagination and sort while we're at it.)
I can add the layered navigation block with
<reference name="left">
<block type="catalog/layer_view" name="catalog.leftnav" template="landing/layer.phtml"/>
</reference>
What I get with that is the layered navigation as applied to the whole catalog, with categories broken, and no interface with the on-page product collection.
How would I go about wiring up the layered navigation (and hey, pagination and sort) to this custom product collection?
No answers were forthcoming here, and I changed direction and never completed this path of development. Figured I'd post what I'd learned.
The approach above is sound. The work basically entails recreating the functionality on the catalog or catalogsearch modules. You'll have to subclass the models and blocks of catalog, modifying the product collection and current category.
This post heads vaguely in the right direction, but doesn't get there.
http://www.webdesign-gm.co.uk/news/layered-navigation-on-home-page-or-any-cms-page-magento.php
If you make more headway on this, feel free to post.
I've had a similar request from a client to include specific filterable attributes under a mega menu.
Using a static block i've added this line to everywhere i needed a listing of attributes for specific category
{{block type="core/template" attribute_code="age_specific" category_id="12" template="megamenu-custom-filter-list.phtml"}}
And then the "megamenu-custom-filter-list.phtml"
<?php if($this->getCategoryId() && is_numeric($this->getCategoryId()) && $this->getAttributeCode()): ?>
<?php
$visible_items = 12;
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
$attrCode = $this->getAttributeCode();
unset($layer);
$layer = Mage::getModel("catalog/layer");
$layer->setCurrentCategory($category);
$attributes = $layer->getFilterableAttributes();
foreach ($attributes as $attribute):
if($attribute->getAttributeCode() != $attrCode){
continue;
}
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = 'catalog/layer_filter_price';
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = 'catalog/layer_filter_decimal';
} else {
$filterBlockName = 'catalog/layer_filter_attribute';
}
$result = Mage::app()->getLayout()->createBlock($filterBlockName)->setLayer($layer)->setAttributeModel($attribute)->init();
?>
<div>
<h4 class="menu-block-title"><?php echo $this->__($attribute->getFrontendLabel()) ?></h4>
<ul class="menu-attr-list">
<?php $counting = 1; ?>
<?php foreach($result->getItems() as $option): ?>
<?php $optionUrl = $category->getUrl() . "?" . $attribute->getAttributeCode() . "=" . $option->getValue(); ?>
<?php if(!$option->getCount()){ continue; } ?>
<li class="<?php echo ($counting >= $visible_items+1)?"visible-on-showmore":"" ?>" style="list-style: none;">
<a class="cube" href="<?php echo $optionUrl ?>">
<?php echo $option->getLabel() ?> <?php /* (<?php echo $option->getCount() ?>) */ ?>
</a>
</li>
<?php $counting++; ?>
<?php endforeach; ?>
<?php if($counting >= $visible_items+1): ?>
<li class="show-more-menuitem">
<a href="javascript:void(0)" onclick="showMoreMenuItems(this); return false;" class="">
<?php echo $this->__('Visa fler') ?>
</a>
</li>
<?php endif; ?>
</ul>
</div>
<?php endoreach; ?>
<?php endif; ?>
Of course, this can be extended to allow all attributes to be shown and not limit them to 12 (as i did here). Although, i've not build a feature to show this for a custom collection, but i believe that following the "catalog/layer" model and see where the collection was loaded, you can see how to overwrite it and load your own custom collection.

How to add submenu on hover effect in left navigation in magento?

I have vertnav/left.phtml file code,
<div class="vertnav-container">
<div class="">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<?php $store_categories = $this->toLinearArray($this->getStoreCategories()) ?>
<?php if ($count = count($store_categories)): ?>
<ul id="vertnav">
<?php endif; ?>
<?php foreach ($store_categories as $i => $_category): ?><?php $class = array() ?>
<?php if ($count == 1): ?>
<?php $class[] = 'only' ?>
<?php elseif (! $i): ?>
<?php $class[] = 'first' ?>
<?php elseif ($i == $count-1): ?>
<?php $class[] = 'last' ?>
<?php if (isset($store_categories[$i+1]) && $this->isCategoryActive($store_categories[$i+1])) $class[] = 'prev'; ?>
<?php if (isset($store_categories[$i-1]) && $this->isCategoryActive($store_categories[$i-1])) $class[] = 'next'; ?>
<?php echo $this->drawOpenCategoryItem($_category, 0, $class) ?>
<?php endforeach ?>
<?php if ($count): ?>
</ul>
<?php endif; ?>
</div>
</div>
and set System > Configuration > Catalog > Category Vertical Navigation to 2 as per my requirement, but now on mouseover on that displayed category subcategories should be shown
so how can i do customization to that and add hover effect code to this?
Please help me
If you take a closer look at the drawOpenCategoryItem of the Mage_Catalog_Block_Navigation you might notice that the method does a check whether the given category is part of the current category path. So only when this check returns true, the children categories of this category will be rendered. For other categories the script will not go into that part of the code.
This sounds to be case if I understand your question correctly.
if (in_array($category->getId(), $this->getCurrentCategoryPath())){
$children = $category->getChildren();
$hasChildren = $children && $children->count();
if ($hasChildren) {
$htmlChildren = '';
foreach ($children as $child) {
$htmlChildren.= $this->drawOpenCategoryItem($child);
}
if (!empty($htmlChildren)) {
$html.= '<ul>'."\n"
.$htmlChildren
.'</ul>';
}
}
}
Additional to this information. The drawOpenCategoryItem() is never actually called upon in the whole PHP codebase.
So to have these rollover effects you need to have code that generates the full tree structure, or at least a big enough part of it. Regarding the System > Configuration > Catalog > Category Vertical Navigation. I guess you customized that yourself?
To give you a few pointers. You might want to have a look at the following methods. These are used for the rendering of the top menu and are actually doing the thing you are planning to implement.
Mage_Catalog_Block_Navigation::renderCategoriesMenuHtml()
Mage_Catalog_Block_Navigation::_renderCategoryMenuItemHtml()
Hopes this helps you getting things underway.

Magento: display multi-selection as a list with unique ID' s so list item can be changed to an image using CSS

I figured out how to display my custom multiselection attributie as a list but havent been able to figure out how to add an ID or class to every list item. This would allow me to display an image using CSS instead of text.
Hope you guys can help me. By the way, this is the code I use to display my custom attribute "rating" as a list:
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)): ?>
<ul><li><?php
$_comma = ",";
$_list = "</li><li>";
echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) ?>
</li></ul>
<?php endif; ?>
</div>
Without knowing the exact format of the return of your function, I can't be 100% sure, but I think this would do the trick:
<div>
<?php if($_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)):?>
<ul>
<?php $i=0?>
<?php foreach(explode(',', $_product->getResource()->getAttribute('rating')->getFrontend()->getValue($_product)) as $value) : ?>
<li id="value_<?php echo $i?>"><?php echo $value ?></li>
<?php $i++ ?>
<?php endforeach ?>
</ul>
<?php endif; ?>
</div>
It would probably be a little easier to just modify your return to give you back an array, but if the return is a comma separated list and not easy to change, then explode should do the trick.

Display Magento order comments in print.phtml (customers prinable order)

Just wondering if anyone has any idea how to show comments on the customers printable order - http://www.mydomain.com/sales/order/print/order_id/48/
I can see the file that I need to edit is “/public_html/app/design/frontend/default/mytemplate/template/sales/order/print.phtml” but am unsure what code I need to add to display the comments.
FYI: We are using this extension to make the order comments box show up on the order page - http://www.magentocommerce.com/magento-connect/catalog/product/view/id/10860/. The order comments are successfully displayed on the order email but we need them be be displayed on the customers order pages as well.
Thanks for your help in advance :)
+1 for code_break, who answered this nicely. Here's my own version for completeness:
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('status',array('pending','processing'));
foreach ($orders as $order) {
$orderComments = $order->getAllStatusHistory();
foreach ($orderComments as $comment) {
$body = $comment->getData('comment');
if (strpos(strtolower($body),'some text') !== false) {
// do something cool here...
}
}
}
Use as you wish. Hope it helps.
The last post used the getVisibleStatusHistory method of the order object, but the first comment entered on an order is never visible. There are several methods for grabbing the status history and setting it in the order object.
That being said we might want to list all of the comments that are marked as visible on front-ed and the first comment entered when the order is created. I've substitued your formatting with a <p> tag.
<?php $_history = $order->getAllStatusHistory(); ?>
<?php $_buffer = array(); ?>
<?php $_i=1; ?>
<?php foreach ($_history as $_historyItem): ?>
<?php // Ignore the visibility for the first comment ?>
<?php if ( $_historyItem->getData('is_visible_on_front') == 1 || $_i == count($_history) ): ?>
<?php $_buffer[] = $_historyItem->getData('comment'); ?>
<?php endif; ?>
<?php $_i++; ?>
<?php endforeach; ?>
<?php if ( count($_buffer) > 0 ): ?>
<p><?php echo implode( $_buffer, '</p><p>' ); ?></p>
<?php endif ?>
As you are asking especially for the oder comment from MageMaven OrderComment this would be the easiest solution:
<p><?php echo nl2br($_order->getCustomerNote()); ?></p>
Hey try adding this code I havent tested it but i have a feeling it will work for you:
<?php $_history = $_order->getVisibleStatusHistory() ?>
<?php if (count($_history)): ?>
<div class="order-additional order-comments">
<dl class="order-about">
<?php foreach ($_history as $_historyItem): ?>
<dd>
<span class='lowcase'><?php echo $_historyItem->getComment()?></span>
</dd>
<?php endforeach; ?>
</dl>
</div>
<?php endif?>

Resources