0

Is it possible to use a small function without creating an entire module to use a helper? I don't have a lot of experience with that, and I would prefer if I could just use the function without having to do all that.

For example this answer:

Do I have to create a module to use that function in a phtml file?

public function getCustomMenuCategory($categoryId) {

    try {            
            $categoryChild = Mage::getModel('catalog/category')->load($categoryId)->getChildrenCategories();
            if (count($categoryChild) > 0) {
                return $categoryChild;
            } else {
                $parentcategories = Mage::getModel('catalog/category')->load($categoryId)->getParentCategory()->getChildrenCategories();
                return $parentcategories;
            }
        } 
    } catch (Exception $ex) {
        Mage::log($ex, null, 'subcategory.log');
    }
}

^ that is what I want to use in a phtml file.

1 Answer 1

0

You can use helper class of core magento helper class using overriding the magento core helper into your local and put this code into core magento helper class.

In your local create directory like Mage -> Catalog -> Helper and put Data helper inside that folder/directory.

Put your code at the end of file.

You can call your function using catalog helper.

Mage::helper('catalog')->getCustomMenuCategory($categoryId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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