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 8862619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:46:18+00:00 2026-06-14T15:46:18+00:00

How do I retrieve my ProductId parameter from my container? ANSWER: You dont retrieve

  • 0

How do I retrieve my ProductId parameter from my container?

ANSWER: You dont retrieve a paramater from the container but from your block.
I’ve read the answers on stack, but none of them tells me how to retrieve the parameter from the container..

EDIT: Thanks to the answers I resloved my question! Working code below.

View.php: /app/code/local/Stackoverflow/Testcase/Block

class Stackoverflow_Testcase_Block_View extends Mage_Core_Block_Template
{

public function getParameters() {


    if (Mage::registry('current_product')) { 

        $product_id = Mage::registry('current_product')->getId(); 

    } else { 

        $product_id = $this->getProductId(); 

    }

    //Make sure we are not cached

    echo "time:".time()."<br/>";

    //This variable will be visible after the second load because it must be cached first!
    //NOTE that you are not able to save variables with an underscore ;-)

    echo "test_var:".$this->getTestVar()."<br/>";

    return "product_id: ".$product_id;

}

public function getCacheKeyInfo()
{
    $info = parent::getCacheKeyInfo();
    if (Mage::registry('current_product'))
    {
        $info['product_id'] = Mage::registry('current_product')->getId();
    }

    $info['test_var'] = "first second third";

    return $info;
}


}

Testcase.php: /app/code/local/Stackoverflow/Testcase/Model/Container

class Stackoverflow_Testcase_Model_Container_Testcase extends Enterprise_PageCache_Model_Container_Abstract { 



protected function _getIdentifier()
{
    return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
}


protected function _getCacheId()
{
    return 'TESTCASE' . md5($this->_placeholder->getAttribute('cache_id') . ',' . $this->_placeholder->getAttribute('product_id')) . '_' . $this->_getIdentifier();
}


protected function _renderBlock()
{
    $blockClass = $this->_placeholder->getAttribute('block');
    $template = $this->_placeholder->getAttribute('template');

    $block = new $blockClass;
    $block->setTemplate($template)
        ->setProductId($this->_placeholder->getAttribute('product_id'))
        ->setTestVar($this->_placeholder->getAttribute('test_var'));



    return $block->toHtml();
}

protected function _saveCache($data, $id, $tags = array(), $lifetime = null) { return false; }  





}

testcase.phtml: app/design/frontend/xxx/default/template/stackoverflow

    $block_html = $this->getParameters();

    echo $block_html;

?>

Catalog.xml: app/design/frontend/ll/default/layout

`

    <label>Catalog Product View (Simple)</label>

    <reference name="product.info">

        <block type="catalog/product_view_type_simple" name="product.info.simple" as="product_type_data" template="catalog/product/view/type/default.phtml">

            <block type="core/text_list" name="product.info.simple.extra" as="product_type_data_extra" translate="label">

                <label>Product Extra Info</label>

            </block>

            <block type="testcase/view" name="testcase" as="testcase" template="stackoverflow/testcase.phtml"/>

        </block>

    </reference>

</PRODUCT_TYPE_simple>

`

default.phtml: app/design/frontend/xxx/default/template/catalog/product/view/

<?php echo $this->getChildHtml('testcase') ?>

The code below is probably unrelevant but….
config.xml: /app/code/local/Stackoverflow/Testcase/etc

<?xml version="1.0"?>
<config>
    <modules>
        <Stackoverflow_Testcase>
            <version>0.1.0</version>
        </Stackoverflow_Testcase>
    </modules>
    <global>
        <blocks>
            <testcase>
                <class>Stackoverflow_Testcase_Block</class>
            </testcase>
        </blocks>
    </global>
</config>

cache.xml: /app/code/local/Stackoverflow/Testcase/etc

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <placeholders>
        <stackoverflow_testcase>
            <block>testcase/view</block>
            <name>testcase</name>
            <placeholder>STACKOVERFLOW_TESTCASE</placeholder>
            <container>Stackoverflow_Testcase_Model_Container_Testcase</container>
            <cache_lifetime>1</cache_lifetime>
        </stackoverflow_testcase>
    </placeholders>
</config>

Stackoverflow_Testcase.xml: /app/etc/modules

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

Thanks,

Martijn

  • 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-14T15:46:19+00:00Added an answer on June 14, 2026 at 3:46 pm

    Take a look at the Enterprise_PageCache_Model_Container_Sidebar_Cart Container for an example :

    file:
    app/code/core/Enterprise/PageCache/Model/Container/Sidebar/Cart.php

    $renders = $this->_placeholder->getAttribute('item_renders');
    

    In order to access a variable in your container, you need to add it to your cachekeyinfo in the Block class :

    file : app/code/core/Mage/Checkout/Block/Cart/Sidebar.php

    public function getCacheKeyInfo()
        {
            $cacheKeyInfo = parent::getCacheKeyInfo();
            $cacheKeyInfo['item_renders'] = $this->_serializeRenders();
            return $cacheKeyInfo;
        }
    

    edit:

    try this in your container :

    protected function _renderBlock()
        {
            $blockClass = $this->_placeholder->getAttribute('block');
            $template = $this->_placeholder->getAttribute('template');
    
            $block = new $blockClass;
            $block->setTemplate($template)
                ->setProductId($this->_placeholder->getAttribute('product_id'););
            return $block->toHtml();
        }
    

    and try this in your block :

    public function getCacheKeyInfo()
        {
            $cacheKeyInfo = parent::getCacheKeyInfo();
            $cacheKeyInfo['product_id'] = $this->getRequest()->getParam('ProductId');
            return $cacheKeyInfo;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve product information from magento by calling its web service using
In my block code I am trying to programmatically retrieve a list of products
Retrieve code from json. C#code:- var collection = getsortcat.Select(x => new { idterm =
To retrieve k random numbers from an array of undetermined size we use a
I retrieve mail using net/pop , but I also need to parse through the
I retrieve 6 values(say name, age, sex, address, id, tag) from a web service.
I retrieve data from db like that: select * from MOVIE_COMMENT where USER_ID =
I have two tables and need to retrieve some columns from both tables based
I am trying to retrieve and store ID's for each item retrieved from my
When I retrieve all orders and their OrderDetails from ASP.NET MVC through WCF 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.