0

magento中如何检索Topmenu中的父类别图像。当单击或将鼠标悬停在受尊敬的父菜单上时,我必须显示父类别图像。我尝试了下面提到的代码,但我得到了所有的类别图像。如果我在前端显示它都显示在受尊重的菜单下。谁能指导我如何显示正确的图像?我的 magento 版本是 1.7.0.2。

$categoryData = 数组(

            'name' => $category->getName(),
            'id' => $nodeId,
            'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
            'is_active' => $this->_isActiveMenuCategory($category),
            'links' => $cat->getData('links'),
            'image' => $cat->getImageUrl('image'),
            'thumbnail' => $cat->getThumbnail(),
            'getLevel' => $category->getLevel()
        );

我想使用缩略图来显示。提前致谢...

4

2 回答 2

1

最后我得到了解决方案并在下面分享答案。我可以使用“ getLevel ”属性来查找所有菜单的位置。然后我找出父菜单并在 Topmenu 中显示受人尊敬的图像。

它被添加到模型文件中。(/app/code/core/Mage/Catalog/Model/Observer.php)

函数名称: _addCategoriesToMenu

$categoryData = array(

                'name' => $category->getName(),
                'id' => $nodeId,
                'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
                'is_active' => $this->_isActiveMenuCategory($category),
                'links' => $cat->getData('links'),
                'image' => $cat->getImageUrl('image'),
                'thumbnail' => $cat->getThumbnail(),
                'getLevel' => $category->getLevel()
            );

它被添加到 Html 文件夹中。(app/code/core/Mage/Page/Block/Html/Topmenu.php)

函数名称: _getHtml

$parentLevels = $child->getLevel();

        if($parentLevels == 0) 
        {

            $urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');

            $html .= '<img src="'.$urls.'" />';
        }
于 2013-03-15T05:43:14.200 回答
-1

此解决方案适用于 Magento -1.8.*

在模型文件中。(/app/code/core/Mage/Catalog/Model/Observer.php)

更新函数名称中的以下代码:_addCategoriesToMenu

      $categoryData = array( 
            'name' => $category->getName(),
            'id' => $nodeId,
            'url' => Mage::helper('catalog/category')->getCategoryUrl($category),
            'is_active' => $this->_isActiveMenuCategory($category),
            'thumbnail' => Mage::getModel('catalog/category')->load($category->getId())->getThumbnail()

        );

然后进入 Html 文件夹。(app/code/core/Mage/Page/Block/Html/Topmenu.php)

在第 128 行更新以下代码行

函数名:_getHtml

        if($childLevel < 1 ){
            $urls = Mage::getBaseUrl('media').'catalog/category/'.$child->getData('thumbnail');
            $img = '<img src="'.$urls.'" />';
        }

        $html .= '<li ' . $this->_getRenderedMenuItemAttributes($child) . '>';
        $html .= '<a href="' . $child->getUrl() . '" ' . $outermostClassCode . '><span>'
            . $this->escapeHtml($child->getName()) . ' </span> '.$img.' </a>';
于 2013-11-11T10:45:25.513 回答