Popular Posts

Saturday, 12 April 2014

How to delete test orders in magento

To delete test order from magento:
  1. Login to Admin Panel and go to Sales-->Orders.
  2. Note down your test order ids, for example: 100000001,100000002,100000003,100000111,100000112,100000199
  3. Now create a php file in magento root directory and name it: deleteOrders.php
  4. Now copy below code and paste it in your file:


    <?php
    require 'app/Mage.php';
    Mage::app('admin')->setUseSessionInUrl(false);                                                                                                                 //replace your own orders numbers here:
    $test_order_ids
    =array(
     
    '100000001',
     
    '100000002',
     
    '100000003',
     
    '100000109',
     
    '100000112',
     
    '100000134'
    );
    foreach($test_order_ids as $id){
       
    try{
           
    Mage::getModel('sales/order')->loadByIncrementId($id)->delete();
            echo
    "order #".$id." is removed".PHP_EOL;
       
    }catch(Exception $e){
            echo
    "order #".$id." could not be remvoved: ".$e->getMessage().PHP_EOL;
       
    }
    }
    echo
    "complete."
     ?>
     
  5. Now go to your browsers address bar and run file from here like:
    [Your_Magento_Base_URL] /deleteOrders.php

How to get currency symbol in Magento


 To get currency symbol for current store:

<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>

or if you want to pass a certain currency code to get currency symbol, then use it:

<?php echo Mage::app()->getLocale()->currency('[CURRENCY_CODE]')->getSymbol(); ?>


Where CURRENCY_CODE should be replaced by currency code of your store:For Example:

<?php echo Mage::app()->getLocale()->currency('AUD')->getSymbol(); ?>



..........:)

Thursday, 10 April 2014

How to upgrade Magento 1.7.1 to 1.8, 1.9, 1.10

Note=->> I'm running Magento enterprise 1.7.1 and I'm searching for any possible way to upgrade this to 1.8, or straight to 1.10.
Currently, I have MANY custom modules w/accompanying SQL that should be run on a fresh install. Here's some things I've attempted:
First: I downloaded the 1.8 and copied all the files from it into my existing 1.7.1 build. I then replaced the local.xml, index.php, and .htaccess with my 1.7.1 build. I attempted to load the homepage, and it turned (computing for a while) then loaded a blank screen. I have nothing in the logs/ logging/ apache-error or php error logs. So, that didn't work.
Second: Accoding to many links, people use PEAR to perform the upgrade. However, they mention not using the system pear, but using the pear in Magento's root (There's also no pear in the root of the 1.10 I just downloaded or the 1.8). Well, I don't have a pear in Magento's root. I do have a pear in lib/PEAR/, but that doesn't seem to run at all:
lib/PEAR$ php ./PEAR.php mage-setup .

lib/PEAR$ php ./PEAR.php install magento-core/Mage_All_Latest
Nothing happens, just returns control to the shell.
There is zero documenation for performing a successful upgrade on Magento, and other posts on stackoverflow don't give me much hope:
^ Are pretty awful resources. Any help is appreciated.

How to upload free magento extension on magento connect

There are three types of Magento extensions:


Magento Core Extensions: These are open source extensions created by the Magento Core team, released under an OSL 3.0 license and distributed for download through PEAR.
Magento Community Extensions: These are open source extensions created by Magento Community members or partners also released under an open source license and distributed for download through PEAR.
Magento Commercial Extensions: Magento Commercial extensions are contributions offered for sale by Magento community members or partners. However, the sale transaction, distribution and licensing is managed by the seller and occur outside Magento.

Creating a Magento Community extension:


1. Package your extension
Follow the steps in http://www.magentocommerce.com/wiki/packaging_a_magento_extension  for packaging your extension
2. Upload your extension
If you are listed as one of the lead maintainers for the package, you can upload it and post it on MagentoConnect from your Magento Community Account. Just, login to your Magento Community account and navigate to the My Account section by clicking on your username and selecting My Account from the drop-down menu.
From the left menu under the heading Magento Connect, select Community Extension and in the main area click on the “Upload a new community extension” link.
Extension Info
  • Extension File Name: Must match the PEAR name of package. (Mage_Oscommerce)
  • Extension Friendly Name: Name that will display in MagentoConnect. (osCommerce DataBase Import)
  • Tags: Add tags to make it easier for community members to find you extension
  • Short Description: Description for extension in listing view.
  • License Type: Choose an open source license type. If not sure consult  
    http://www.magentocommerce.com/wiki/packaging_a_magento_extension
  • Categories: Select category(s). Choose other, if the category you wanted is not listed and contact us with the desired category name.
  • Locales: Select the locale(s) available with this extension.
  • Detailed Description: Description for extension in detail view.
  • Screenshot: Upload a screenshot of thee extension
  • Caption: write a short description for screenshot
  • Click on the “Next Step” button.
