Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.
5 added 2566 characters in body
source | link

Below is the code for renderer.phtml

$html = '';

$children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

$counter = 1; $childrenCount = $children->count();

$parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

if(Mage::app()->getStore()->isCurrentlySecure()){ $mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA,true); }else{
$mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); }

foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter);

$outermostClassCode = 'level' . $childLevel;
$_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

if ($childLevel != 0) {
    $urls = $mediaurl . 'catalog/category/' . $child->getData('thumbnail');
    $img = '<img src="' . $urls . '" alt="' . $child->getName() . '" />';
}

$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';

if ($childLevel != 0) {
    $html .= '<a href="' . $child->getUrl() . '" class="' . $outermostClassCode . ' ' . $_hasChildren . '">' . $img .

$this->escapeHtml($this->($child->getName())) . ''; } else { $html .= 'getUrl() . '" class="' . $outermostClassCode . ' ' . $_hasChildren . '">' . $this->escapeHtml($this->($child->getName())) . ''; }

if (!empty($childrenWrapClass)) {
    $html .= '<div class="' . $childrenWrapClass . '">';
}

$nextChildLevel = $childLevel + 1;

if (!empty($_hasChildren)) {
    $html .= '<ul class="level' . $childLevel . '">';
    $html .= '<li class="level' . $nextChildLevel . '">';
    $html .= '<a class="level' . $nextChildLevel . '" href="' . $child->getUrl() . '">';
    $html .= $this->__('View All ') . $this->escapeHtml($this->__($child->getName()));
    $html .= '</a>';
    $html .= '</li>';
    $html .= $this->render($child, $childrenWrapClass);
    $html .= '</ul>';
}

if (!empty($childrenWrapClass)) {
    $html .= '</div>';
}

$html .= '</li>';

$counter++; }

return $html;

Below is the code for renderer.phtml

$html = '';

$children = $menuTree->getChildren(); $parentLevel = $menuTree->getLevel(); $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

$counter = 1; $childrenCount = $children->count();

$parentPositionClass = $menuTree->getPositionClass(); $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

if(Mage::app()->getStore()->isCurrentlySecure()){ $mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA,true); }else{
$mediaurl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); }

foreach ($children as $child) { $child->setLevel($childLevel); $child->setIsFirst($counter == 1); $child->setIsLast($counter == $childrenCount); $child->setPositionClass($itemPositionClassPrefix . $counter);

$outermostClassCode = 'level' . $childLevel;
$_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

if ($childLevel != 0) {
    $urls = $mediaurl . 'catalog/category/' . $child->getData('thumbnail');
    $img = '<img src="' . $urls . '" alt="' . $child->getName() . '" />';
}

$html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';

if ($childLevel != 0) {
    $html .= '<a href="' . $child->getUrl() . '" class="' . $outermostClassCode . ' ' . $_hasChildren . '">' . $img .

$this->escapeHtml($this->($child->getName())) . ''; } else { $html .= 'getUrl() . '" class="' . $outermostClassCode . ' ' . $_hasChildren . '">' . $this->escapeHtml($this->($child->getName())) . ''; }

if (!empty($childrenWrapClass)) {
    $html .= '<div class="' . $childrenWrapClass . '">';
}

$nextChildLevel = $childLevel + 1;

if (!empty($_hasChildren)) {
    $html .= '<ul class="level' . $childLevel . '">';
    $html .= '<li class="level' . $nextChildLevel . '">';
    $html .= '<a class="level' . $nextChildLevel . '" href="' . $child->getUrl() . '">';
    $html .= $this->__('View All ') . $this->escapeHtml($this->__($child->getName()));
    $html .= '</a>';
    $html .= '</li>';
    $html .= $this->render($child, $childrenWrapClass);
    $html .= '</ul>';
}

if (!empty($childrenWrapClass)) {
    $html .= '</div>';
}

$html .= '</li>';

$counter++; }

return $html;

4 added 172 characters in body
source | link

public function addCategoryImages(Varien_Event_Observer $observer) { $block = $observer->getEvent()->getBlock(); $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG); $this->_addCategoriesToMenu( Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true ); }

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) { $categoryModel = Mage::getModel('catalog/category'); foreach ($categories as $category) { if (!$category->getIsActive()) { continue; }

public function addCategoryImages(Varien_Event_Observer $observer) {
    $block = $observer->getEvent()->getBlock();
    $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG);
    $this->_addCategoriesToMenu(
        Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true
    );
}

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) {
    $categoryModel = Mage::getModel('catalog/category');
    foreach ($categories as $category) {
        if (!$category->getIsActive()) {
            continue;
        }

        $nodeId = 'category-node-' . $category->getId();

        $categoryModel->setId($category->getId());
        if ($addTags) {
            $menuBlock->addModelTags($categoryModel);
        }

        $tree = $parentCategoryNode->getTree();
        $categoryData = array(
            'name' => $category->getName(),
            'id' => $nodeId,
            'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
            'is_active' => $this->_isActiveMenuCategory($category),
            'thumbnail' => $categoryModel->load($category->getId())->getThumbnail()
        );
        $categoryNode = new Varien_Data_Tree_Node($categoryData, 'id', $tree, $parentCategoryNode);
        $parentCategoryNode->addChild($categoryNode);

        $flatHelper = Mage::helper('catalog/category_flat');
        if ($flatHelper->isEnabled() && $flatHelper->isBuilt(true)) {
            $subcategories = (array) $category->getChildrenNodes();
        } else {
            $subcategories = $category->getChildren();
        }

        $this->_addCategoriesToMenu($subcategories, $categoryNode, $menuBlock, $addTags);
    }
}

}

