0

I try to get the product data in my module. I tried to find a solution without

Mage::getModel('catalog/product')->load($id)

My module is embedded in the product detail site. So, when I load the site the data of this product is already loaded. How and where can I access this data?

  • Should I use any observers?

  • Is it stored in session?

May be some body can help me :)

1

i want to answer my question with my solution:

i did it in this way:

  1. add session Object from Magento in the modul template
  2. add to the 'core/session' new value from registry('curent_product')
  3. the controller which is calling with ajax can now access the product id or ather stuff over the session

here is the code:

phtml - File

$_product = Mage::registry('current_product');
$zwSession = Mage::getSingleton('core/session', array('name'=>'frontend'));
$zwSession->setProductId($_product->getData('entity_id'));

here the controller:

 $zwProductId = Mage::getSingleton('core/session')->getProductId();
 $zwProduct = Mage::getModel('catalog/product')->load($zwProductId);
 $zwProduct->getData('od3_json');

So it works know like i need.

But is it nice? ;)

0

If you're on the product page you can access the current product using:

$_product = Mage::registry('current_product');

3
  • Great idea! But i get NULL. Is there a possibility to see all registered parameters? – Ivan Gartsev May 6 '16 at 13:06
  • How are you trying to access the value? What page are you on when you're trying to get the product? – Paul May 6 '16 at 13:36
  • It was my mistake. I try to do it in the Modul controller. This is wrong, becouse in this case the modul controller knows nothing from the product ;). I try it out in the template of the modul which is loaded in product this works fine. But this is not the solution i am looking for :( – Ivan Gartsev May 11 '16 at 15:02
0

Add your custom module template file in local Xml file with handle such as

< reference name="product.info"> < /reference>

then Mage::register() method work.

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.