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');
            
            }
        }
    }
}
?>

how to add a custom column in Magento sales/order grid


Step 1 :- Copy app\code\core\Mage\Adminhtml\Block\Sales\Order\grid.php
to
app\code\local\Mage\Adminhtml\Block\Sales\Order\grid.php now Find _prepareColumns() function to Add column use this code:-
$this->addColumn('color ', array(
    'header' => Mage::helper('sales')->__('color #'),
    'index' => 'color',
    'sortable'  => false,
    'filter'    => false,
    'renderer' => 'Mage_Adminhtml_Block_Sales_Order_Renderer_Productatt',
));
Step 2:- Create a new file at :-
app\code\local\Mage\Adminhtml\Block\Sales\Order\Renderer\Productatt.php add this code :-
<?php
class Mage_Adminhtml_Block_Sales_Order_Renderer_Productatt extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {                    

         $order = Mage::getModel('sales/order')->load($row->getData('entity_id'));              
            $attribute ="";

        foreach($order->getAllVisibleItems() as $_item){  
        $product    =   Mage::getModel('catalog/product')->load($_item->getProductId());         
       if($product->getAttributeText('color')){
            $attribute .= $product->getAttributeText('color');
       }
    }
        unset($order);
        return $attribute;      
    }       
}
?>

How to send custom attribute in magento Order email.

Recently i was working on a project and my client want to send a custom shipping note in order email.
So lets's see how to achieve this:-
Create a file On this location app/design/frontend/your_package/your_theme/template/email/shipnote.phtml in this file i am getting shipnote info i am installed following extension for it :-
https://github.com/drewhunter/ShipNote
Now in shipnote.phtml i have added following code.
<?php

$order = $this->getOrder();
$shipNoteId = $order->getShipNoteId();
$ShipnoteModel = Mage::getModel('shipnote/note')->load($shipNoteId);    
echo 'Pickup Location :- '.$ShipnoteModel->getNote();
?>
Now open your transactional email template you can find it system->>Transactional Emails or app/locale/en_US/template/email/sales/order_new.html and add following code in it:-
{{block type='core/template' area='frontend' template='email/shipnote.phtml' order=$order}}

Fix CSS hover on iPhone/iPad/iPod

Copy this code and paste it any where in your file.
Make sure jQuery included in your page.


How to Show product options in product list page in wordpress

In this article, we will recommend some effective methods to show options for the configurable and product options in product list. Check them out! Showing options for Configurable products :-

Open content-product.php file you can find this file at this location :-
wp-content\plugins\woocommerce\templates\content-product.php
Copy this code before end of li and after "do_action( 'woocommerce_after_shop_loop_item_title' )"
<?php	
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
		remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
		do_action( 'woocommerce_single_product_summary' );
	
?>

Odesk PHP Frontend Developer Test v2 answer

In this test there are 4 questions they are following.


Question no 1:- Fantastic three sequence

Solution :-
<?php
function fantastic3($n) {
$series = array(0,1,1,1);
for($i=3 ; $i<=$n ; $i++){
$a = (isset($series[ (int)$i-3 ]))?$series[ (int)$i-3 ]:0;
$b = (isset($series[ (int)$i-2 ]))?$series[ (int)$i-2 ]:0;
$c = (isset($series[ (int)$i-1 ]))?$series[ (int)$i-1 ]:0;
$d = ($a+$b+$c)-1;
if($d<0){
$d = 0;
}
$series[$i] = $d;
}
echo $series[ (int)$n-1 ];
}
// Do NOT call the fantastic3 function in the code
// you write. The system will call it automatically.
?>

how to change shipping method from radio to dropdown in Magento

Today my client want to change shipping method from radio to dropdown on onepage checkout after a lot of googling i not found any proper solution for this.
Then i tried it my self and it's worked for me so i am share my coding here :-
To make shipping method from radio to dropdown copy this file at this location:-

app/design/frontend/your-theme-package/your-theme/template/checkout/onepage/shipping_method/available.phtml

You can download file here.

How to Show product options in product list page in Magento

In this article, we will recommend some effective methods to show options for the configurable and product options in product list. Check them out! Showing options for Configurable products :-

How to Set Up Table Rate Shipping in Magento

In this tutorial, we’re going to look at how to set up table rate shipping in Magento, giving you the ability to charge different shipping rates to individual customers based on their location–from the regional all the way down to the postcode level.

