How to pragmatically create admin user in Magento

To create Admin User copy this code in your file and put this file on Magento root directory.
<?php
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app('admin');
try {
$user = Mage::getModel('admin/user')
->setData(array(
'username'  => 'admin1',
'firstname' => 'Admin',
'lastname'    => 'Admin',
'email'     => 'waytest@test.com',
'password'  =>'admin123',
'is_active' => 1
))->save();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

//Assign Role Id
try {
$user->setRoleIds(array(1))  //Administrator role id is 1 ,Here you can assign other roles ids
->setRoleUserId($user->getUserId())
->saveRelations();

} catch (Exception $e) {
echo $e->getMessage();
exit;
}

echo "User created successfully";

?>

How to get Magento layout outside of Magento

I integreated wordpress in my magento store and I will try to get magento data in wordpress file. I want to same header in my both site magento and wordpress. I tryed to hard and finally got the solution to get any magento layout in wordpress. Below are the script to

get magento layout outside of magento.

<?php
require_once '/home/.../public_html/.../app/Mage.php';
umask(0);
/* not Mage::run(); */
Mage::app('default');
 
// get layout object
$layout = Mage::getSingleton('core/layout');
 
//get block object
$block = $layout->createBlock('page/template_links');
 
/* choose whatever category ID you want */
//$block->setCategoryId(3);
$block->setTemplate('page/template/links.phtml');
 
echo $block->renderView();
?>

Listing sub-categories on a category page with category images.

This tutorial is going to show you one of the ways to list sub-categories on category pages of your Magento store. In order to display thumbnails of subcategories and their names on your category pages:
1:-In your Magento admin go to CMS -> Static Blocks
2:-Click “Add New Block” at the top right.
3:-Create a new static block as follows:
Block Title: Sub Category Listing
Identifier: subcategory_listing
Status: Enabled
Content:
{{block type="catalog/navigation" template="catalog/navigation/subcategory_listing.phtml"}}

How to Create a block in Magento


Many time we need to create a new block in Magento sites.There are two types of Block in Magento:-
1. Structural Blocks
2.Content Blocks For more detail see here.
Step 1 :- Now we are going to create a new Structural Blocks for this you have to create a new file local.xml in your them's layout folder and put this code:-
<?xml version="1.0"?>

  
 
 
   
    
   
  
    

How to modify/change shpping price in Magento


If you want modify or change Shipping price in Magento then we can do it using Observer So let's see how to do it:- We are going to create a Custom Module for it.
Step 1:- So let's create a config file Arunendra_Extrashipcost.xml in app/etc/modules put following code in this file:-

<?xml version="1.0"?>



    
        true
        local
    


Step 2:- create following folder and file under app/code/local
1:-Arunendra/Extrashipcost/etc/config.xml
2:-Arunendra/Extrashipcost/etc/Model/Observer.php
Step 3:-Put following code in config.xml file:-

<?xml version="1.0"?>


  

    
      0.1.0
    
  
	
		
            
            Arunendra_Extrashipcost_Model
            
		
	
 
	
		
			
				
					singleton
					extrashipcost/observer
					salesQuoteCollectTotalsBefore
				
			
		
	

 
Step 4:-Put following code in Observer.php file:-
<?php
class Arunendra_Extrashipcost_Model_Observer
{
 public function salesQuoteCollectTotalsBefore(Varien_Event_Observer $observer)
    {
         $quote = $observer->getQuote();        
	    $store    = Mage::app()->getStore($quote->getStoreId());
        $carriers = Mage::getStoreConfig('carriers', $store);     
		$newFee = 	floatval($carriers['flatrate']['price'] * 0.15);
        foreach ($carriers as $carrierCode => $carrierConfig) {
            if($carrierCode == 'flatrate'){          
			
                    Mage::log('Handling Fee(Before):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
                    $store->setConfig("carriers/{$carrierCode}/handling_type", 'F'); #F - Fixed, P - Percentage                 
                    $store->setConfig("carriers/{$carrierCode}/handling_fee", $newFee);     
                    ###If you want to set the price instead of handling fee you can simply use as:
                    #$store->setConfig("carriers/{$carrierCode}/price", $newPrice);     
                    Mage::log('Handling Fee(After):' . $store->getConfig("carriers/{$carrierCode}/handling_fee"), null, 'shipping-price.log');
            
            }
        }
    }
}
?>