public function addCategoryImages(Varien_Event_Observer $observer) { $block = $observer->getEvent()->getBlock(); $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG); $this->_addCategoriesToMenu( Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true ); }

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) { $categoryModel = Mage::getModel('catalog/category'); foreach ($categories as $category) { if (!$category->getIsActive()) { continue; }

    $nodeId = 'category-node-' . $category->getId();

    $categoryModel->setId($category->getId());
    if ($addTags) {
        $menuBlock->addModelTags($categoryModel);
    }

    $tree = $parentCategoryNode->getTree();
    $categoryData = array(
        'name' => $category->getName(),
        'id' => $nodeId,
        'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
        'is_active' => $this->_isActiveMenuCategory($category),
        'thumbnail' => $categoryModel->load($category->getId())->getThumbnail()
    );
    $categoryNode = new Varien_Data_Tree_Node($categoryData, 'id', $tree, $parentCategoryNode);
    $parentCategoryNode->addChild($categoryNode);

    $flatHelper = Mage::helper('catalog/category_flat');
    if ($flatHelper->isEnabled() && $flatHelper->isBuilt(true)) {
        $subcategories = (array) $category->getChildrenNodes();
    } else {
        $subcategories = $category->getChildren();
    }

    $this->_addCategoriesToMenu($subcategories, $categoryNode, $menuBlock, $addTags);
}

}

public function addCategoryImages(Varien_Event_Observer $observer) {
    $block = $observer->getEvent()->getBlock();
    $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG);
    $this->_addCategoriesToMenu(
        Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true
    );
}

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) {
    $categoryModel = Mage::getModel('catalog/category');
    foreach ($categories as $category) {
        if (!$category->getIsActive()) {
            continue;
        }

        $nodeId = 'category-node-' . $category->getId();

        $categoryModel->setId($category->getId());
        if ($addTags) {
            $menuBlock->addModelTags($categoryModel);
        }

        $tree = $parentCategoryNode->getTree();
        $categoryData = array(
            'name' => $category->getName(),
            'id' => $nodeId,
            'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
            'is_active' => $this->_isActiveMenuCategory($category),
            'thumbnail' => $categoryModel->load($category->getId())->getThumbnail()
        );
        $categoryNode = new Varien_Data_Tree_Node($categoryData, 'id', $tree, $parentCategoryNode);
        $parentCategoryNode->addChild($categoryNode);

        $flatHelper = Mage::helper('catalog/category_flat');
        if ($flatHelper->isEnabled() && $flatHelper->isBuilt(true)) {
            $subcategories = (array) $category->getChildrenNodes();
        } else {
            $subcategories = $category->getChildren();
        }

        $this->_addCategoriesToMenu($subcategories, $categoryNode, $menuBlock, $addTags);
    }
}
3 added 2042 characters in body
source | link

