Month: April 2014

Get Attribute label easily on Magento

Posted on Updated on

 private static function getAttributeLabel($attributeCode)
{
$query = “SELECT frontend_label FROM eav_attribute WHERE attribute_code = ‘”.$attributeCode.”‘;”;
$data = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchOne($query);
return $data;
}

Get Category by Product and Store – Magento with direct SQL

Posted on Updated on

  private static function getCategoryByProductAndStore($productId, $storeId, $isParent = 0)
{
$query = ‘SELECT category_id FROM `catalog_category_product_index` WHERE product_id = ‘ . $productId
. ‘ AND store_id=’ . $storeId . ‘ AND is_parent=’ . $isParent . ‘;’;
$data = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’)->fetchAll($query);
return $data;
}

Calling to functions of Magento

Posted on Updated on

On your Config.xml

<?xml version=”1.0″?>
<config>
<modules>
<MyNamespace_MyModule>
<version>0.1.0</version>
</MyNamespace_MyModule>
</modules>
<global>
<helpers>
<module>
<class>MyNamespace_MyModule_Helper</class>
</module>
</helpers>

<models>
<module>
<class>MyNamespace_MyModule_Model</class>
</module>
</models>

</global>
</config>

Calling Model
Mage::getModel(‘module/modelname’)->callYourfunction();

calling Helper
Mage::helper(‘module’)->callYourfunction();