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>