Please let me know how this issue can be fixed.
Any help will be appreciated.
CODE FOR ADDING IMAGES
I have re-written class Mage_Catalog_Model_Observer below methods

public function addCategoryImages(Varien_Event_Observer $observer) { $block = $observer->getEvent()->getBlock(); $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG); $this->_addCategoriesToMenu( Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true ); }

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) { $categoryModel = Mage::getModel('catalog/category'); foreach ($categories as $category) { if (!$category->getIsActive()) { continue; }

    $nodeId = 'category-node-' . $category->getId();

    $categoryModel->setId($category->getId());
    if ($addTags) {
        $menuBlock->addModelTags($categoryModel);
    }

    $tree = $parentCategoryNode->getTree();
    $categoryData = array(
        'name' => $category->getName(),
        'id' => $nodeId,
        'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
        'is_active' => $this->_isActiveMenuCategory($category),
        'thumbnail' => $categoryModel->load($category->getId())->getThumbnail()
    );
    $categoryNode = new Varien_Data_Tree_Node($categoryData, 'id', $tree, $parentCategoryNode);
    $parentCategoryNode->addChild($categoryNode);

    $flatHelper = Mage::helper('catalog/category_flat');
    if ($flatHelper->isEnabled() && $flatHelper->isBuilt(true)) {
        $subcategories = (array) $category->getChildrenNodes();
    } else {
        $subcategories = $category->getChildren();
    }

    $this->_addCategoriesToMenu($subcategories, $categoryNode, $menuBlock, $addTags);
}

}

I have added "thumbnail" in categoryData array and then fetched this in template app/design/frontend/rwd/bluebath/template/page/html/topmenu/renderer.phtml

Please let me know how this issue can be fixed.
Any help will be appreciated.

Please let me know how this issue can be fixed.
Any help will be appreciated.
CODE FOR ADDING IMAGES
I have re-written class Mage_Catalog_Model_Observer below methods

public function addCategoryImages(Varien_Event_Observer $observer) { $block = $observer->getEvent()->getBlock(); $block->addCacheTag(Mage_Catalog_Model_Category::CACHE_TAG); $this->_addCategoriesToMenu( Mage::helper('catalog/category')->getStoreCategories(), $observer->getMenu(), $block, true ); }

public function _addCategoriesToMenu($categories, $parentCategoryNode, $menuBlock, $addTags = false) { $categoryModel = Mage::getModel('catalog/category'); foreach ($categories as $category) { if (!$category->getIsActive()) { continue; }

    $nodeId = 'category-node-' . $category->getId();

    $categoryModel->setId($category->getId());
    if ($addTags) {
        $menuBlock->addModelTags($categoryModel);
    }

    $tree = $parentCategoryNode->getTree();
    $categoryData = array(
        'name' => $category->getName(),
        'id' => $nodeId,
        'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
        'is_active' => $this->_isActiveMenuCategory($category),
        'thumbnail' => $categoryModel->load($category->getId())->getThumbnail()
    );
    $categoryNode = new Varien_Data_Tree_Node($categoryData, 'id', $tree, $parentCategoryNode);
    $parentCategoryNode->addChild($categoryNode);

    $flatHelper = Mage::helper('catalog/category_flat');
    if ($flatHelper->isEnabled() && $flatHelper->isBuilt(true)) {
        $subcategories = (array) $category->getChildrenNodes();
    } else {
        $subcategories = $category->getChildren();
    }

    $this->_addCategoriesToMenu($subcategories, $categoryNode, $menuBlock, $addTags);
}

}

I have added "thumbnail" in categoryData array and then fetched this in template app/design/frontend/rwd/bluebath/template/page/html/topmenu/renderer.phtml

2 deleted 55 characters in body
source | link
1
source | link