Order email confirmation Issue in Magento 1.9.1

Order email confirmation Issue in Magento 1.9.1
Go to /app/code/core/Mage/Sales/Model/Order.php
First, create one directory structure on the path below, then copy and paste the file to the path below.
/app/code/local/Mage/Sales/Model/Order.php
Now, change from
$mailer->setQueue($emailQueue)->send();

to

$mailer->send();

Installing Magento2 on XAMPP

Installing  Magento2 on XAMPP could be pretty painful for the developers, as Magento2 requires a lot of server configurations.

Before you start installing you need the following:
1. XAMPP server installed in your computer
2. Magento 2 can be downloaded from this link Magento2.
Apache Version :-  2.2 or 2.4
PHP            :-  5.5.x or 5.6.x
MySQL          :-  5.6.x

Installation :-
1.) Enter your Magento 2 url in browser and hit Enter.

2.) Click on “Agree and Setup Magento”.

3.) Now Magento 2 will check your environment for readiness for the setup. Click on “Start readiness check”.

4.) Now enter Empty database that you created previously, where you want to install Magento2.

5.) Click Next, now you will be asked for web configurations like store url, admin url, Apache rewrites, https options.

6.) Click Next, now you can select Timezone, Currency and language in “Customize Your Store” section.

7.)Click Next, Enter Admin username, email and password to setup Admin credentials.

8.)Click Next, Voila J, Now Magento 2 is ready to be installed on localhost. Click on “Install Now”. Don’t close your browser until setup is done.

9.)After the installer has completed the setup, it will show Success page.

10.) Now You can open Magento Admin panel and front page.

Installing Magento 2 with Composer

Installing Magento 2 with Composer

1. Install Composer
curl -sS https://getcomposer.org/installer | php

  1.1 Make Composer Globally Available
mv composer.phar /usr/local/bin/composer

2. Download Magento 2
 2.1 Via Git
git clone git@github.com:magento/magento2.git
This clones the repository and puts it under the magento2 directory. The thing is that you now still have to manually invoke Composer to fetch all the dependencies:
cd magento2 && composer install

 2.2 Via Composer
composer create-project magento/community-edition magento2 -s dev –prefer-dist

 2.3 Build from source
At the moment of writing, the Magento 2 project is divided into two Github repositories: magento2 and magento2-community-edition. The former hosts the complete Magento 2 code base and the latter has recently been completely wiped and only hosts the composer.json for “building from source”.

The magento2 repository is known on Packagist as magento/community-edition. magento2-community-edition is known on Packagist as magento/product-community-edition. They couldn’t have made it any more confusing!

If you prefer have all the Magento modules collected for you instead of having them prepared already, as is the case with the magento/community-edition package, you can create a new magento/product-community-edition project.

composer create-project magento/product-community-edition magento2 -s dev –prefer-source

3. Set Up Permissions
After all dependencies are retrieved, you should set the correct permissions on the entire Magento 2 installation directory.

And Run your local host directory  Url From Frontend.

MySQL Database Backup Using PHP

<?php
$host=”localhost”;
$uname=”root”;
$pass=””;
$database = “manv_jqueryimageupload”;
$connection=mysql_connect($host,$uname,$pass)or die(“Database Connection Failed”);

