Wednesday, 23 April 2014

Get Option Value by ID in Magento

<?php
$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("manufacturer");

if ($attr->usesSource()) {
    echo $color_label = $attr->getSource()->getOptionText(45);
}
?>

Note:- manufacturer (product attribute code)
            45 ==> (option value id)

Thursday, 17 April 2014

Magento Currency Symbol 404's when i go to admin

/app/code/core/Mage/CurrencySymbol/etc/config.xml

<currencysymbol>Mage_CurrencySymbol_Adminhtml</currencysymbol>
                                  Change to

<currencysymbol before="Mage_Adminhtml">Mage_CurrencySymbol_Adminhtml</currencysymbol>

Wednesday, 16 April 2014

How to check is object

if(is_object(Mage::registry('current_category')))

{

$GetCurrentCatName=Mage::registry('current_category')->getName();

}

Wednesday, 2 April 2014

How to resize product/custom image in magento


$_product = Mage::getModel('catalog/product')->load($_product->getId());
 <img src="<?php echo Mage::helper('catalog/image')->init($_product ,'image')->resize(224,299) ?>" />

Friday, 28 March 2014

Magento: Resize category image and thumbnail


<?php
$mediaPath=Mage::getBaseDir('media')."/catalog/category/resized/";
                        if(!is_dir($mediaPath)) mkdir($mediaPath,0777);
 foreach($collections as $subcate){

                                 
                                    $_curCat_sub = Mage::getModel('catalog/category')->load($subcate->getId());
                                    $count_sub = $_curCat_sub->getProductCount();
                                    $_subimage=$subcate->getThumbnail();
                                    if($_subimage!=''){
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail(); //Real path
                                 
                                 
                                    $_imageUrl=Mage::getBaseDir('media')."/catalog/category/".$subcate->getThumbnail();
                                 
                                    $imageResized=Mage::getBaseDir('media')."/catalog/category/resized/".$subcate->getThumbnail();
                                    $imageObj = new Varien_Image($_imageUrl);
                                    $imageObj->constrainOnly(TRUE);
                                    $imageObj->keepAspectRatio(TRUE);
                                    $imageObj->keepFrame(FALSE);
                                    $imageObj->resize(null,300);
                                    $imageObj->save($imageResized);
                                    $mediaurl= Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
                                    $imageResized = $mediaurl."/catalog/category/resized/".$subcate->getThumbnail();
?>
<img src="<?php echo $imageResized;?>"/>
<?php } ?>