How to create Shipment and invoice by code in magento

For automization magento we required auto create a shipment and invoice
therefor i decide to write blog for create shipment and invoice by code so after placing an order it will auto generate invoice and shipment.
Following are the steps for create a shipment and invoice.
step 1: create invoice by code

order_id = "100000042";
//load order by increment id
$order = Mage::getModel("sales/order")->loadByIncrementId($order_id);
try {
	if($order->canInvoice()) {
		//Create invoice with pending status
		$invoiceId = Mage::getModel('sales/order_invoice_api')
			->create($order->getIncrementId(), array());

		$invoice = Mage::getModel('sales/order_invoice')

		//set invoice status "paid"
}catch (Mage_Core_Exception $e) {
// print_r($e);

Step 2: Create Shipment by code

order_id = "100000042";

//load order by increment id
$order = Mage::getModel("sales/order")->loadByIncrementId($order_id);
try {
	if($order->canShip()) {
		//Create shipment
		$shipmentid = Mage::getModel('sales/order_shipment_api')
						->create($order->getIncrementId(), array());
		//Add tracking information
		$ship = Mage::getModel('sales/order_shipment_api')
						->addTrack($order->getIncrementId(), array());		
}catch (Mage_Core_Exception $e) {
// print_r($e);

Step3 : Create cron Or setup observer for create auto invoice and shipment

How to put Javascript and php validation for Credit card?

Step 1: First create creditcard.php file and use the below code.

  $credit_card_cc_owner = $_POST['credit_card_cc_owner'];
  $cardnumber = $_POST['credit_card_cc_number'];
  $cardname = $_POST['credit_card_type'];
  $cardcvv = $_POST['credit_card_cvv'];
  $card_cc_expires_month = $_POST['credit_card_cc_expires_month'];
  $card_cc_expires_year = $_POST['credit_card_cc_expires_year'];
  if (strlen($credit_card_cc_owner) < 3)
    $error = true;
    $Errormessage.="The Owner\'s name of the credit card must be at least 3 characters.
  if (strlen($cardnumber) < 13)
      $error = true;
      $Errormessage.="The Credit Card number must be at least 13 characters.
  if (strlen($credit_card_cvv) < 3)   {       $error = true;       $Errormessage.="The Credit Card cvv number must be at least 3 characters. ";   }   if(!tep_validateCC($cardnumber,$cardname))   {       $error = true;       $Errormessage.="Please make sure that you entered a valid Credit Card Number. ";   }   if(!tep_CheckCVV($cardnumber,$cardcvv))   {       $error = true;       $Errormessage.="Please make sure that you entered valid CVV Number. ";  }  if(!tep_CheckCreditCardExpirationDate($card_cc_expires_month,$card_cc_expires_year))  {       $error = true;       $Errormessage.="Please Select Valid Date";  }  if($error==false)  	$Successmessage="Your Credit card is valid"; } ?>
Credit Card Validation Java+PHP Example
<script type="text/javascript" language="javascript" src="creditcard.js"></script></pre>
<form action="" method="post" name="creditcard" onsubmit="return check_form(creditcard);">
<table width="30%" border="0" cellspacing="0" cellpadding="2" align="center">
<td colspan="2"><?php if($error==1) { echo '<span style="color: #ff0000;">'.$Errormessage.'</span>';
 } else { echo '<span style="color: #76c776;">'.$Successmessage.'</span>';} ?></td>
<td class="main" width="180">Credit Card Owner:</td>
<td class="main"><input type="text" name="credit_card_cc_owner" /></td>
<td class="main" width="180">Credit Card Type:</td>
<td class="main"><select name="credit_card_type"><option value="Amex">Amex</option><option value="Mastercard">Mastercard</option><option value="Visa">Visa</option></select></td>
<td class="main" width="180">Credit Card Number:</td>
<td class="main"><input type="text" name="credit_card_cc_number" /></td>
<td class="main" width="180">Credit Card Expiry Date:</td>
<td class="main"><select name="credit_card_cc_expires_month"><option value="01">January</option><option value="02">February</option><option value="03">March</option><option value="04">April</option><option value="05">May</option><option value="06">June</option><option value="07">July</option><option value="08">August</option><option value="09">September</option><option value="10">October</option><option value="11">November</option><option value="12">December</option></select> <select name="credit_card_cc_expires_year"><option value="2011">2011</option><option value="2012">2012</option><option value="2013">2013</option><option value="2014">2014</option><option value="2015">2015</option><option value="2016">2016</option><option value="2017">2017</option><option value="2018">2018</option><option value="2019">2019</option><option value="2020">2020</option></select></td>
<td class="main" width="180">CVV number</td>
<td class="main"><input type="text" name="credit_card_cvv" size="4," maxlength="4" /></td>
<td class="main" width="180"></td>
<td class="main"><input type="submit" name="submit" value="Submit" /></td>

Step 2: You can download creditcard_valid.php file:  creditcard_valid.php

Step 3: You can download creditcard.js file : creditcard.js

Step 4: Now run your creditcard.php file and you can enjoy the javascript and PHP Caredit card validation on your site.

Parse csv file with column name as key

Whenever we are dealing with CSV, we fill that we can get value of CSV row as array. Therefore, I come with this small solution for parse CSV like array structure

We taken column name as key and find value of that row using key index.
Here is the code example.

To get column name as key, we create a class. using this class, you can get array of array of CSV that with column name as an array key.


class csvParse
  var $mappings = array();

  function parseFile($filename)
//open the file
    $id = fopen($filename, "r"); 
/*This will get us the main column names */
    $data = fgetcsv($id, filesize($filename)); 

       $this->mappings = $data;

    while($data = fgetcsv($id, filesize($filename)))
            foreach($data as $key => $value)
               $converted_data[$this->mappings[$key]] = addslashes($value);
	/* put each line into  its own entry in  the $table array   */
            $table[] = $converted_data; 
   //close file
    return $table;




How To Create Photoshop Action

(1).With a file open in Photoshop — it does not matter if the image has to be rotated or not; you just need to be in the Photoshop application — open your Actions window (Window > Actions).

(2). At the top right of the Actions box or palette, there is an arrow. Click here to open more options and select New Action.

(3). Give a Name to your Action and assign a Function Key (I give a name “rotate 90ccw” and assigned the F11 key to your action). If you like, create a new “Set” folder in advance to store related actions.

(4).Now you are ready to record each step you make. Either select Record on the window that is still open or simply click on the round record button at the bottom of the palette (it will turn red when you are in Record mode). Go to Image > Rotate Canvas > Rotate 90º CCW. Your image should rotate at 90 degrees counter-clockwise (see image below). Next, go back to your Actions options and select Stop Recording or simply click on the square button at the bottom of the palette.


5. You have just recorded your Action. To test it, press your F11 key, and the image will rotate again. The same action can now be applied to any image you open in Photoshop.


How to disable right click using php script?

First you have to put below code in php tag and run the page Now Right click is disabled for that particular page.

echo '  <script>

var isNS = (navigator.appName == "Netscape") ? 1 : 0;

if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);

function mischandler(){

return false;


function mousehandler(e){

var myevent = (isNS) ? e : event;

var eventbutton = (isNS) ? myevent.which : myevent.button;

if((eventbutton==2)||(eventbutton==3)) return false;


document.oncontextmenu = mischandler;

document.onmousedown = mousehandler;

document.onmouseup = mousehandler;


How to use magento grid to display master database value

I recently ran into this problem while I was building new customer module that use admin side grid with master child releationship

then i found solution like this

At one point I need to access value customer name that in save in master table

I create a database like this

CREATE TABLE 'gallary' (

`gallary_id` int(11) unsigned NOT NULL auto_increment,

`customer_id` int(11) unsigned NOT NULL,

PRIMARY KEY (`gallary_id`)


Then create collection without join table it display id not master value

/app/code/local/<your interface>/<your modulename>/block/adminhtml/<modulename>/Grid.php

protected function _prepareCollection()


$collection = Mage::getModel('modulename/classname')->getCollection();


return parent::_prepareCollection();


To display customer name of customer id that we get in our collection I create one array collection that have in customer[id] and customer[name], and this is assign to  grid column  with column type= option

Like this

/app/code/local/<your interface>/<your modulename>/block/adminhtml/<modulename>/Grid.php

protected function _prepareColumns()

$customers= array();
$collection = Mage::getResourceModel('customer/customer_collection')
 $customers = array();
 foreach( $collection as $customer){
 $customers[] = array('value' => $customer['entity_id'], 'label'=> $customer['name']);

foreach ($customers as $customer){



$this->addColumn('customer', array(

'header'    =>  Mage::helper('classname')->__('Customer'),

'width'     =>  '200',

'index'     =>  'customer_id',

'type'      =>  'options',

'options'   => $customers,


return parent::_prepareColumns();


And magic is display all row  of customer column display their respective customer name.

Enjoy  magento ;