$selectdb=mysql_select_db($database) or die(“Database could not be selected”);
$result=mysql_select_db($database)
or die(“database cannot be selected <br>”);
function backup_db(){
/* Store All Table name in an Array */
$allTables = array();
$result = mysql_query(‘SHOW TABLES’);
while($row = mysql_fetch_row($result)){
$allTables[] = $row[0];
}
$return = “”;
foreach($allTables as $table){
$result = mysql_query(‘SELECT * FROM ‘.$table);
$num_fields = mysql_num_fields($result);

$return.= ‘DROP TABLE IF EXISTS ‘.$table.’;’;
$row2 = mysql_fetch_row(mysql_query(‘SHOW CREATE TABLE ‘.$table));
$return.= “\n\n”.$row2[1].”;\n\n”;

for ($i = 0; $i < $num_fields; $i++) {
while($row = mysql_fetch_row($result)){
$return.= ‘INSERT INTO ‘.$table.’ VALUES(‘;
for($j=0; $j<$num_fields; $j++){
$row[$j] = addslashes($row[$j]);
$row[$j] = str_replace(“\n”,”\\n”,$row[$j]);
if (isset($row[$j])) { $return.= ‘”‘.$row[$j].'”‘ ; }
else { $return.= ‘””‘; }
if ($j<($num_fields-1)) { $return.= ‘,’; }
}
$return.= “);\n”;
}
}
$return.=”\n\n”;
}

// Create Backup Folder
$folder = ‘DB_Backup/’;
if (!is_dir($folder))
mkdir($folder, 0777, true);
chmod($folder, 0777);

$date = date(‘m-d-Y-H-i-s’, time());
$filename = $folder.”db-backup-“.$date;

$handle = fopen($filename.’.sql’,’w+’);
fwrite($handle,$return);
fclose($handle);
}

// Call the function
backup_db();
?>

 

Note : Please check ‘ and ” and then use this code. 

How to resize image in custom module in magento

Open namespace/modulename/helper/data.php

paste following code in helper class :-

<?php

class Namespace_Modulename_Helper_Data extends Mage_Core_Helper_Abstract

{

public function resizeImage($imageName, $width=NULL, $height=NULL, $imagePath=NULL)

{

$imagePath = str_replace(“/”, DS, $imagePath);

$imagePathFull = Mage::getBaseDir(‘media’) . DS . $imagePath . DS . $imageName;

if($width == NULL && $height == NULL) {

$width = 100;

$height = 100;

}

$resizePath = $width . ‘x’ . $height;

$resizePathFull = Mage::getBaseDir(‘media’) . DS . $imagePath . DS . $resizePath . DS . $imageName;

if (file_exists($imagePathFull) && !file_exists($resizePathFull)) {

$imageObj = new Varien_Image($imagePathFull);

$imageObj->constrainOnly(TRUE);

$imageObj->keepAspectRatio(TRUE);

$imageObj->resize($width,$height);

$imageObj->save($resizePathFull);

}

$imagePath=str_replace(DS, “/”, $imagePath);

return Mage::getBaseUrl(“media”) . $imagePath . “/” . $resizePath . “/” . $imageName;

}

}

and  use in any template/phtml file of your module :-

<img src=”<?php echo Mage::helper(‘modulename’)->resizeImage(‘imagename.jpg’, 100, 100, ‘path/image’); ?>” style=”padding:10px;”>

Note :- it take automatically base url (www.domain.com/media/). So you put only your image url.

Magento : Login Issue in magento after upgrade to magento 1.8

Find the following code in /app/design/frontend/package_name/theme_name/template/persistent/customer/form/login.phtml
<ul class=”form-list”>
<li>
and put this line below the above code :

<input type=”hidden” name=”form_key” value=”<?php echo Mage::getSingleton(‘core/session’)->getFormKey(); ?>” />

 

Note : Please check Single Quote(‘) and double quote (“) then use it.

Contact us form with attachment in magento

1.)Edit -> ../app/design/frontend/[your-interface]/[your-theme]/template/contacts/form.phtm
Add enctype
<form action=”<?php echo $this->getFormAction(); ?>” id=”contactForm” method=”post” enctype=”multipart/form-data”>
2.)Add Upload field to the form
<li>
<label for=”attachment”><?php echo Mage::helper(‘contacts’)->__(‘Attachment’) ?></label>
<div>
<input name=”MAX_FILE_SIZE” type=”hidden” value=”2000000″ />
<input name=”attachment” id=”attachment” type=”file” />
</div>
</li>
3.) Add fileattachment / upload to contact controler    /app/code/core/Mage/Contacts/controllers/IndexController.php
After Line 93
if ($error) {
throw new Exception();
}
Add
/**************************************************************/
$fileName = ”;
if (isset($_FILES[‘attachment’][‘name’]) && $_FILES[‘attachment’][‘name’] != ”) {
try {
$fileName       = $_FILES[‘attachment’][‘name’];
$fileExt        = strtolower(substr(strrchr($fileName, “.”) ,1));
$fileNamewoe    = rtrim($fileName, $fileExt);
$fileName       = preg_replace(‘/\s+’, ”, $fileNamewoe) . time() . ‘.’ . $fileExt;

$uploader       = new Varien_File_Uploader(‘attachment’);
$uploader->setAllowedExtensions(array(‘zip’, ‘jpg’,’pdf’, ‘rar’, ‘png’, ‘eps’, ‘ai’));
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = Mage::getBaseDir(‘media’) . DS . ‘contacts’;
if(!is_dir($path)){
mkdir($path, 0777, true);
}
$uploader->save($path . DS, $fileName );

} catch (Exception $e) {
$error = true;
}
}
/**************************************************************/
Below that should be
$mailTemplate = Mage::getModel(‘core/email_template’);

