2

I need to create New Label Icon for selected categories, How can I create new labels icons like,

enter image description here

1

Create a custom category attribute (Yes or no), You can get help here :

https://www.atwix.com/magento/add-category-attribute/

http://inchoo.net/magento/how-to-add-new-custom-category-attribute-in-magento/

https://magento.stackexchange.com/a/11408/21339

Set the value of those category (yes/no) from backed and then within your template put you logic.

Edit

Here is the code for this, I have not tested this code, Please do it on demo site.

Step 1 : Add the following code in your app/etc/Arunendra_Pratap.xml file.

<?xml version="1.0"?>
<config>
    <modules>
      <Arunendra_Pratap>
         <active>true</active>
         <codePool>local</codePool>
      </Arunendra_Pratap>
    </modules>
</config>

Step 2 :Add the following code to the app/code/local/Arunendra/Pratap/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Arunendra_Pratap>
            <version>0.0.1</version>
        </Arunendra_Pratap>
    </modules>

    <global>
        <resources>
            <add_category_attribute>
                <setup>
                    <module>Arunendra_Pratap</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </add_category_attribute>
            <add_category_attribute_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </add_category_attribute_write>
            <add_category_attribute_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </add_category_attribute_read>
        </resources>
    </global>
</config>

Step 3 :Add the custom attribute to the app/code/local/Arunendra/Pratap/sql/add_category_attribute/mysql4-install-0.0.1.php file as shown below.

  <?php
    $this->startSetup();
    $this->addAttribute(Mage_Catalog_Model_Category::ENTITY, 'is_new_cat', array(
        'group'         => 'General Information',
        'input'         => 'select',
        'type'          => 'text',
        'label'         => 'Is new',
        'backend'       => '',
        'visible'       => true,
        'required'      => false,
        'visible_on_front' => true,
        'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'source' => 'eav/entity_attribute_source_boolean',
    ));

    $this->endSetup();

Edit :

You need to modify this file /app/code/community/WP/CustomMenu/Block and

find this public function drawCustomMenuItem and replace with this

 public function drawCustomMenuItem($category, $level = 0, $last = false)
    {
        if (!$category->getIsActive()) return;
        $htmlTop = array();
        $id = $category->getId();
        $isNew = $category->getIsNewCat()== 1 ? 'new-cat-class' : '';
        // --- Static Block ---
        $blockId = sprintf(self::CUSTOM_BLOCK_TEMPLATE, $id); // --- static block key
        #Mage::log($blockId);
        $collection = Mage::getModel('cms/block')->getCollection()
            ->addFieldToFilter('identifier', array(array('like' => $blockId . '_w%'), array('eq' => $blockId)))
            ->addFieldToFilter('is_active', 1);
        $blockId = $collection->getFirstItem()->getIdentifier();
        #Mage::log($blockId);
        $blockHtml = Mage::app()->getLayout()->createBlock('cms/block')->setBlockId($blockId)->toHtml();
        // --- Sub Categories ---
        $activeChildren = $this->_getActiveChildren($category, $level);
        // --- class for active category ---
        $active = ''; if ($this->isCategoryActive($category)) $active = ' act';
        // --- Popup functions for show ---
        $drawPopup = ($blockHtml || count($activeChildren));
        if ($drawPopup) {
            $htmlTop[] = '<div id="menu' . $id . '" class="menu' . $active . '" onmouseover="wpShowMenuPopup(this, event, \'popup' . $id . '\');" onmouseout="wpHideMenuPopup(this, event, \'popup' . $id . '\', \'menu' . $id . '\')">';
        } else {
            $htmlTop[] = '<div id="menu' . $id . '" class="menu' . $active . '">';
        }
        // --- Top Menu Item ---
        $htmlTop[] = '<div class="parentMenu">';
        if ($level == 0 && $drawPopup) {
            $htmlTop[] = '<a  class="level' . $level . $active .$isNew. '" href="javascript:void(0);" rel="'.$this->getCategoryUrl($category).'">';
        } else {
            $htmlTop[] = '<a  class="level' . $level . $active . .$isNew.'" href="'.$this->getCategoryUrl($category).'">';
        }
        $name = $this->escapeHtml($category->getName());
        if (Mage::getStoreConfig('custom_menu/general/non_breaking_space')) {
            $name = str_replace(' ', '&nbsp;', $name);
        }
        $htmlTop[] = '<span>' . $name . '</span>';
        $htmlTop[] = '</a>';
        $htmlTop[] = '</div>';
        $htmlTop[] = '</div>';
        $this->_topMenu[] = implode("\n", $htmlTop);
        // --- Add Popup block (hidden) ---
        if ($drawPopup) {
            $htmlPopup = array();
            // --- Popup function for hide ---
            $htmlPopup[] = '<div id="popup' . $id . '" class="wp-custom-menu-popup" onmouseout="wpHideMenuPopup(this, event, \'popup' . $id . '\', \'menu' . $id . '\')" onmouseover="wpPopupOver(this, event, \'popup' . $id . '\', \'menu' . $id . '\')">';
            // --- draw Sub Categories ---
            if (count($activeChildren)) {
                $columns = (int)Mage::getStoreConfig('custom_menu/columns/count');
                $htmlPopup[] = '<div class="block1">';
                $htmlPopup[] = $this->drawColumns($activeChildren, $columns);
                $htmlPopup[] = '<div class="clearBoth"></div>';
                $htmlPopup[] = '</div>';
            }
            // --- draw Custom User Block ---
            if ($blockHtml) {
                $htmlPopup[] = '<div id="' . $blockId . '" class="block2">';
                $htmlPopup[] = $blockHtml;
                $htmlPopup[] = '</div>';
            }
            $htmlPopup[] = '</div>';
            $this->_popupMenu[] = implode("\n", $htmlPopup);
        }
    }

and add this style

.new-cat-class{ color:red !important;}

Note: if this work revert back the changes and override this block with local module. http://inchoo.net/magento/overriding-magento-blocks-models-helpers-and-controllers/

Hope this will help you.

| improve this answer | |
  • @ arunendra : where i can below code, – Gem Dec 28 '16 at 6:39
  • i.imgur.com/txyORnW.png – Gem Dec 28 '16 at 6:40
  • @JeevaRathinam just read above the pink line "script must be located in the folder with the same name (in our case path will be ‘app/code/community/Atwix/CustomCategoryAttribute/sql/add_category_attribute’) " – Arunendra Dec 28 '16 at 6:46
  • could u pls join chat – Gem Dec 28 '16 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.