Magento

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;
}

Advertisements

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();

ereg_replace deprecated

Posted on

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

USE

$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

### NEW REWRITE – REMOVE TAILING SLASHES
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.

tax_percent
tax_class_id

$products = Mage::getResourceModel(‘catalog/product_collection’);
$products->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘configurable’));
$products->addAttributeToFilter(‘status’, 1);
$products->addAttributeToFilter(‘visibility’, 4);
$products->addAttributeToSelect(‘sku’);
$products->addAttributeToSelect(‘name’);
$products->addAttributeToSelect(‘description’);
$products->addAttributeToSelect(‘short_description’);
$products->addAttributeToSelect(‘url’);
$products->addAttributeToSelect(‘image’);
$products->addAttributeToSelect(‘price’);
$products->addAttributeToSelect(‘special_price’);
$products->addAttributeToSelect(‘manufacturer’);
$products->addAttributeToSelect(‘category_ids’);
$products->addAttributeToSelect(‘gender’);
$products->addAttributeToSelect(‘tax_percent’);
$products->addAttributeToSelect(‘tax_class_id’);

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;

}