Wednesday, August 13, 2014

How to change core configuration data in magento programmatically

$coreConfig = Mage::getModel('core/config');
$coreConfig ->saveConfig($path, $value, $scope = ‘default’, $scopeId = 0);

For it magento use core_config_data table and
core_config_data table contain two important fields scope and scope_id.
There are three scope types
    default
    websites
    stores
If scope is set to default then scope_id is always 0.
If scope is set to websites then scope_id is website_id.
If scope is set to stores then scope_id is store_id(store view).
Imagine that we need to get some config value.
How Magento will get the it for current store view?
Search value by priority:
    scope == stores and scope_id == store_id(store view)
    scope == websites and scope_id == website_id (to which belongs current store view)
    scope == default
    default section of config.xml

Wednesday, July 30, 2014

Magento : Difference between “Flush Magento Cache” and “Flush Cache Storage” in magento cache management

Flush Magento Cache

Removes all items in the default Magento cache (var/cache) and the var/full_page cache that have a Magento tag

Flush Cache Storage

Removes all items in the cache. This is the equivalent of deleting the entire contents of the cache folder on the server.If your system uses an alternate cache location, any cached files used by other applications will be removed.

Sunday, June 15, 2014

Add wysiwyg editor in Magento Custom Module

Considering custom module Bd_Demo

Add following function in Bd_Demo_Block_Adminhtml_Demo_Edit

protected function _prepareLayout() {
    parent::_prepareLayout();
    if (Mage::getSingleton('cms/wysiwyg_config')->isEnabled()) {
        $this->getLayout()->getBlock('head')->setCanLoadTinyMce(true);
    }
}

Then use as in grid from  Bd_Demo_Block_Adminhtml_Demo_Edit_Tab_Form
$fieldset->addField("wood_description", "editor", array(
"label" => Mage::helper("woodflooring")->__("Description"),
"class" => "required-entry",
"required" => true,
"name" => "wood_description",
'config'    => Mage::getSingleton('cms/wysiwyg_config')->getConfig(),
'wysiwyg'   => true,
));

Wednesday, May 14, 2014

Accordion using jQuery

<div id="accordion">
  <h3 class="title">First header</h3>
  <div class="content">First content panel</div>
  <h3 class="title">Second header</h3>
  <div class="content">Second content panel</div>
</div>

<style>
.content{display:none;}
</style>

//Type One
<script>
jQuery('#accordion .title').each(function(){
jQuery(this).addClass('active');
jQuery(this).toggle(function(){
jQuery(this).addClass('active').next().slideDown(200);
},function(){
jQuery(this).removeClass('active').next().slideUp(200);
})
}); 
</script>

//Type Two
<script>
a = jQuery('.footer-menu').find('#accordion .title');
console.log(a.hasClass('active'));
jQuery('#accordion .title').click(function(e){ 
e.preventDefault();
speed = 300;
if(jQuery(this).hasClass('active') === true) {
} else if(a.hasClass('active') === false) {
jQuery(this).addClass('active').next('.content').slideDown(speed);
} else {
a.removeClass('active').next('.content').slideUp(speed);
jQuery(this).addClass('active').next('.content').delay(speed).slideDown(speed);
}
});
</script>

Tuesday, May 6, 2014

Magento : SQL Injection in Magento

SQL injection is a technique where malicious users can inject SQL commands into an SQL statement, via web page input.

Binding is the way to go for direct queries in Magento.
As
$write = Mage::getSingleton("core/resource")->getConnection("core_write");
$query = "insert into table_name(name, email, company, description) values (:name, :email, :company, :desc)";
$binds = array(
    'name'      => "name' or 1=1",
    'email'     => "email",
    'company'   => "company",
    'desc'      => "desc",
);
$write->query($query, $binds);

Monday, April 21, 2014

Add a link to show Desktop View for responsive site

       <span class="destop-versite">View Desktop Version</span>
var targetWidth = 1280;

