Tuesday, January 22, 2013

How to resize product/custom image in magento


>> Resize product image with product object.

          <img src="<?php echo Mage::helper('catalog/image')->init($_product, 'image')->resize(70,155);?>"/>


>> Resize a custom Image.

        // Image name
        $image = "";

        // actual image path
        $imageUrl = Mage::getBaseDir('media'). DS .'justonestepsolution'. DS .$image;
    
        // Give resized image path to be saved
        // here, the resized image will save in media/justonestepsolution/resized folder
        $imageResized = Mage::getBaseDir('media'). DS .'justonestepsolution'. DS .'resized'. DS .$image;
    
        // image will resize only if the image file exists and the resized image file doesn't exist

        if (!file_exists($imageResized) && file_exists($imageUrl))
        {
            $imageObj = new Varien_Image($imageUrl);
            $imageObj->constrainOnly(TRUE);
            $imageObj->keepAspectRatio(TRUE);
            $imageObj->keepFrame(FALSE);
            $imageObj->resize(300, null);
            $imageObj->save($imageResized);
        }


enjoy :-)



Tuesday, January 15, 2013

Get current logged customer details in magento


>>  $CusSession=mage::getSingleton('customer/session');
    //Checking is logged in customer
    if($CusSession->isLoggedIn())
    {
        $customer    = $CusSession->getCustomer();     // Customer object
        $name        = $customer->getName();
    }

Wednesday, January 9, 2013

Simple jQuery/html tab

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery Simple Tab</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
     jQuery(".tab_content").hide();
     jQuery("ul.tabs li:first").addClass("active").show();
     jQuery(".tab_content:first").show();
  
     //On Click Event
     jQuery("ul.tabs li").click(function() {
         if(!jQuery(this).hasClass('active')){
            jQuery("ul.tabs li").removeClass("active");
            jQuery(this).addClass("active");
            jQuery(".tab_content").hide();
          
            var activeTab = jQuery(this).find("a").attr("href");
            jQuery(activeTab).fadeIn();
            return false;
         }else{
            return false;
         }
     });

});
</script>
<style type="text/css">
.details-tab-container{width: 800px; height:auto; position:absolute;}
.details-tab{ width:800px; float:left;}
.details-tab ul.tabs{ list-style-type:none;}
.details-tab li{background:#999; border:1px solid; float:left; padding:3px; margin:1px; border-radius: 6px;}
.details-tab li.active{background:#000;}
.details-tab li.active a{color:#FFF; font-size:14px; }
.details-tab li a{ text-decoration:none; font-family:Verdana, Geneva, sans-serif; font-weight:bold; font-size:11px; color:#000;}
.tab-container{ width:800px; float:left; border:2px solid;}
</style>
</head>

<body>
<div class="details-tab-container">
  <div class="details-tab">
    <ul class="tabs">
      <li><a href="#description"><span>Product Description</span></a></li>
      <li><a href="#attribute"><span>Product Attributes</span></a></li>
      <li><a href="#review"><span>Product Reviews</span></a></li>
    </ul>
  </div>
  <div class="tab-container">
    <div class="tab_content" id="description">Description Lorem ipsum dolor sit amet, tation intellegebat cum ea, at vidit splendide has, te sit ridens salutatus abhorreant. Eum te augue cetero. Clita interpretaris eos cu. Per no senserit suscipiantur. Altera molestie eos ad, pro no fierent periculis. Ponderum convenire sit no.</div>
    <div class="tab_content" id="attribute">Attributes Lorem ipsum dolor sit amet, tation intellegebat cum ea, at vidit splendide has, te sit ridens salutatus abhorreant. Eum te augue cetero. Clita interpretaris eos cu. Per no senserit suscipiantur. Altera molestie eos ad, pro no fierent periculis. Ponderum convenire sit no.</div>
    <div class="tab_content" id="review">Review Lorem ipsum dolor sit amet, tation intellegebat cum ea, at vidit splendide has, te sit ridens salutatus abhorreant. Eum te augue cetero. Clita interpretaris eos cu. Per no senserit suscipiantur. Altera molestie eos ad, pro no fierent periculis. Ponderum convenire sit no.</div>
  </div>
</div>
</body>
</html>

see the demo here..  :-)

Add social share button with custom image in your web page


>> Add facebook share...
            <a href="javascript:;" onclick="window.open('http://www.facebook.com/share.php?u=your page url','facebook share','resizable=yes,width=700,height=500,scrollbars=yes,status=yes')"><img alt="facebook" src="yourimage.jpg"></a>

>> Twitter Share...
            <a href="javascript:;" onclick="window.open('https://twitter.com/share','twitter share','resizable=yes,width=700,height=500,scrollbars=yes,status=yes')"><img alt="twitter" src="yourimage.jpg"/></a>

>> Pin It share ....
            <a target="_blank" href="http://pinterest.com/pin/create/button/?url=your page url&media=image url&description=image description" class="pin-it-share" count-layout="horizontal"><img alt="pinit" src="yourimage.jpg"></a>


:-)


Thursday, January 3, 2013

Magento Error : "You cannot define a correlation name 'size_idx' more than once"....


>> The error occurs if you use <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/> this block twice in your catalog.xml(in your theme folder).
Make sure there is only one layered block.

I got this error when I copied the leftnav block within content block without removing the leftnav block from the left block.

<reference name="left">
            <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/>
</reference>
<reference name="content">
            <block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
                <block type="catalog/layer_view" name="content.leftnav" as="cat_left_nav" template="catalog/layer/view.phtml"/>
</reference>