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(); ?>