jQuery('.destop-versite').bind('click', function(){
jQuery('meta[name="viewport"]').attr('content', 'width=' + targetWidth);
});

Tuesday, April 1, 2014

How to add sharing functionality to website

<?php
$message='';
$url=urlencode($url);
?>
<div class="share-this">
<span><?php echo $this->__('Share this article on');?></span>
    <ul>
                    <li class="fb-share">
                    <a href="javascript:poptastic('https://www.facebook.com/sharer/sharer.php?u=<?php echo $url; ?>')" title="<?php echo $this->__('Share on Facebook'); ?>">Facebook</a>
                    </li>

<li class="twitter-share">
                    <a href="javascript:poptastic('http://twitter.com/intent/tweet?text=<?php echo $message; ?>&url=<?php echo $url; ?>');" title="<?php echo $this->__('Share With Twitter'); ?>">Tweet</a>
                    </li>
                 
<li class="zing-share">
<a href="javascript:poptastic('http://link.apps.zing.vn/share?u=<?php echo $url; ?>&t=&desc=&images=&media=&width=0&height=0')">Zing</a>
                   </li>
                 
<script>
function poptastic(url) {
      var newWindow = window.open(url, 'name', 'height=600,width=450,top=100,left=500');
      if (window.focus) {
        newWindow.focus();
      }
   
 }
</script>
                 
            </ul>
</div>

Thursday, March 27, 2014

Wednesday, March 19, 2014

Magento : Sort By Newest Product In Category Page

Create a custom module. Suppose, Bd_Sortbynew

Write following code in config.xml
<?xml version="1.0"?>
<config>
<modules>
<Bd_Sortbynew>
<version>0.1.0</version>
</Bd_Sortbynew>
</modules>
<global>
<resources>
<sortbynew_setup>
<setup>
<module>Bd_Sortbynew</module>
                    <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</sortbynew_setup>
</resources>
    </global>
</config>

Then create a sql installer file with following code
$installer = $this;
$installer->startSetup();
$prodEntityTypeId = $installer->getEntityTypeId('catalog_product');
$installer->updateAttribute($prodEntityTypeId, 'created_at', 'frontend_label', 'New');
$installer->updateAttribute($prodEntityTypeId, 'created_at', 'used_for_sort_by', 1);
$installer->endSetup();

For revert you can use following script

require 'app/Mage.php';
Mage::app();

$eavAttribute = new Mage_Eav_Model_Mysql4_Entity_Attribute();
$attribute_id = $eavAttribute->getIdByCode('catalog_product', 'created_at');
if($attribute_id) {
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql  = "update catalog_eav_attribute SET used_for_sort_by = 1 where attribute_id = '$attribute_id' limit 1";
$write->query($sql);
} else {
echo 'Error!';
}

Monday, March 3, 2014

Magento : How do I add a frontend date picker

First create your own module, then follow following step as
1. Add following css & js on that page as
<reference name="head">
        <action method="addItem"><type>js_css</type><name>calendar/calendar-win2k-1.css</name><params/><!--<if/><condition>can_load_calendar_js</condition>--></action>
        <action method="addItem"><type>js</type><name>calendar/calendar.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
        <action method="addItem"><type>js</type><name>calendar/calendar-setup.js</name><!--<params/><if/><condition>can_load_calendar_js</condition>--></action>
</reference>

2. Add date filed in your form as
<div class="input-box">                        
                        <input type="text" name="dob" id="dob" title="<?php echo Mage::helper('team')->__('Date Of Birth') ?>" value="" class="input-text required-entry" /> 
                        <img title="Select date" id="dob_trig" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN) . 'adminhtml/default/default/images/grid-cal.gif'; ?>"  class="v-middle"/>
                        <?php echo $this->getLayout()->createBlock('core/html_calendar')->setTemplate('page/js/calendar.phtml'); ?>
                        <script type="text/javascript">
                            Calendar.setup({
                            inputField : 'dob',
                            ifFormat : '%m/%e/%y',
                            button : 'dob_trig',
                            align : 'Bl',
                            singleClick : true
                            });
                        </script> 