Add this
$attachmentFilePath = Mage::getBaseDir(‘media’). DS . ‘contacts’ . DS . $fileName;
if(file_exists($attachmentFilePath)){
$fileContents = file_get_contents($attachmentFilePath);
$attachment   = $mailTemplate->getMail()->createAttachment($fileContents);
$attachment->filename = $fileName;
}

how to get all product from all category in slider on view page in magento

<?php
$categoryidxxx = Mage::getModel(‘catalog/layer’)->getCurrentCategory()->getId();
if($categoryidxxx!=’2′)
{
$category_id = Mage::registry(‘current_category’)->getId();
/*  get category id to product id   */
$category = new Mage_Catalog_Model_Category();
$category->load($category_id); //My cat id is 10
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds arraygetProductUrl
}

/*   product id to get product array key  */
$product_id = $this->getProduct()->getId();
$key = array_search($product_id, $prdIds); // $key = 2;

/* get current , next , prev array key  */
$curremidx=$prdIds[$key];
$nextidx=$prdIds[$key+1];
$previdx=$prdIds[$key-1];

/* get product id to product url */
$objn = Mage::getModel(‘catalog/product’);
$_productn = $objn->load($nextidx);
$next_p_u = $_productn->getProductUrl();

$objp = Mage::getModel(‘catalog/product’);
$_productp = $objp->load($previdx);
$prev_p_u = $_productp->getProductUrl();

/* get first and last array value  */
$c1 = current($prdIds);
$e1 = end($prdIds);

