Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

3
Need Help Understanding productAttribute() Method for Product Pages
Post Body

I am developing a custom product page for our store and I need help familiarizing myself with helpers, their methods, and product attributes. Specifically: $_helper->productAttribute($product, $attributeHtml, $attributeName)

Here are the files I am using/reviewing: app\code\core\Mage\catalog\helper\output.php app\design\frontend[theme name]\template\catalog\product\view\media.phtml

My first goal in customizing the page is to edit the width of the product image. The following line of code generates the html for the product image.

echo $_helper->productAttribute($_product, $_img, 'image');

Why do we need this method if we can simply echo the img html described in the previous line?

What exactly is being returned and why I would use this method? The following pieces of code are what I'd like to understand the most and if someone could explain it to me, I'd greatly appreciate it.

public function getHandlers($method)
{
    $method = strtolower($method);
    return isset($this->_handlers[$method]) ? $this->_handlers[$method] : array();
}

public function process($method, $result, $params)
{
    foreach ($this->getHandlers($method) as $handler) {
        if (method_exists($handler, $method)) {
            $result = $handler->$method($this, $result, $params);
        }
    }
    return $result;
}

public function productAttribute($product, $attributeHtml, $attributeName)
{
    /* Code that is not relevant to this example */

    $attributeHtml = $this->process('productAttribute', $attributeHtml, array(
        'product'   => $product,
        'attribute' => $attributeName
    ));

    return $attributeHtml;
}

Thank you for any help. [Edited to be concise]

Author
Account Strength
100%
Account Age
12 years
Verified Email
Yes
Verified Flair
No
Total Karma
8,694
Link Karma
3,873
Comment Karma
4,735
Profile updated: 3 days ago
Posts updated: 1 year ago
DEVELOPER

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
11 years ago