Friday, March 22, 2013
Prevent visitors to view the store without login in Magento
>> Magento use methods : _redirect() AND _redirectUrl()
for redirect in Mage_Core_Controller_Varien_Action controller. If you see these methods, they are using this code to redirect $this->getResponse()->setRedirect('your_url');
Now you just need to call like :
Mage::app()->getFrontController()
->getResponse()
->setRedirect(Mage::getBaseUrl('your_url');
I used this code to prevent visitors to view my store without login.
With the following code in head.phtml :
<?php
$CusSession=mage::getSingleton('customer/session');
$frontController = Mage::app()->getFrontController();
if(!$CusSession->isLoggedIn() && $frontController->getRequest()->getActionName() != 'login')
{
$frontController->getResponse()->setRedirect(Mage::getUrl("customer/account/login"));
}
?>
Wednesday, February 20, 2013
How to add image in magento admin product Grid
>> With the help of this code you can able to add product image in admin Grid View :
Step 1:
First you need to copy the core block to local. Copy Grid.php from app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php to
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php
Here you'll find a method named _prepareColumns(), add the below code within this method
$this->addColumn('product_image', array(
'header' => Mage::helper('catalog')->__('Image'),
'align' =>'left',
'index' => 'entity_id',
'width' => '100px',
'renderer' => 'Mage_Adminhtml_Block_Catalog_Product_Renderer_Image'
));
Step 2:
Now create the renderer file named Image.php in the following path
app/code/local/Mage/Adminhtml/Block/Catalog/Product/Renderer/Image.php
Here add the below code..
class Mage_Adminhtml_Block_Catalog_Product_Renderer_Image extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$_product = Mage::getModel('catalog/product')->load($row->getEntityId());
if($_product->getImage() != 'no_selection'){
$image = "<img src='".Mage::helper('catalog/image')->init($_product, 'image')->resize(100)."' title='".$_product->getName()."' />";
}
return $image;
}
}
Tuesday, February 19, 2013
Use INR symbol in magento
>> By default magento shows indian rupee as "Rs". If you want to show the symbol.
₹ = ₹
₨ = ₨
i.e. ₹ 1,200 would show ₹ 1,200
Note* : Use the font DejaVu Sans <span style='font-family: DejaVu Sans;'>₹</span> for Internet Explorer and Safari.
>> Go to Admin=>System=>Configuration=>Manage Currency=>Symbols. Replace the symbol.
>> Here is a useful extension that will help you to replace rupee to new symbol. You can configure this one.
http://www.magentocommerce.com/magento-connect/et-currency-manager.html
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.. :-)
<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>
:-)
Subscribe to:
Comments (Atom)