<script type="text/javascript">
//<![CDATA[
enUS = {"m":{"wide":["January","February","March","April","May","June","July","August","September","October","November","December"],"abbr":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]}}; // en_US locale reference
Calendar._DN = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]; // full day names
Calendar._SDN = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]; // short day names
Calendar._FD = 0; // First day of the week. "0" means display Sunday first, "1" means display Monday first, etc.
Calendar._MN = ["January","February","March","April","May","June","July","August","September","October","November","December"]; // full month names
Calendar._SMN = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; // short month names
Calendar._am = "AM"; // am/pm
Calendar._pm = "PM";

// tooltips
Calendar._TT = {};
Calendar._TT["INFO"] = "About the calendar";

Calendar._TT["ABOUT"] =
"DHTML Date/Time Selector\n" +
"(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +
"For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
"Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
"\n\n" +
"Date selection:\n" +
"- Use the \xab, \xbb buttons to select year\n" +
"- Use the " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " buttons to select month\n" +
"- Hold mouse button on any of the above buttons for faster selection.";
Calendar._TT["ABOUT_TIME"] = "\n\n" +
"Time selection:\n" +
"- Click on any of the time parts to increase it\n" +
"- or Shift-click to decrease it\n" +
"- or click and drag for faster selection.";

Calendar._TT["PREV_YEAR"] = "Prev. year (hold for menu)";
Calendar._TT["PREV_MONTH"] = "Prev. month (hold for menu)";
Calendar._TT["GO_TODAY"] = "Go Today";
Calendar._TT["NEXT_MONTH"] = "Next month (hold for menu)";
Calendar._TT["NEXT_YEAR"] = "Next year (hold for menu)";
Calendar._TT["SEL_DATE"] = "Select date";
Calendar._TT["DRAG_TO_MOVE"] = "Drag to move";
Calendar._TT["PART_TODAY"] = ' (' + "Today" + ')';

// the following is to inform that "%s" is to be the first day of week
Calendar._TT["DAY_FIRST"] = "Display %s first";

// This may be locale-dependent. It specifies the week-end days, as an array
// of comma-separated numbers. The numbers are from 0 to 6: 0 means Sunday, 1
// means Monday, etc.
Calendar._TT["WEEKEND"] = "0,6";

Calendar._TT["CLOSE"] = "Close";
Calendar._TT["TODAY"] = "Today";
Calendar._TT["TIME_PART"] = "(Shift-)Click or drag to change value";

// date formats
Calendar._TT["DEF_DATE_FORMAT"] = "%b %e, %Y";
Calendar._TT["TT_DATE_FORMAT"] = "%B %e, %Y";

Calendar._TT["WK"] = "Week";
Calendar._TT["TIME"] = "Time:";

CalendarDateObject._LOCAL_TIMZEONE_OFFSET_SECONDS = -28800;
CalendarDateObject._SERVER_TIMZEONE_SECONDS = 1333496531;

//]]>
</script>
                        
</div>


Wednesday, February 19, 2014

Magento: Add breadcrumbs in custom module

There are following way to add breadcrumbs
1. From layout files
Suppose the layout file for you module is present in design/frontend/default/default/layout/custommodule.xml.

Now, open the layout xml file of your module. You must see the node named default. Write the following code inside the default node or suppose, you have an address page for you module. The test page will have the node named something like YourModule_index_test.

<reference name="breadcrumbs">
            <action method="addCrumb">
                <crumbName>Home</crumbName>
                <crumbInfo><label>Home</label><title>Home</title><link>/</link></crumbInfo>
            </action>
            <action method="addCrumb">
                <crumbName>Test</crumbName>
                <crumbInfo><label>Test</label><title>Test</title></crumbInfo>
            </action>
</reference>


Tuesday, February 18, 2014

Magento : Add pagination to Wishlist