Upload Extension Release:
  • Upload the package (tar.gz) file.
  • The Extension Guidelines - Extension Status can be found here.
3. Navigate to MagentoConnect in the Magento community site to view your extension.

Editing a Magento Community extension:


  • 1. Community Extensions that you uploaded are accessible through your Community Account section as well. You can edit the information that is used to display the extension on MagentoConnect.

Downloading and Installing a Magento Core or Community extension:


Get Extension Key
  1. Find extension in Magento Connect: Click on the extension name to view the extension’s details.
  2. Get Extension Key Click on Extension Key button. Extension key is what MagentoConnect uses to identify the package in PEAR.
  3. Check the box to agree to the extension license agreement
  4. Click on the Get Extension Key again.
  5. Select selection key displaying in the text box and copy.
Download and Installation
  1. Navigate to your Magento Admin Panel and select Manage Extension under the System Menu
  2. After logging in with your Admin login, paste in the extension key you copied and click the “Install” button.
Manage Existing Packages
You can also manage your previously-installed extensions in this interface: reinstall, uninstall or upgrade extensions for which a new release has been issued.

Note :_- http://info.magento.com/rs/magentocommerce/images/packagingmagentoconnectextensions6%200.pdf

php example Ajax live search

HTML PAGE

=======================================


<html>
<head>
<script>
function showResult(str)
{
if (str.length==0)
  { 
  document.getElementById("livesearch").innerHTML="";
  document.getElementById("livesearch").style.border="0px";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
    document.getElementById("livesearch").style.border="1px solid #A5ACB2";
    }
  }
xmlhttp.open("GET","livesearch.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<input type="text" size="30" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>

</body>
</html>


 ============================================

PHP FILE



<?php
$xmlDoc=new DOMDocument();
$xmlDoc->load("links.xml");

$x=$xmlDoc->getElementsByTagName('link');

//get the q parameter from URL
$q=$_GET["q"];

//lookup all links from the xml file if length of q>0
if (strlen($q)>0)
{
$hint="";
for($i=0; $i<($x->length); $i++)
  {
  $y=$x->item($i)->getElementsByTagName('title');
  $z=$x->item($i)->getElementsByTagName('url');
  if ($y->item(0)->nodeType==1)
    {
    //find a link matching the search text
    if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
      {
      if ($hint=="")
        {
        $hint="<a href='" . 
        $z->item(0)->childNodes->item(0)->nodeValue . 
        "' target='_blank'>" . 
        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
        }
      else
        {
        $hint=$hint . "<br /><a href='" . 
        $z->item(0)->childNodes->item(0)->nodeValue . 
        "' target='_blank'>" . 
        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
        }
      }
    }
  }
}

// Set output to "no suggestion" if no hint were found
// or to the correct values
if ($hint=="")
  {
  $response="no suggestion";
  }
else
  {
  $response=$hint;
  }

//output the response
echo $response;
?>

php code to search and show results on same page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<?
// MySQL Connection Information
$server = "localhost";
$username = "sharlene";
$password = "";
$dbname = "baby_names";
// MySQL Connect String
$connection = mysql_connect($server,$username,$password);
// Select the database
mysql_select_db($dbname);
$gender = $_POST['gender'];
$meaning = $_POST['meaning'];
$name = $_POST['name'];
$origin = $_POST['origin'];
$gender = mysql_real_escape_string($gender);
$meaning = mysql_real_escape_string($meaning);
$name = mysql_real_escape_string($name);
$origin = mysql_real_escape_string($origin);
$sql = "SELECT * FROM names WHERE gender = '" . $gender . "' and name LIKE '" . $name . "%' and
meaning LIKE '%" . $meaning . "%' and origin = '" . $origin . "'";
//print($sql);
//execute SQL query and get result
$sql_result = mysql_query($sql, $connection)
    or die(mysql_error());
//print("after sql");
// Loop through the data set and extract each row into it's own variable set
while ($row = mysql_fetch_array($sql_result)) {
    extract($row);
}
// Loop through the data set and extract each row into it's own variable set
//while ($row = mysql_fetch_array($sql_result)) {
//    echo $row['gender']." ".$row['meaning']." ".$row['name']." ".$row['origin']."<br>";
?>
</BODY>
</HTML>

Magento: How to get last order id

There are many ways to get last order id:   1. From checkout session: $lastOrderId = Mage::getSingleton('checkout/session'...