Three ways to price shipping

One thing to note, before we start, is that there are three main ways of setting up table rates–price vs. destination, weight vs. destination and number of items vs. destination.
Essentially what this means is that you can set cheaper shipping to certain destinations if the cost of the item is high, or if the weight and number of items is low.

Configuring table rate shipping

You set table rate shipping inside the System menu accessed via Magento’s backend.
While logged in as admin, navigate to System > Configuration and then, in the left menu under Sales, select Shipping Methods.

Change shipping address dropdown to div in Magento

If you want to change shipping address dropdown to div structure.
After a long research i found that this select box is comming form core php file and it's hard to make any change in core file. So we have to change in shipping.phtml file as following. Step 1 : Open shipping.phtml you can find it :- /app/design/frontend/package/yourtheme/template/checkout/onepage/shipping.phtml Please find this code around line no 30.
  • <?php echo $this->getAddressesHtmlSelect('shipping') ?>
  • Set Payment Method "PayPal" on Particular State Only in Magento

    If you want to disable a specfic payment method for specfic State then follow these steps. 1.Make a new file in app/etc/module/Arunendra_Disablepayment.xml copy and Paste below code in that file
    
    <?xml version="1.0"?>
    
    
         
            true
            local
         
    
    
    
    2.Now make module folder inside app/code/local/Arunendra/Disablepayment 3.Make new folder and file inside app/code/local/Arunendra/Disablepayment/etc/config.xml and copy and paste below code in that file.

    How to disable specfic payment method for specfic products in Magento

    How to disable specfic payment method for specfic products If you want to disable a specfic payment method for specfic products then follow these steps. 1.Make a new file in app/etc/module/Arunendra_Disablepayment.xml copy and Paste below code in that file
    <?xml version="1.0"?>
    
    
    
         
            true
            local
    
        
    
    
    
    2.Now make module folder inside app/code/local/Arunendra/Disablepayment 3.Make new folder and file inside app/code/local/Arunendra/Disablepayment/etc/config.xml and copy and paste below code in that file.

    Add Product Images In Magento Transactional Emails

    In order to add the order Image to the transaction email templates (order), you need to play with the following two files:
    1.) Edit the file: app/design/frontend/base/default/template/email/order/items.phtml Locate this line (Around Line 32) :
    <th align="left" bgcolor="#EAEAEA" style="font-size:13px; padding:3px 9px"> <?php echo $this->__('Sku') &#63></th>
    

    Disable admin notification popup in Magento

    Every time you log in to the Magento Admin Panel, you see an admin notification popop message telling you there's a new Magento version. As a developer, it's best to stay informed about new releases by reading blogs, tweets and lots of other news channels - besides this, upgrades should never be taken lightly. It's possible to remove this notification popup message.


    To remove this notification popup message.
    • Login to your Magento Admin Panel
    • Go to System >> Configuration >> Advanced
    • Disable the Mage_AdminNotification module


    How to create custom page layout in magento

    To create a new custom column layout, you need to place a new file in the Magento theme. With the Magento default theme, you could use the folder app/design/frontend/default/default/template/page, but of course - when building your own site - it is recommended to have your own theme-directory.

    In the tutorial, the file 1column.phtml is copied to the file 1columnfp.phtml (where "fp" stands for the front page). To make this new page reckognizable you wll need to add a new XML-definition. In the tutorial the following code is added to the file app/code/core/Mage/Page/etc/config.xml. copy this module in local exp app/code/local/Mage/Page/etc/config.xml
    
        
        
        page_one_column_fp
    
    
    However, with a Magento upgrade this change could be gone. The same XML could also be added to your app/etc/local.xml file instead:

    Customizing Magento email templates

    Emails (or often referred to as transactional emails) are - just like the entire Magento theme - based on files in the filesystem: If you open up the folder app/locale/en_US/template/email you will numerous files. Don't edit them directly, because any Magento upgrade will override your changes. Instead, the purpose of these files is to override them. You can override these email templates either using the Magento Admin Panel, or by copying them to your Magento theme. The first approach allows for easy editing using the Magento Admin Panel, but this interface lacks nice editing features like syntax highlighting or code completion. Ofcourse, you can copy the textarea contents ofcourse to your local editor modify things there and copy the code back into the textarea once you're done.