Author Archives: prakash

How to set up SSL certificate in local development apache

It was very difficult to setup SSL certificate for local environment in APACHE finally I got the solution. it takes 3 steps as follow

1. Generate Certificate:

mkdir \-p /etc/apache2/ssl
openssl req \-new \-x509 \-days 365 \-nodes \-out /etc/apache2/ssl/apache.pem \-keyout /etc/apache2/ssl/apache.pem
ln \-sf /etc/apache2/ssl/apache.pem /etc/apache2/ssl/`/usr/bin/openssl x509 \-noout \-hash < /etc/apache2/ssl/apache.pem`.0
chmod 600 /etc/apache2/ssl/apache.pem

2. Modify and add /etc/apache/ports.conf:


NameVirtualHost \*:443
Listen 443

3. add following code in vhost file:


SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem
DocumentRoot /pfad/zum/Webinhalt

How to add Wishlist in Magento toplinks menu for only logged in user

Here is the simple method to add wishlist only for loggedin user in magento.
just go to your layout page that is app/design/frontend/PACKAGE7THEME/layout/local.xml and add following code

<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>
            <action method="addLink" translate="label title" module="wishlist"><label>My Wishlist</label><path>wishlist</path><title>My Wishlist</title><prepare>true</prepare><urlParams/><position>110</position></action>
        </reference>
    </customer_logged_in>
    <customer_logged_out>
        <reference name="top.links">
            <remove name="wishlist_link"/>
        </reference>
    </customer_logged_out>

Product count of category in Magento default navigation

To display number of product that is associated to the particular category I have overrided a magento Navigation Block. for that I have create a very small extension code. please check it down.

create a xml file at app/etc/modules/Prakash_All.xml and copy/paste following code

&lt;config&gt;
  &lt;modules&gt;
    &lt;Prakash_Catalog&gt;
      &lt;active&gt;true&lt;/active&gt;
      &lt;codePool&gt;local&lt;/codePool&gt;
    &lt;/Prakash_Catalog&gt;
  &lt;/modules&gt;
&lt;/config&gt;

Then create another xml file in exact following path and name
app/code/local/Prakash/Catelog/Block/etc/config.xml and copy/paste following code in this file

&lt;config&gt;
  &lt;modules&gt;
    &lt;Prakash_Catalog&gt;
      &lt;version&gt;0.1.0&lt;/version&gt;
    &lt;/Prakash_Catalog&gt;
  &lt;/modules&gt;
  &lt;global&gt;
    &lt;blocks&gt;
      &lt;catalog&gt;
        &lt;rewrite&gt;
          &lt;navigation&gt;Prakash_Catalog_Block_Navigation&lt;/navigation&gt;
        &lt;/rewrite&gt;
      &lt;/catalog&gt;
    &lt;/blocks&gt;
  &lt;/global&gt;
&lt;/config&gt;

This code rewrite the existing Navigation Block with our custom navigation. Even though we have to change just a few code it is always better to to write in our own custom rewrite module.

and then create another files with name and location as app/code/local/Prakash/Catelog/Block/Navigation.php

and copy/paste following code


class Prakash_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{

	protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
			$isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
	{
		if (!$category-&amp;gt;getIsActive()) {
			return '';
		}
		$html = array();

		// get all children
		if (Mage::helper('catalog/category_flat')-&amp;gt;isEnabled()) {
			$children = (array)$category-&amp;gt;getChildrenNodes();
			$childrenCount = count($children);
		} else {
			$children = $category-&amp;gt;getChildren();
			$childrenCount = $children-&amp;gt;count();
		}
		$hasChildren = ($children &amp;amp;&amp;amp; $childrenCount);

		// select active children
		$activeChildren = array();
		foreach ($children as $child) {
			if ($child-&amp;gt;getIsActive()) {
				$activeChildren[] = $child;
			}
		}
		$activeChildrenCount = count($activeChildren);
		$hasActiveChildren = ($activeChildrenCount &amp;gt; 0);

		// prepare list item html classes
		$classes = array();
		$classes[] = 'level' . $level;
		$classes[] = 'nav-' . $this-&amp;gt;_getItemPosition($level);
		if ($this-&amp;gt;isCategoryActive($category)) {
			$classes[] = 'active';
		}
		$linkClass = '';
		if ($isOutermost &amp;amp;&amp;amp; $outermostItemClass) {
			$classes[] = $outermostItemClass;
			$linkClass = ' class="'.$outermostItemClass.'"';
		}
		if ($isFirst) {
			$classes[] = 'first';
		}
		if ($isLast) {
			$classes[] = 'last';
		}
		if ($hasActiveChildren) {
			$classes[] = 'parent';
		}

		// prepare list item attributes
		$attributes = array();
		if (count($classes) &amp;gt; 0) {
			$attributes['class'] = implode(' ', $classes);
		}
		if ($hasActiveChildren &amp;amp;&amp;amp; !$noEventAttributes) {
			$attributes['onmouseover'] = 'toggleMenu(this,1)';
			$attributes['onmouseout'] = 'toggleMenu(this,0)';
		}

		// assemble list item with attributes
		$htmlLi = '&amp;lt;li';
		foreach ($attributes as $attrName =&amp;gt; $attrValue) {
			$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
		}
		//count product for first category
		$productCount = '';
		$catRef = Mage::getModel('catalog/category')-&amp;gt;load($category-&amp;gt;getId());
		$productCount = ' '.$catRef-&amp;gt;getProductCount().' ';
		$htmlLi .= '&amp;gt;';
		$html[] = $htmlLi;
		$html[] = '&amp;lt;a href="'.$this-&amp;gt;getCategoryUrl($category).'"'.$linkClass.'&amp;gt;';
		$html[] = '&amp;lt;span&amp;gt;' . $this-&amp;gt;escapeHtml($category-&amp;gt;getName()).$productCount . '&amp;lt;/span&amp;gt;';
		$html[] = '&amp;lt;/a&amp;gt;';

		// render children
		$htmlChildren = '';
		$j = 0;
		foreach ($activeChildren as $child) {
			$htmlChildren .= $this-&amp;gt;_renderCategoryMenuItemHtml(
					$child,
					($level + 1),
					($j == $activeChildrenCount - 1),
					($j == 0),
					false,
					$outermostItemClass,
					$childrenWrapClass,
					$noEventAttributes
			);
			$j++;
		}
		if (!empty($htmlChildren)) {
			if ($childrenWrapClass) {
				$html[] = '&amp;lt;div class="' . $childrenWrapClass . '"&amp;gt;';
			}
			$html[] = '&amp;lt;ul class="level' . $level . '"&amp;gt;';
			$html[] = $htmlChildren;
			$html[] = '&amp;lt;/ul&amp;gt;';
			if ($childrenWrapClass) {
				$html[] = '&amp;lt;/div&amp;gt;';
			}
		}

		$html[] = '&amp;lt;/li&amp;gt;';

		$html = implode("\n", $html);
		return $html;
	}
	public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
	{
		$activeCategories = array();
		foreach ($this-&amp;gt;getStoreCategories() as $child) {
			if ($child-&amp;gt;getIsActive()) {
				$activeCategories[] = $child;
			}
		}
		$activeCategoriesCount = count($activeCategories);
		$hasActiveCategoriesCount = ($activeCategoriesCount &amp;gt; 0);

		if (!$hasActiveCategoriesCount) {
			return '';
		}

		$html = '';
		$j = 0;
		foreach ($activeCategories as $category) {
			$html .= $this-&amp;gt;_renderCategoryMenuItemHtml(
					$category,
					$level,
					($j == $activeCategoriesCount - 1),
					($j == 0),
					true,
					$outermostItemClass,
					$childrenWrapClass,
					true
			);
			$j++;
		}

		return $html;
	}
}

Here we have just added one line of code from existing Navigation.php block of Magento code but I hope that it will be helpful to all of you.
Please download full code from following location

Navigation

Download from github repository:

https://github.com/phpprakash/navigation