I have two custom blocks in my homepage of Magento. One of the blocks displays all the products. And the other block should display the product which was recently clicked on/viewed. I have created the observer for the event to get the clicked product data. How can I use this data from observer to show that product's data in my second block in the homepage? I have to pass the data from the observer somehow.
Observer.php
<?php
include 'C:\wamp64\www\magento1924\app\code\local\Company\Namespace\Block\Recommended.php';
class Company_Namespace_Model_Observer {
public function getProductData($observer) {
//Uncomment the line below to log what is contained here:
//Mage::log($observer);
$data = new Company_Namespace_Block_Recommended();
$product = $observer->getProduct();
$pId = $product->getId();
$pName = $product->getName();
//Mage::log($pId);
Mage::log($pName);
$data->recommended($pId, $pName);
}
}
?>
Block file Recommended.php
<?php
class Company_Namespace_Block_Recommended extends Mage_Core_Block_Template
{
public function recommended($pId, $pName){
echo $pId;
echo $pName;
echo "Test!";
}
}
?>
Recommended.phtml
<h1>Recently viewed</h1>
<?php
$this->recommended();
?>
So I'm using this function recommended() to print out the clicked product's data. When I'm in the homepage and I click something, it takes me to the product view page in which I can also see (in the upper part) the product's name and id and also "Test!"(which was also echoed out in the function). What I want to have is that since I'm also callin the same function recommended() out in the homepage (in the phtml file) I should see the products id, name and also "Test!". The problem is it is only showing the "Test!". Am I doing something totally wrong?