if($curremidx==$c1)
{ $p_url=’#’; $pcname=’dactive’; }else { $p_url=$prev_p_u; $pcname=’active’; }

if($curremidx==$e1)
{ $n_url=’#’; $ncname=’dactive’; }else { $n_url=$next_p_u;  $ncname=’active’;}

?>
<a id=”prevx” href=”<?php echo $p_url; ?>” >Prev << </a>
<a id=”nextx” href=”<?php echo $n_url; ?>” >Next >> </a>

<?php } ?>

 

Note : Please check Single Quote(‘) and double quote (“) then use it.

How to Export Product like Google Base Xml in Magento

<?php
// Magento XML products exporter
// by Manvendra Sharma
// http://sharmamanvndra.wordpress.com/

require_once ‘app/Mage.php’;
umask( 0 );
Mage::app( “default” );
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//echo getcwd();

$_urlPath = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$_imagePath = $_urlPath . “media”;
$_logFileName = getcwd().”export_products.log”;
$_xmlPath = getcwd().”/var/export”;
$xmlFile = $_xmlPath . “/” . “new5.xml”;

$doc = new DomDocument(‘1.0’, ‘UTF-8’);
$doc->preserveWhiteSpace = false;
$doc->formatOutput = true;
//$element = $doc->createElement(‘test’, ‘This is the root element!’);
$rss = $doc->createElement(‘rss’);
$doc->appendChild($rss);

$version = $doc->createAttribute(‘version’);
$rss->appendChild($version);

$value = $doc->createTextNode(‘2.0 ‘);
$version->appendChild($value);

$xml = $doc->createAttribute(‘xml:g’);
$rss->appendChild($xml);

$value = $doc->createTextNode(‘http://base.google.com/ns/1.0 ‘);
$xml->appendChild($value);

$xmlns_wp = $doc->createAttribute(‘xmlns:g’);
$rss->appendChild($xmlns_wp);

$valuewp12 = $doc->createTextNode(‘http://base.google.com/ns/1.0&#8217;);
$xmlns_wp->appendChild($valuewp12);

// We insert the new element as root (child of the document)
// $doc->appendChild($element);
//$doc->createElementNS(‘http://base.google.com/ns/1.0&#8217;, ‘g:item_type’, ‘house’);
//$doc->simplexml_load_string(‘<rss version=”2.0″ xmlns:g=”http://base.google.com/ns/1.0″>&#8217;);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace(‘g’, “http://base.google.com/ns/1.0&#8221;);
$chennel=$doc->CreateElement(‘chennel’);
$chennel = $rss->appendChild($chennel);
Mage::log( “Export start”, null, $_logFileName );

// Prepare collection
$_productCollection = Mage::getModel(‘catalog/product’)->getCollection();
$_productCollection->addAttributeToSelect(‘*’);

/* You can change and uncomment these lines below to filter your products collection */

// Filter by updated_at date, get only daily changes
//$_productCollection->addFieldToFilter(‘updated_at’, array(‘from’=>date(“Y-m-d”, time()-86400)));

// Filter by product type, get only downloadables
//$_productCollection->addFieldToFilter(‘type_id’,  array(‘like’=>’downloadable’));

// Filter by sku get only products with sku like “EBOOK-%”
//$_productCollection->addFieldToFilter(‘sku’,  array(‘like’=>’EBOOK-%’));

// Limit output to 15 records
//$_productCollection->getSelect()->limit(15);

Mage::log( “Products to be exported: ” . $_productCollection->count(), null, $_logFileName );
$_productCollection->count();
$i = 1;
foreach ( $_productCollection as $_product ) {

// Prepare array of variables to grow XML file
$v[‘g:id’] = $_product->getSku();
$v[‘title’] = $_product->getName();
// $v[‘type’] = $_product->getTypeId();
$v[‘link’] = $_urlPath . $_product->geturlpath();
$v[‘description’] = $_product->getDescription();
$v[‘short_description’] = $_product->getShortDescription();
$v[‘meta_title’] = $_product->getMetaTitle();
$v[‘meta_description’] = $_product->getMetaDescription();
$v[‘meta_keyword’] = $_product->getMetaKeyword();
$v[‘g:created_at’] = $_product->getCreatedAt();
$v[‘g:updated_at’] = $_product->getUpdatedAt();
$v[‘g:image_link’] = $_urlPath . $_product->geturlpath();
$v[‘g:image’] = $_imagePath . $_product->getImage();
$v[‘image_label’] = $_product->getImageLabel();
$v[‘g:price’] = $_product->getPrice();
$v[‘g:special_price’] = $_product->getSpecialPrice();
$v[‘g:shipping_weight’] = $_product->getWeight();

// Get the Magento categories for the product
$categoryIds = $_product->getCategoryIds();

foreach($categoryIds as $categoryId) {
$category = Mage::getModel(‘catalog/category’)->load($categoryId);
$v[‘categories’][$_product->getSku()][] = $category->getName();
}

// If product is downloadable get some informations about links added
/*  if ( $_product->getTypeId() == “giftcard” ) {
$_links = Mage::getModel(‘giftcard/product_type’)->getLinks( $_product );
foreach ( $_links as $_link )
$v[‘available_formats’][$_product->getSku()][] = $_link->getTitle();
}*/

// Prepare XML file to save

$root = $doc->createElement(‘item’);
$root = $chennel->appendChild($root);

/*$occ = $doc->createElement(‘root’);
$occ = $root->appendChild($occ);*/

foreach ( $v as $fieldName => $fieldValue ) {
$child = $doc->createElement($fieldName);
$child = $root->appendChild($child);

if ( is_array($fieldValue) ) {
$value = $doc->createCDATASection(implode( “|”, $fieldValue[$_product->getSku()] ));
$value = $child->appendChild($value);
} else {
$value = $doc->createCDATASection($fieldValue);
$value = $child->appendChild($value);
}
//$channel->appendChild($value);

}

}

echo $doc->save( $xmlFile ).'<br/>’;

Mage::log( “File ” . $i . “: ” . $_product->getSku(), null, $_logFileName );
$i++;

Mage::log( “Export done”, null, $_logFileName );