Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7940927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:30:47+00:00 2026-06-03T23:30:47+00:00

Heyo, been working on a magento theme for a little while now (… and

  • 0

Heyo, been working on a magento theme for a little while now (… and my understanding of the system is slowly but steadily growing). I need to start working on some custom modules soon, and so I’m starting with this little project to get my bearings:

I found a little bit of code to manage a specific task that I have been copying and pasting into template files:

<?php         
    $ids    = $_product->getCategoryIds(); 
    $cat    = Mage::getModel('catalog/category')->load($ids[0]);     
    $isFF   = false;
    foreach ($ids as $key=>$val) {
        $cat = Mage::getModel('catalog/category')->load($val);
        $name = $cat->getName(); 
        if ( $name === 'Fast Fulfillment' ) {
            $isFF = true;
        }
    }
    if ($isFF) { echo '<span class="ff-logo"></span>'; } 
?>

Very simple. I’m just checking to see if a product is in a specific category, and producing an element if it is. (I know there are about 5 solid ways of doing this… this is the one I went with).

I need to test this every time a product block is displayed, and have, up till now, been replicating this code to make it work. It does work, but is backasswards (I shouldn’t be putting logic into the view layer).

Ok – so, lets make a simple module to share the functionality:

local/WACI/ProductFlag/etc/config.xml

<config>
    <modules>
        <WACI_ProductFlag>
            <version>0.1.0</version>
        </WACI_ProductFlag>
    </modules>
    <global>
        <blocks>
            <WACI_ProductFlag>
                <class>WACI_ProductFlag_Block_View</class>
            </WACI_ProductFlag>
        </blocks>
    </global>
</config>

etc/modules/WACI_All.xml

<config>
    <modules>
        <WACI_CustomPageLayouts>
            <codePool>local</codePool>
            <active>true</active>
        </WACI_CustomPageLayouts>
    </modules>
    <modules>
        <WACI_ProductFlag>
            <codePool>local</codePool>
            <active>true</active>
        </WACI_ProductFlag>
    </modules>
</config>

Now, for the Class … I’m not really sure if a Block or a Helper is appropriate. I went with Block, but – idk… I’m probably wrong (tutorials for this stuff vary wildly).

local/WACI/ProductFlag/Block/View.php

<?php

    /**
     * WACI
     * 
     * @codepool   Local
     * @category   View
     * @package    WACI
     * @module      ProductFlag  
     */

    class WACI_ProductFlag_Block_View extends Mage_Core_Block_Template
    {
        private $_focus;
        private $_isFF = false;

        public function getIsFF( $product ){
            $this->_focus = "FF";
            $isFF   = false;
            $ids    = $product->getCategoryIds(); 
            $cat    = Mage::getModel('catalog/category')->load($ids[0]);   

            foreach ($ids as $key=>$val) {
                $cat = Mage::getModel('catalog/category')->load($val);
                $name = $cat->getName(); 

                if ( $name === 'Fast Fulfillment' ) {
                    $isFF = true;
                }
            }
        }

        protected function _toHtml(){
            $html = parent::_toHtml();

            if ($this->_focus === "FF") {
                if ($this->_isFF){
                    $html .= '<span class="ff-logo"></span>';
                }
            }

            return $html;
        }
    }
?>

Hopefully its clear that I only want to output a string based on the input of any given product. Should I be overriding the _toHtml() to deliver the string? Again. Probably not…

in my local.xml I reference the block:

<catalog_product_view>
<reference name="content">
            <reference name="product.info">
<block type="WACI/ProductFlag" name="product.flag" as="productFlag" output="toHtml" />...

… I’m not clear if this instantiates this class? I don’t think so. I’m not really sure how to address it in my product/view/media.phtml anyway, given that I need to call a method with a parameter.

I don’t think I need a template file, given that I’m just outputting a string, but I don’t think I’ve seen block modules without an associated template. Maybe a helper class is appropriate then?

Whatever the case, it ain’t workin.
I either get a fatal error saying my media class has no getIsFF() method (not surprising), or just nothing shows up. My config files are correct, but that’s about it, I think.

Jebus. I’m all turned around.

Can someone with Mage skillz clarify this simple issue and point me in the right direction?

Cheers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T23:30:48+00:00Added an answer on June 3, 2026 at 11:30 pm

    No advice? Well = I sussed out this slightly modified and working solution:

    local/WACI/ProductFlag/etc/config.xml

    <config>
        <modules>
            <WACI_ProductFlag>
                <version>0.1.0</version>
            </WACI_ProductFlag>
        </modules>
        <global>
            <blocks>
                <productflag>
                    <class>WACI_ProductFlag_Block</class>
                </productflag>
            </blocks>
            <helpers>
                <productflag>
                    <class>WACI_ProductFlag_Helper</class>
                </productflag>
            </helpers>
        </global>
    </config>
    

    local/WACI/ProductFlag/Helper/Flag.php

    class WACI_ProductFlag_Helper_Flag extends Mage_Core_Helper_Abstract
        {
            private $_isFF = false;
    
            public function getIsFF( $product ){
    
                $html   = '';
                $ids        = $product->getCategoryIds(); 
                $cat        = Mage::getModel('catalog/category')->load($ids[0]);   
    
                foreach ($ids as $key=>$val) {
                    $cat = Mage::getModel('catalog/category')->load($val);
                    $name = $cat->getName(); 
    
                    if ( $name === 'Fast Fulfillment' ) {
                        $this->_isFF = true;
                    }
                }
    
                if($this->_isFF) { 
                    $html = '<span class="ff-logo"></span>';
                }
    
                return $html;
            }
    
        }
    

    and call it up in any template file via the simple:

    <?php echo $this->helper('productflag/flag')->getIsFF($_product); ?>
    

    I’m still not sure if this is exactly appropriate to the magento way of doing things – ie the model calls, I think, should be relegated to their own class and dropped in a Model folder.

    Whatever the case – and for anyone else trying to figure this stuff out – as I monkeyed around with it I slowly realized the intent of the config.xml file is to add available factory classes to the blocks/helpers/model pools – and that the path is to the containing directory. The helper call in the template file, then, identifies the “short name” of the directory and then the actual class name.

    ie – You could have multiple classes of helpers:

    <?php echo $this->helper('productflag/class_one')->someMethod($_product); ?>
    <?php echo $this->helper('productflag/class_two')->someOtherMethod($_product); ?>
    <?php echo $this->helper('productflag/class_three')->yetAnotherMethod($_product); ?>
    

    So… One step closer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Heyo, I'm currently working on a project where I need to place the camera
Heyo, My class at college has us writing programs in assembly. I have never
Heyo. This is my first stack overflow post because I am stumped and not
Heyo, this is a bit of an extension of the Imports within imports question
Heyo, I'm using a 2000px width image as a background for a 960px width
Heyo, Odd question... is it possible/ ok. To use a combination of SESSION variables
Heyo, Just started writing an assembler for the imaginary computer my class is creating
Heyo! I am writing an application in Qt/C++ that creates connections between peers. The
So I've just started playing around with Django and I decided to give it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.