I have a widget where I need to get a parameter from user and then be able to use it inside my Helper/Data.php file.
The widget looks like
<?xml version="1.0" encoding="UTF-8"?>
<widgets>
<my_product_reviews type="reviewcontainer/product_container">
<name>My Review Container</name>
<description>Displays the product reviews for a given product in a widget</description>
<query_reviews_by>
<label>Get product reviews by</label>
<type>select</type>
<values>
<product_id translate="label">
<label>Product ID</label>
<value>id</value>
</product_id>
<product_sku translate="label">
<label>Product SKU</label>
<value>sku</value>
</product_sku>
</values>
<sort_order>10</sort_order>
<visible>1</visible>
<required>1</required>
</query_reviews_by>
I can access this params from my Block/Product/Container:
<?php
class My_Reviewcontainer_Block_Product_Container extends Mage_Core_Block_Template implements Mage_Widget_Block_Interface
{
/**
*
* Returns the parameter set on the widget for: query_reviews_by
*
* @return string
*/
public function getParamQueryReviewsBy()
{
if ($queryReviewsBy = $this->getData('query_reviews_by')) {
return $queryReviewsBy;
} else {
return '';
}
}
}
But how can I access it from my Helper:
<?php
/**
* Class My_ReviewContainer_Helper_Data
*/
class My_ReviewContainer_Helper_Data extends Mage_Core_Helper_Abstract
{
/**
* The constructor
*/
public function __construct()
{
// here for example
}
..
Best Answer
After reading some Magento books and tuts.. I found out that I should move the methods on the
Data.php
into a model becauseData.php
is just a helper class of the module and most of the time its just empty but required!So now in my templates, I call the block
Block\Product\Container.php
which calls the model usingMage::getModel('my_model_name_here',$params)
.. The params array contain the data I get from$this->getData()