January 04, 2016

Javascript URL parse

Javascript URL parse

window.location.host : example.com:80
window.location.hostname : example.com
window.location.protocol : http:
window.location.port : 8080 or 80
window.location.origin : http://example.com *

January 13, 2015

MySQL storage engines

MySQL storage engines


MySQL storage engines
InnoDB
MyISAM
ISAM
MEMORY(HEAP)
BLACKHOLE


You want to know all storage engines. Login to mysql terminal window using mysql credentails
Just type the commane
show engines;
you get the list of all storage engines.

December 24, 2014

Magento how to call other block in phtml file

Magento how to call other block in phtml file

To get the block in your template, other than child block.
When you want to call the block other than specified xml child blocks.
$this->getLayout()->getBlock('block_name')->toHtml();
For example
$this->getLayout()->getBlock('top.links')->toHtml();    

December 20, 2014

Alternate to if else use switch statement


Alternate to if else use switch statement

If you execute the if else statements which multiple conditions
its go throw each condition and check with those condition is matching. For example you written if else condition
 
 if($i == 15)
 elseif($i == 25)
 elseif($i == 35)
 elseif($i == 45)
 elseif($i == 55)
 else
You want to match 45 value,while executing this above script variable matches with each if and else condition
and finally matches 45 value, so condition executed above with unmatched value then it took the execution time.

Alternative Switch statement

Suppose you are using the swithc statement for the above case. Example
 
 switch($i) {
   case 15:
     break;
   case 25:
     break;
   case 35:
     break;
   case 45:
     break;
   case 55:
     break;
 }
In this above switch statement, if the $i values was 45 then execute 45 matched values and go through the further process.

PHP error reporting


PHP error reporting

As of developer view, error reporting is more sensitive one.

There are 3 types of errors.
1) Fatal error
2) Warning error
3) Notice error

In production environment, we cant see the errors in live it appears blank page.
In this case, you want to see the server log normally for apache server which is generated in the server log file
/var/log/apache2/error.log

In terminal, you see the last few occurences error as
tail -f /var/log/apache2/error.log

While developing environment you want to see the all errors through
ini_set('display_errors', 1); /*By default its value as 0 in php.ini*/
error_reporting(-1); /*It shows all errors*/

Magento add Custom js/css in Current Theme

Add Custom JS/CSS in current theme


If you want the css and js for all the pages then you can add the code in local.xml with default handles xml tag.
 
   
     
       
         
       
       
         [css_filename.css]
       
     
   
 
[script_filename.js] - specify the script filename
[css_filename.css] - specify the css filename

For specific pages you want to add the custom css or js, then
specify the handles in local.xml and add the custom css, js xml code.

And also if want to add the custom css in specific handles,
then add the custom add code within that handles.

Modify Home Page Banner Image


Modify Banner Image


Step 1


Go to Magento admin pages through
Admin -> CMS -> Pages -> Edit home(Which mentioned in URL key)

Step 2


After click the home page which redirected to edit page.
In home edit page, go through the Content tab in left panel, click the tab.

Step 3


You see the textarea with the HTML code, in that you find the block id "home-slider".
You will change the home page banner images in the textarea.

Magento Product Collection Query


Magento product collection query

For developers, print the product collection query.

$statusEnabled = Mage_Catalog_Model_Product_Status::STATUS_ENABLED;

$collection = Mage::getModel('catalog/product')
                 ->getCollection()
                 ->addAttributeToFilter('status', 
                  $statusEnabled);
/**
 *
 * Print query
 *
 */
echo $collection->getSelect();
/**
 *or
 */
echo $collection->getSelect()->__toString();
/**
 *
 *print collection query 
 */
$Collection->printLogQuery(true);

You can then view the result query.
For developer, enable the system log settings by
System -> Configuration -> Developer -> Log Settings
see the generated log file in [magento_root_folder]/var/log/ folder

Magento Add the Default Permission for Folders


Folder permissions

/media - accessing the product images
/var - generating the cache, report files

Downloader, var and media folders are need be writable
[magento_root_folder]/var - 777 [magento_root_folder]/media - 777 [magento_root_folder]/downloader - 777

Once completed instllation and development process.
Reset back downloader folder to 755 so that this folders are non-writeable in production.

For files keep the permission as 644.

December 19, 2014

Use local.xml in theme layout for Updating Handles

Use local xml in layout file to update the handles

Step 1

Create local.xml in your custom theme as app/design/frontend/[package]/[theme]/layout/

Step 2

Create the layout code in local.xml and update the layout handles that you want in custom theme.


Within the layout tag, update the base xml handles. For example, want to remove the newsletter globally in left column for your current theme.