Sometimes we need current category id or other stuff in product detail page.
We can get current category id in product detail page by :
$this->getProduct()->getCategory()->getEntityId();
Showing posts with label Magento[wahid's code ]. Show all posts
Showing posts with label Magento[wahid's code ]. Show all posts
Wednesday, January 26, 2011
Monday, July 26, 2010
What should we do if we need to create menu navigation with product attributes??
<?php ?> <li><a href="<? echo $this->getUrl();?>designer"><span>Designer</span></a> <ul class="designer"> <li class="first designer_section"><h4>Men's Designer</h4> <span class="designer_section"> <?php $product = Mage::getModel('catalog/product'); // load a product collection filtered by desginersex $productCollection = $product->getCollection() //->distinct(true) //->addAttributeToSelect('designername') ->addAttributeToSelect('*') ->addAttributeToFilter('designersex', 128) ->load(); // process the collection $i = 0; foreach ($productCollection as $prod) { //print_r($prod->getdesigner()); $designer_name[$i] = $prod->getAttributeText('designer'); $designer_id[$i] = $prod->getdesigner(); $i++; } $count = $i -1; if($count >30) $count = 30; $temp = ''; $k = 0; for($i = 0; $i < $count; $i++) { for($j = $i + 1; $j < $count; $j++){ if($designer_name[$i] == $designer_name[$j]){ $designer_name[$j] = ''; //$count--; } } } for($i = 0; $i < $count; $i++) if($designer_name[$i]!= ''){ echo '<span><a href="'.$this->getUrl().'designer_list?gender=male&designer='.$designer_id[$i].'">'.$designer_name[$i].'</a></span>'; } ?> </span> </li> <li class="first designer_section"><h4>Women's Designer</h4> <span class="designer_section"> <?php $product = Mage::getModel('catalog/product'); // load a product collection filtered by desginersex $productCollection = $product->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('designersex', 127) ->load(); $i = 0; foreach ($productCollection as $prod) { $designer_name[$i] = $prod->getAttributeText('designer'); $designer_id[$i] = $prod->getdesigner(); $i++; } $count = $i; if($count >30) $count = 30; $temp = ''; $k = 0; for($i = 0; $i < $count; $i++) { for($j = $i + 1; $j < $count; $j++){ if($designer_name[$i] == $designer_name[$j]){ $designer_name[$j] = ''; //$count--; } } } for($i = 0; $i < $count; $i++) if($designer_name[$i]!= '') echo '<span><a href="'.$this->getUrl().'designer_list?gender=female&designer='.$designer_id[$i].'">'.$designer_name[$i].'</a></span>'; ?> </span> </li> <a style="float:left; color:#fff; font-size:10px; padding-left:20px;" href="<? echo $this->getUrl();?>designer"> View All</a> </ul> </li> <?php ?>
Saturday, July 3, 2010
How to add static block in magento
First we need to create a static block from admin panel.
Then we shall write what we need. Remember, We need to input the identifier value, which will represent the block by BlockId.
Then we shall write what we need. Remember, We need to input the identifier value, which will represent the block by BlockId.
Thursday, July 1, 2010
Displaying Product's Filter attributes in breadcrumbs.
This is a wonder, why Magento does not allow displaying product's Filter attributes in breadcrumbs.
Thats why I need to create custom code.
Here is the way:
Thats why I need to create custom code.
Here is the way:
<?php if($crumbs && is_array($crumbs)): ?> <?php $current_url = $this->helper('core/url')->getCurrentUrl(); $link_pass = strpos($current_url, '?'); ?> <div class="breadcrumbs"> <ul> <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?> <li class="<?php echo $_crumbName ?>"> <?php if($_crumbInfo['link']): ?> <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a> <?php elseif($_crumbInfo['last']): ?> <?php if($link_pass){ ?><a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php }?> <?php echo $this->htmlEscape($_crumbInfo['label']) ?> <?php if($link_pass){ ?></a><?php }?> <?php else: ?> <?php echo $this->htmlEscape($_crumbInfo['label']) ?> <?php endif; ?> </li> <?php endforeach; ?> <?php if($link_pass){ $final_filter = ''; $pass = 0; $filter_link = explode("?", $current_url); $filter_link = $filter_link[1]; $filter_attr = explode("&",$filter_link); $filter_len = count($filter_attr); ?> <li> <?php if(Mage::app()->getRequest()->getParam('cat')){ $id = Mage::app()->getRequest()->getParam('cat'); $_category = Mage::getModel('catalog/category')->load($id); $cat_url = Mage::getModel("catalog/category")->load($id)->getUrl(); $cat_name = $_category->getName(); if($filter_len > 1) { ?> <a href="<?php echo $cat_url; ?>" style="margin-right:4px;"> <?php } ?> <?php echo $cat_name; ?> <?php if(count($filter_link) != 0) { ?> </a> <?php } } ?> </li> <?php for($i = 0; $i < $filter_len; $i++) { $filter_pos = strpos($filter_attr[$i], '='); $filter_attr1 = substr($filter_attr[$i], 0, $filter_pos); if( $filter_attr1 != 'cat'){ $filter_attr1 = '<b style="text-transform:capitalize;">'.str_replace("_", " ", $filter_attr1).'</b>'; $final_filter = $final_filter .", ".$filter_attr1; $pass = 1; } } if($pass) echo "<li> [".substr($final_filter, 2, strlen($final_filter))." ]</li>"; } ?> </ul> </div> <?php endif; ?>Everything is done in breadcrumbs.phtml file.
Subscribe to:
Posts (Atom)