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″?>



Calling Model

calling Helper

ereg_replace deprecated

Posted on

$hex = ereg_replace(“#”, “”, $hex);


$hex = preg_replace(‘/#/’, ”, $hex);

Remove trailling slashes on Magento

Posted on Updated on

Tailing slash can be removed using followings on .htaccess file with rewrite module

Options +FollowSymLinks
RewriteEngine on

RewriteBase /
RewriteCond %{REQUEST_URI} !^/checkout.*$
RewriteCond %{REQUEST_URI} !^/index.php\/admin.*$
RewriteRule ^(.+)/$ /$1 [L,R=301]

How to fix one cent of additional price added on total as tax and rounding on Magento

Posted on Updated on

Go to System->Configuration->SALES->Tax->Calculation Settings

Set the Calculation Method Based On Row Total.

Row total will calculate based on each item total. Sot it will be accurate than calculating tax on Total. This will fix the issue of one cent hat could be shown as a rounding issue.

The setting can be used as the rules and lows of taxation on relevant country but here if there is no restriction, issue will be fixed.

Magento Tax on Row

Magento if tax is not included on configurable product

Posted on Updated on

if tax are not included on configurable product, You have to check following attributes if query does not include them itself.


$products = Mage::getResourceModel(‘catalog/product_collection’);
$products->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘configurable’));
$products->addAttributeToFilter(‘status’, 1);
$products->addAttributeToFilter(‘visibility’, 4);

foreach ($products as $product) {
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();

//Original Price with Tax
echo number_format(Mage::helper(‘tax’)->getPrice($product, $product->getPrice()),2, ‘.’, ”).$currency_code;

//Special Price with Tax
$product_data[‘sale_price’] = number_format(Mage::helper(‘tax’)->getPrice($product, $product->getSpecialPrice()),2, ‘.’, ”).$currency_code;