Create a custom module then override a core class 'Mage_Wishlist_Block_Customer_Wishlist'
and add following methods _prepareLayout(), getPagerHtml()
as
<?php
class Bd_Custommodulet_Block_Wishlist_Customer_Wishlist extends Mage_Wishlist_Block_Customer_Wishlist
{
     /**
     * Preparing global layout
     *
     * @return Mage_Wishlist_Block_Customer_Wishlist
     */
    protected function _prepareLayout()
    {
        parent::_prepareLayout();
$pager = $this->getLayout()->createBlock('page/html_pager', 'wishlist.customer.pager');
$pager->setAvailableLimit(array(5=>5,10=>10,20=>20,'all'=>'all'));
$pager->setCollection($this->getWishlist());
$this->setChild('pager', $pager);
$this->getWishlist()->load();
return $this;
    }
     /**
     * Pager HTML
     *
     * @return HTML
     */
    public function getPagerHtml()
    {
return $this->getChildHtml('pager');
    }
}

After that add following code in /app/design/frontend/base/default/template/wishlist/view.phtml
<?php echo $this->getPagerHtml(); ?>

Wednesday, January 22, 2014

Magento : Get and Resize Category Images


Override following file app/code/core/Mage/Catalog/Model/Category.php and define following method

public function getCategoryImage(Mage_Catalog_Model_Category $category, $width = 250, $height = 250, $quality = 100)
{
    // return when no image exists
    if (!$category->getImage()) {
        return false;
    }
    // return when the original image doesn't exist
    $imagePath = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category'
               . DS . $category->getImage();
    if (!file_exists($imagePath)) {
        return false;
    }
    // resize the image if needed
    $rszImagePath = Mage::getBaseDir('media') . DS . 'catalog' . DS . 'category'
                  . DS . 'cache' . DS . $width . 'x' . $height . DS
                  . $category->getImage();
    if (!file_exists($rszImagePath)) {
        $imageObj = new Varien_Image($imagePath);
$imageObj->constrainOnly ( true );
$imageObj->keepAspectRatio ( true );
$imageObj->keepFrame ( false );
$imageObj->quality ( $quality );
$imageObj->resize($width, $height);
        $imageObj->save($rszImagePath);
    }
    // return the image URL
    return Mage::getBaseUrl('media') . '/catalog/category/cache/' . $width . 'x'
         . $height . '/' . $category->getImage();
}

Tuesday, January 21, 2014

Magento : Get thumbnail in navigation


First create your custom module the follow as
1. Override following file app/code/core/Mage/Catalog/Block/Navigation.php
and a function
public function getThumbnailUrl($category)
{
  return Mage::getModel('catalog/category')->load($category->getId())->getThumbnailUrl();
}

2. Then override following file app/code/core/Mage/Catalog/Model/Category.php
and add a function
public function getThumbnailUrl()
{
  $url = false;
  if ($image = $this->getThumbnail()) {
      $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
  }
  return $url;
}

Magento: Improved one page checkout design using CSS


/*  CSS */
.block-progress .block-title { background:none; margin:0 0 34px; padding:0; }
.checkout-onepage-index .col-main { padding:0; border:0; }
.checkout-onepage-index .page-title { padding-right:40px; width:auto; }
.checkout-onepage-index .page-title h1 { background:none; padding:0; }

