Friday, September 21, 2012

Magento : Paypal is not working in Magento for Multishipping

Override folowing file code/core/Mage/Paypal/Model/Standard.php and Replace following code
protected $_canUseForMultishipping = flase; with protected $_canUseForMultishipping = true;

Magento : How to change product folder name in media

Rename product folder( media/catalog/product) to any name (like custom_product)

You need to change from all media path ‘product’ to ‘products’ to below listed files.

file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'product'.DS.$size.DS.$image)
to
file_exists(Mage::getBaseDir('media').DS.'catalog'.DS.'custom_product '.DS.$size.DS.$image)

Replace following code 'catalog/product/' to 'catalog/custom_product/' in following files
 Product/Attribute/Frontend/Image.php
 Product/Attribute/Media/Image.php
Product/Image.php
 Product/Media/Config.php
 Entity/Product/Attribute/Frontend/Image.php

Magento : How to encode product path image


Override following file /app/Local/Mage/Catalog/Helper/Image.php
and add following code
public function base64_encode_image ($filename=string) {
if ($filename) {

$forFiletype = explode('.',$ filename);
$forFiletype = array_reverse($forFiletype);
$filetype = $forFiletype[0];
if(strtoupper($filetype) == 'JPG')
{
$filetype = 'jpeg';
}
$base64image = '';
$changeFilePath = explode(‘cache’,$filename);
$changeFilePath = Mage::getBaseDir(). DS. ‘media’. DS. ‘catalog’.DS.’products’.DS.’cache’.$changeFilePath[1];
$imgbinary = fread(fopen($changeFilePath, “r”), filesize($changeFilePath));
return ‘data:image/’ . $filetype . ‘;base64,’ . base64_encode($imgbinary);
}
}

Now use in /app/design/catalog/product/list.phtml as
$this->helper('catalog/image')->init($_product, 'small_image')->resize(193,250);
$base64image = $this->helper('catalog/image')->base64_encode_image($product_image,$filetype);
<img src="<?php echo $this->getSkinUrl('images/spacer.png'); ?>" width="193" height="250" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" style="background:url(<?php echo $base64image;?>) no-repeat;"/>

Magento : Integrity constraint violation Column in where clause is ambiguous

Generally, This types of error come, when we are using join query or custom module 
Add ‘filter_index’=>’main_table.column_name’ in $this->addColumn() function

As
$this->addColumn('column_name', array(
'header' => Mage::helper('module')->__('Column Value'),
'align' =>'left',
'index' => 'column_name',
'filter_index'=>'main_table.column_name', // This parameter helps to resolve above error
));

Magento : Add custom column from custom table in magento admin grid


Use columns() method in collection as
 $collection->getSelect()->columns(new Zend_Db_Expr("[expression or any myql sub query] as custom_column"));

For example:

Consider Bd_Test module and override _prepareCollection() method in admin grid

protected function _prepareCollection()
                {
                 $collection = Mage::getModel('test/test')->getCollection();
     
                  $collection->getSelect()->columns(new Zend_Db_Expr("if((SELECT count(*) FROM table_name as  table_alias  WHERE table_alias.column > main_alias. column ) , 'NO', 'YES') as custom_column"));
               // echo $collection->getSelect();
                                $this->setCollection($collection);
                                return parent::_prepareCollection();
                }

Wednesday, September 19, 2012

Magento: Add google translator in website


Add following script in any template file

<div id="google_translate_element"></div><script>
function googleTranslateElementInit() {
  new google.translate.TranslateElement({
    pageLanguage: 'en'
  }, 'google_translate_element');
}
</script><script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>

Monday, September 17, 2012

Show More /Less link using jQuery

Sample text:
<div class="comment more">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    Vestibulum laoreet, nunc eget laoreet sagittis,
    quam ligula sodales orci, congue imperdiet eros tortor ac lectus.
    Duis eget nisl orci. Aliquam mattis purus non mauris
    blandit id luctus felis convallis.
    Integer varius egestas vestibulum.
    Nullam a dolor arcu, ac tempor elit. Donec.
</div>
 
 
CSS: 

a {
    color: #0254EB
}
a:visited {
    color: #0254EB
}
a.morelink {
    text-decoration:none;
    outline: none;
}
.morecontent span {
    display: none;
}
.comment {
    width: 400px;
    background-color: #f0f0f0;
    margin: 10px;
}
 
Javascript:
$(document).ready(function() {
    var showChar = 100;
    var ellipsestext = "...";
    var moretext = "more";
    var lesstext = "less";
    $('.more').each(function() {
        var content = $(this).html();
 
        if(content.length > showChar) {
 
            var c = content.substr(0, showChar);
            var h = content.substr(showChar, content.length - showChar);
 
            var html = c + '<span class="moreellipses">' + ellipsestext+ '&nbsp;</span><span class="morecontent"><span>' + h + '</span>&nbsp;&nbsp;<a href="" class="morelink">' + moretext + '</a></span>';
 
            $(this).html(html);
        }
 
    });
 
    $(".morelink").click(function(){
        if($(this).hasClass("less")) {
            $(this).removeClass("less");
            $(this).html(moretext);
        } else {
            $(this).addClass("less");
            $(this).html(lesstext);
        }
        $(this).parent().prev().toggle();
        $(this).prev().toggle();
        return false;
    });
});