Friday, February 19, 2016

Magento admin change default page size of grid

You have to modify two files for that: Grid.php and Grid.phtml,
Below are the details of files:

In Admin Block File:
/public_html/app/code/core/Mage/Adminhtml/Block/Widget
Grid.php

Search for $_defaultLimit in the file and change the value according to your choice.
protected $_defaultLimit    = 75;

PHTML File:
app/design/adminhtml/default/default/template/widget
grid.phtml

Add your option in the select box.

<select name="<?php echo $this->getVarNameLimit() ?>" onchange="<?php echo $this->getJsObjectName() ?>.loadByElement(this)">
<option value="20"<?php if($this->getCollection()->getPageSize()==20): ?> selected="selected"<?php endif; ?>>20</option>
<option value="30"<?php if($this->getCollection()->getPageSize()==30): ?> selected="selected"<?php endif; ?>>30</option>
<option value="50"<?php if($this->getCollection()->getPageSize()==50): ?> selected="selected"<?php endif; ?>>50</option>
<option value="75"<?php if($this->getCollection()->getPageSize()==75): ?> selected="selected"<?php endif; ?>>75</option>
<option value="100"<?php if($this->getCollection()->getPageSize()==100): ?> selected="selected"<?php endif; ?>>100</option>
<option value="200"<?php if($this->getCollection()->getPageSize()==200): ?> selected="selected"<?php endif; ?>>200</option>
</select>

I have added 75 as additional page size, It will be default pagesize too.

Monday, October 26, 2015

PHP Remove special (non printable) characters from text

 

$mystring = " Fund BDM̢۪s were then able to engage with 19 employers, most of whom were subsequently converted to the MTAA Super Clearinghouse.
";
preg_replace("/[^\x0A\x20-\x7E]/",'', $mystring);

echo $mystring;

//The above code will result in

Fund BDMs were then able to engage with 19 employers, most of whom were subsequently converted to the MTAA Super Clearinghouse..
        

Wednesday, October 21, 2015

DISPLAY OUT OF STOCK PRODUCTS ACCORDING TO ADMIN INVENTORY SETTING

 

$isOutOfStockAllowed = Mage::getStoreConfig('cataloginventory/options/show_out_of_stock');
 
  foreach($_productCollection as $_product)
       {
        if(!$isOutOfStockAllowed){
         if(!$_product->isSaleable()){
          continue;
         }
         
        }
        //PRODUCT DISPLAY CODE HERE
        
        }
        

Saturday, October 17, 2015

Facebook page feed time issue

I was implementing facebook page feed for one of my client, the feeds were appearing correct but time was different, actually it was a timezone issue, you have to convert facebook time to local timezone, and to do this i found the perfect way.

step1.
Download and include the js file into your script.

https://gist.github.com/aredo/4153245

step2:

use below code to determine the client timezone:

<script type="text/javascript">
    jQuery(document).ready(function() {
       var timezone = jstz.determine();
var timezonename = timezone.name();  
    });
</script>

Saturday, December 20, 2014

Magento Flat category , show category tree

Below code displays dropdown of categories and subcategories upto n level.


<!----NEW CODE---->

<select id="category-changer"  name="cat" style="width:150px;">
<option value="6"> All Categories </option>
<?php echo $catlistHtml; ?>  
</select>
<?php
function str_prefix($str, $n=1, $char=" "){
    for ($x=0;$x<$n;$x++){ $str = $char . $str; }
    return $str;
}
function getTreeCategories($parentId, $isChild){
    $_cathelper = Mage::helper('catalog/category');
$allCats = Mage::getModel('catalog/category')->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('is_active','1')
                ->addAttributeToFilter('parent_id',array('eq' => $parentId));
    $class = ($isChild) ? "sub-cat-list" : "cat-list";
    //$children = Mage::getModel('catalog/category')->getCategories(7);
    foreach ($allCats as $category)
    {
   $prefix = '';
   $_category =  Mage::getModel('catalog/category')->load($category->getId());
   $lblval=$_category->getLevel()-3;
$catname = ($lblval==0)?strtoupper($_category->getName()):$_category->getName();
$catname =  str_prefix($catname,$lblval*2,"-");
        $html .= '<option lbl="'.$_category->getLevel().'" value="'.$_category->getId().'" caturl="'.$_cathelper->getCategoryUrl($_category).'" >'.$catname."</option>";
        $subcats = $category->getChildren();
        if($subcats != ''){
            $html .= getTreeCategories($category->getId(), true);
        }
    }
    return $html;
}
$catlistHtml = getTreeCategories(6, false);
?>

<!--NEW CODE ENDS--> 

Monday, August 12, 2013

Magento add datepicker to frontend

Code referece:

http://stackoverflow.com/questions/8335456/magento-how-do-i-add-a-frontend-date-picker-that-returns-dd-mm-yy-instead-of-m


STEPS:
1. Add js and css necessary for the datepicker in frontend
<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.
 <block type="core/html_calendar" name="html_calendar" as="html_calendar" template="page/js/calendar.phtml"/> 

3.call that block in the phtml file where u want to implement datepicker.
<?php echo $this->getChildHtml('html_calendar') ?>
 
4. Last use the below code:
 
<script type="text/javascript">
  Calendar.setup({
  inputField : 'deliverydate',
  ifFormat : '%m/%e/%y',
  button : 'date_from_trig',
  align : 'Bl',
  singleClick : true
  });
</script> 

Tuesday, June 18, 2013

Magento signin signout links on any phtml file

 <ul class="links si_ac">
            <?php
            $signout =$baseurl.'customer/account/logout';
            if(!Mage::getSingleton('customer/session')->isLoggedIn()) {
            $signinUrl =$baseurl.'customer/account/login';
            $signup   =$baseurl.'customer/account/create';
             $linkks = "<li><a href='$signinUrl'>".$this->__("Sign In")."</a></li>
                <li class='last'><a  href='$signup'>".$this->__("Create an Account")."</a></li>";
            }else{
              $linkks = "<li class='last'><a  href='$signout'>".$this->__("Sign Out")."</a></li>";
            }
            echo $linkks;
            ?> 
         </ul>