.opc { position:relative; overflow:hidden; height:970px; padding-top:20px; text-align:center; border:1px solid #BBAFA0; background:#F9F3E3; }
.opc .buttons-set { margin:15px 0 0; opacity:1!important; }
.opc .buttons-set p.required { margin:0; padding:0 0 10px; }
.opc .buttons-set .back-link { display:none; }
.opc .buttons-set .please-wait { position:absolute; z-index:99; top:30%; left:50%; margin:-80px 0 0 -146px; border:5px solid #f3b66f; font-size:12px; background:#fff; padding:30px; white-space:nowrap; border:1px solid #c0c0c0; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; -moz-box-shadow:1px 1px 2px rgba(0,0,0,0.2); -webkit-box-shadow:0 0 50px rgba(0,0,0,0.2); box-shadow:0 0 50px rgba(0,0,0,0.2); }
.opc .buttons-set a { color:#214D90; }
.opc .ul { list-style:disc outside; padding-left:18px; }
.opc li.section { display:inline; }
.opc .step-title,.opc .allow .step-title { border:1px solid #F9F3E3; height:69px }
.opc .step { padding:30px 20px; position:absolute; border:0; top:110px; left:0; z-index:1; background:#FBFAF6; width:605px; height:900px; border-bottom:1px dotted #ccc; border:none; width:643px; text-align:left; border-top:1px solid #BBAFA0; }
.opc .step-title .number,.opc .allow .step-title .number,.opc .active .step-title .number { float:none; display:block; margin:0 auto; margin-bottom:10px; }
.opc .step-title { position:relative; float:left; text-align:center; padding:15px 11px 0; margin-left:-1px; background:none; }
.opc .step-title a { display:none; }
.opc .step-title .number { background:#ccc; color:#fff; width:30px; height:30px; line-height:30px; -moz-border-radius:20px; -webkit-border-radius:20px; border-radius:20px; margin-bottom:10px; padding:0; border:0; }
.opc .step-title h2 { font-size:12px; color:#bbb; clear:both; }
.opc .allow .step-title { cursor:pointer; background:none; }
.opc .allow .step-title .number { background:#000; color:#fff; }
.opc .allow .step-title h2 { color:#000; }
.opc .active .step-title { color:#ef0606; cursor:default; border:1px solid #BBAFA0; border-bottom:1px solid #FBFAF6; z-index:2; background:#FBFAF6 url(../images/bkg_checkout.gif) 0 0 repeat-x; }
.opc .active .step-title .number { background:#F18200; border-color:#fff; color:#fff; }
.opc .active .step-title h2 { color:#F18200; }
.opc .step-title h2,.opc .allow .step-title h2,.opc .active .step-title h2 { width:100%; text-align:center; }
.opc .step-title { width:16%; }
.opc .form-list .field,.opc .form-list .wide { }
.opc .form-list li fieldset { margin-bottom:40px; }
.opc .form-list label { float:left; width:220px; text-align:right; padding:4px 0 0; }
.opc .form-list label.required em { float:none; position:relative; right:4px; }
.opc .form-list li.fields { margin:0; }
.opc .form-list div.fields { width:100%; overflow:hidden; margin:0 0 8px; }
.opc .form-list .wide,.opc .form-list li.fields .field { width:645px; margin:0 0 8px; }
.opc .form-list li.wide .input-box,.opc .form-list .input-box { clear:none; float:right; margin-right:140px; width:260px; }
.opc .form-list li.wide select { width:390px; }
.opc .form-list li.wide input.input-text { width:254px; }
.opc .form-list .control input { margin:8px 0 0 25px; }
.opc .form-list li.control label { float:left; }
.opc form .form-list li.wide { margin-bottom:8px; }
.opc form .address-select { margin:8px 0 40px; }

.opc:first-of-type .step{-webkit-transition: all 0.5s ease-in-out;-moz-transition: all 0.5s ease-in-out;-o-transition: all 0.5s ease-in-out;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;}
.opc:first-of-type .step[style*='display:none;'],
.opc:first-of-type .step[style*='display: none;']{display:block !important;}
.opc:first-of-type .section .step{left: 100%;}
.opc:first-of-type .allow .step{left: -100%;}
.opc:first-of-type .active .step{left:0;}
.opc:first-of-type li:last-child .step-title a{width:50%}
.opc:first-of-type li:first-child .step-title a{width:50%;left:50%}

#opc-login p.required { display:none; }
#opc-login h3 { margin-bottom:18px; }
#opc-login .col-2 { float:left; }
#opc-login .col-2 form fieldset h4 { display:none; }
#opc-login .col-2 { display:block; width:300px; }
#opc-login .col-2 fieldset { width:300px; }
#opc-login .col-2 .input-box { width:188px; margin:0; float:left; }
#opc-login .col-2 .input-text { width:182px; }
#opc-login .col-2 .form-list label { text-align:left; }
#opc-login .col-2 .form-list label { width:110px; }
#opc-login .form-list li.control label { float:none; }
#opc-login .form-list li.control input { margin:0 8px 0 0; }
#opc-login .col-1 { float:right; }
#opc-login .col-1 { width:290px; }
#opc-login .col-1 h4,#opc-login .col-1 .ul { display:none; }
#checkout-step-review.step { width:645px; }

#opc-review .step { padding:30px 20px; border-top:1px solid #BBAFA0; }
#opc-review .product-name { font-weight:bold; color:#0a263c; }
#opc-review .item-options { margin:5px 0 0; }
#opc-review .buttons-set { padding:20px 0; border:0; }
#opc-review .buttons-set p { margin:0; line-height:40px; }
#opc-review .buttons-set .please-wait { height:40px; line-height:40px; }
#opc-shipping_method .buttons-set { border-top:1px solid #E4E4E4; }

.block-progress .block-title { background:none; margin:0 0 34px; padding:0; }
.checkout-onepage-index .col-main { padding:0; border:0; }
.checkout-onepage-index .page-title { padding-right:40px; width:auto; }
.checkout-onepage-index .page-title h1 { background:none; padding:0; }

.opc { position:relative; overflow:hidden; height:970px; padding-top:20px; text-align:center; border:1px solid #BBAFA0; background:#F9F3E3; }
.opc .buttons-set { margin:15px 0 0; opacity:1!important; }
.opc .buttons-set p.required { margin:0; padding:0 0 10px; }
.opc .buttons-set .back-link { display:none; }
.opc .buttons-set .please-wait { position:absolute; z-index:99; top:30%; left:50%; margin:-80px 0 0 -146px; border:5px solid #f3b66f; font-size:12px; background:#fff; padding:30px; white-space:nowrap; border:1px solid #c0c0c0; -moz-border-radius:6px; -webkit-border-radius:6px; border-radius:6px; -moz-box-shadow:1px 1px 2px rgba(0,0,0,0.2); -webkit-box-shadow:0 0 50px rgba(0,0,0,0.2); box-shadow:0 0 50px rgba(0,0,0,0.2); }
.opc .buttons-set a { color:#214D90; }
.opc .ul { list-style:disc outside; padding-left:18px; }
.opc li.section { display:inline; }
.opc .step-title,.opc .allow .step-title { border-color:#FBFAF6; }
.opc .step { padding:30px 20px; position:absolute; border:0; top:100px; left:0; z-index:1; background:#fff; width:605px; height:900px; border-bottom:1px dotted #ccc; border:none; background:none; width:643px; text-align:left; background:#FBFAF6 url(../images/bkg_checkout.gif) 0 0 repeat-x; border-top:1px solid #BBAFA0; }
.opc .step-title .number,.opc .allow .step-title .number,.opc .active .step-title .number { float:none; display:block; margin:0 auto; margin-bottom:10px; }
.opc .step-title a { display:none; }
.opc .step-title .number { background:#fff; color:#ccc; width:30px; height:30px; line-height:30px; -moz-border-radius:20px; -webkit-border-radius:20px; border-radius:20px; margin-bottom:10px; padding:0; border:0; position:relative; z-index:1; }
.opc .step-title h2 { font-size:12px; color:#bbb; clear:both; margin-bottom:10px; }
.opc .allow .step-title .number { background:#000; border-color:#fff; color:#fff; }
.opc .allow .step-title h2 { color:#000; }
.opc .active .step-title .number { background:#F18200; border-color:#fff; color:#fff; }
.opc .active .step-title h2 { color:#F18200; }
.opc .step-title,.opc .allow .step-title,.opc .active .step-title { position:relative; text-align:center; border:none; background:none; padding:0; overflow:hidden!important; height:80px; display:inline-block; vertical-align:top; }
.opc .step-title,.opc .allow .step-title,.opc .active .step-title { *display:block; *float:left; }
.opc .step-title h2,.opc .allow .step-title h2,.opc .active .step-title h2 { width:100%; text-align:center; }
.opc .step-title { width:16%; }
.opc .form-list .field,.opc .form-list .wide { }
.opc .form-list li fieldset { margin-bottom:40px; }
.opc .form-list label { float:left; width:220px; text-align:right; padding:4px 0 0; }
.opc .form-list label.required em { float:none; position:relative; right:4px; }
.opc .form-list li.fields { margin:0; }
.opc .form-list div.fields { width:100%; overflow:hidden; margin:0 0 8px; }
.opc .form-list .wide,.opc .form-list li.fields .field { width:645px; margin:0 0 8px; }
.opc .form-list li.wide .input-box,.opc .form-list .input-box { clear:none; float:right; margin-right:140px; width:260px; }
.opc .form-list li.wide select { width:390px; }
.opc .form-list li.wide input.input-text { width:254px; }
.opc .form-list .control input { margin:8px 0 0 25px; }
.opc .form-list li.control label { float:left; }
.opc form .form-list li.wide { margin-bottom:8px; }
.opc form .address-select { margin:8px 0 40px; }

.opc:first-of-type .step{-webkit-transition: all 0.5s ease-in-out;-moz-transition: all 0.5s ease-in-out;-o-transition: all 0.5s ease-in-out;-webkit-transition: all 0.5s ease-in-out;transition: all 0.5s ease-in-out;}
.opc:first-of-type .step[style*='display:none;'],
.opc:first-of-type .step[style*='display: none;']{display:block !important;}
.opc:first-of-type .section .step{left: 100%;}
.opc:first-of-type .allow .step{left: -100%;}
.opc:first-of-type .active .step{left:0;}
.opc:first-of-type li:last-child .step-title a{width:50%}
.opc:first-of-type li:first-child .step-title a{width:50%;left:50%}
.opc:first-of-type .step-title a { display:block;height:1px;border-bottom:1px dashed #ccc; width:100%; text-indent:-3000px; position: absolute;top:15px;z-index: 0}
.opc:first-of-type .allow .step-title a {}

#opc-login p.required { display:none; }
#opc-login h3 { margin-bottom:18px; }
#opc-login .col-2 { float:left; }
#opc-login .col-2 form fieldset h4 { display:none; }
#opc-login .col-2 { display:block; width:300px; }
#opc-login .col-2 fieldset { width:300px; }
#opc-login .col-2 .input-box { width:188px; margin:0; float:left; }
#opc-login .col-2 .input-text { width:182px; }
#opc-login .col-2 .form-list label { text-align:left; }
#opc-login .col-2 .form-list label { width:110px; }
#opc-login .form-list li.control label { float:none; }
#opc-login .form-list li.control input { margin:0 8px 0 0; }
#opc-login .col-1 { float:right; }
#opc-login .col-1 { width:290px; }
#opc-login .col-1 h4,#opc-login .col-1 .ul { display:none; }

#checkout-step-review.step { width:645px; }
#opc-review .step { padding:30px 20px; border-top:1px solid #BBAFA0; }
#opc-review .product-name { font-weight:bold; color:#0a263c; }
#opc-review .item-options { margin:5px 0 0; }
#opc-review .buttons-set { padding:20px 0; border:0; }
#opc-review .buttons-set p { margin:0; line-height:40px; }
#opc-review .buttons-set .please-wait { height:40px; line-height:40px; }
#opc-shipping_method .buttons-set { border-top:1px solid #E4E4E4; }

Monday, January 20, 2014

Facebook Fan Box


<?php
$fb_page_url= Mage::getStoreConfig('setting/fbfanbox/fb_page_url');
$box_width=250;
$box_height=290;
$header=TRUE;
$stream=FALSE;
$box_content="";
$box_content .='<iframe src="http://www.facebook.com/plugins/likebox.php?href='. urlencode($fb_page_url);
if($box_width)
{
$box_content .= '&amp;width='. $box_width;
}
if($box_height)
{
$box_content .= '&amp;height='. $box_height;
}

$box_content .= '&amp;connections='. $connection;

if($header)
{
$box_content .= '&amp;header=true';
}

if($stream)
{
$box_content .= '&amp;stream=true';
}
$box_content .= '" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; ';

if($box_width)
{
$box_content .= ' width:'. $box_width . 'px; ';
}
if($box_height)
{
$box_content .= ' height:'. $box_height. 'px; ';
}
$box_content .= '"></iframe>';
?>
<div id='fbfanbox'>
<?php echo($box_content); ?>
</div>


Friday, January 10, 2014

Magento: Use ajax filter in magento catalog

There are two things need to do
1.Convert all request into ajax request using following script

function filter(){
    jQuery('.toolbar a').each(function(index){
        jQuery(this).click(function(){
            filterAjax(jQuery( this ).attr('href'));          
            console.log( index + ": " + jQuery( this ).text() ); return false;
        });
     
    });
    jQuery('.toolbar select').each(function(index){
        jQuery(this).removeAttr('onchange');
        jQuery(this).change(function(){
            filterAjax(jQuery( this ).val());
            console.log( index + ": " + jQuery( this ).text() ); return false;
        });
     
    });
    jQuery('.block-layered-nav a').each(function(index){
        jQuery(this).click(function(){        
            filterAjax(jQuery( this ).attr('href'));
            console.log( index + ": " + jQuery( this ).text() ); return false;
        });
     
    });
}
function filterAjax(s_url){
    jQuery('#loader').show();
    jQuery.ajax({
            type: "GET",
            //data : {is_ajax:1},
            url: s_url,
            success: function(data) {
            jQuery('.category-products').remove();
            jQuery('.col-main').append(data.page);                  
            jQuery('.block-layered-nav').remove();
            jQuery('.col-left').prepend(data.block);
            //jQuery('body').append(data.js);
            jQuery('#loader').hide();
            filter();
      }
    });
}
jQuery(document).ready(function(){
    filter();
});

2. Then convert output into JSON using following script

$layout = Mage::getSingleton('core/layout');
if (!$layout)
return;
if (!Mage::app()->getRequest()->isXmlHttpRequest())
return;          
$layout->removeOutputBlock('root');  
Mage::app()->getFrontController()->getResponse()->setHeader('content-type', 'application/json');

$page = $layout->getBlock('product_list');
if (!$page)
return;
$block='';
foreach ($layout->getAllBlocks() as $child){              
if (!in_array($child->getNameInLayout(), array('catalog.leftnav'))){
    continue;
}
$block = $child;
}
if (!$block)
return;      
$container = $layout->createBlock('core/template', 'sparx_container');
//$container->setData('js', $layout->createBlock('core/template', 'ajaxfilter_js')->setTemplate('ajaxfilter/js.phtml')->toHtml());
$container->setData('block', $block->toHtml());
$container->setData('page', $page->toHtml());
$layout->addOutputBlock('sparx_container', 'toJson');

Here we have to use event observer concept.
(controller_action_layout_render_before_catalog_category_view)



Thursday, January 2, 2014

Magento : How to add Indexes in a custom module

Follow these steps:

config.xml:

<index>                              
<indexer>
<cms_indexer>
<model>module/cmsindexer</model>
</cms_indexer>
</indexer>
</index>            

Model:

cmsindexer.php

Class Module_Model_CmsIndexer extends Mage_Index_Model_Indexer_Abstract
{

public function getName(){
                return 'Add CMS Cache';
}

public function getDescription(){
return 'Rebuild Cache Index for all CMS Pages';
}

protected function _processEvent(Mage_Index_Model_Event $event){
// process
}

public function reindexAll(){
//Your Function to be executed
}