Wednesday, September 5, 2012

Sql query for getting Category id and name from magento database table


SELECT `entity_id`,`value` FROM `catalog_category_entity_varchar` WHERE `attribute_id` = 3 and
`entity_id` IN(SELECT distinct(`entity_id`)  FROM `catalog_category_entity` WHERE `path` LIKE
'%1/xxx%')
For more than one store
Take the root category id  of store from admin and put it in place of 1/xxx as 1/categoryid
Also you have to search in table `catalog_category_entity_varchar'  for attribute_id  by giving the name of you store root category in place of value field.

SELECT  `attribute_id`   FROM `catalog_category_entity_varchar` WHERE `value` = "your category name";

Monday, April 23, 2012

How to Create different store view with different sub-domain in magento

How to create store view


1. Go to admin then select tab System->manage stores
2.Click create store view and complete the form and save store view
then you will be able to see in the list.

How to Change the Base URL for each Store view


1.. Go to admin then select tab System->configuration
2.On the left side of the page General under that select web but before that you have to change the Current Configuration Scope to your store view name
3. Edit the base url to you subdomain(eg: http://en.yourdomain.com)
4.click save config.

How to change .htaccess for redirecting to store view if you call the subdomain


1.Your .htaccess file is at the root folder of magento.
2.Search for "RewriteEngine on" word  in .htaccess file and write the code below it

RewriteCond %{HTTP_HOST} ^en.yourdomain.com
RewriteRule ^ - [E=MAGE_RUN_CODE:english]
RewriteCond %{HTTP_HOST} ^fr. yourdomain .com
RewriteRule ^ - [E=MAGE_RUN_CODE:french]

 then save the .htaccess file and try to clear all cache and browsing history from your browser as well as from magento

Tuesday, February 14, 2012

magento the shipment email is not sent


Solution Works For Me
Go to -> Mage_Sales_Model_Order_Shipment and copy the file Api.php
Make a path like this in local folder app/code/local/Mage/Sales/Model/Order/Shipment
Edit Api.php 
In function Create comment the sendEmail function call
try { 
$transactionSave = Mage::getModel(’core/resource_transaction’) 
->addObject($shipment) 
->addObject($shipment->getOrder()) 
->save(); 
/*$shipment->sendEmail($email, ($includeComment ? $comment : ‘’));*/ 
} catch (Mage_Core_Exception $e) { 
$this->_fault(’data_invalid’, $e->getMessage()); 

In function addTrack add function call sendEmail
try { 

$shipment->save(); 
$track->save(); 
$email=true; 
$shipment->sendEmail($email,’’); 
} catch (Mage_Core_Exception $e) { 
$this->_fault(’data_invalid’, $e->getMessage()); 
}
Now you Shipment Email will be send as usual email with tracking number

Friday, February 3, 2012

PHP Mailing by attaching a file

<?php
  $to = "some mail@mymail.com";
  $subject = "New Product Details";
  $message = "New product be find in attachment.";
  # Open a file
  $file = fopen( "product.txt", "r" );
  if( $file == false )
  {
     echo "Error in opening file";
     exit();
  }
  # Read the file into a variable
  $size = filesize("product.txt");
  $content = fread( $file, $size);
  # encode the data for safe transit
  # and insert \r\n after every 76 chars.
  $encoded_content = chunk_split( base64_encode($content));
 
  # Get a random 32 bit number using time() as seed.
  $num = md5( time() );
  # Define the main headers.
  $header = "From:admin@magento-works.com\r\n";
  $header .= "MIME-Version: 1.0\r\n";
  $header .= "Content-Type: multipart/mixed; ";
  $header .= "boundary=$num\r\n";
  $header .= "--$num\r\n";
  # Define the message section
  $header .= "Content-Type: text/plain\r\n";
  $header .= "Content-Transfer-Encoding:8bit\r\n\n";
  $header .= "$message\r\n";
  $header .= "--$num\r\n";
  # Define the attachment section
  $header .= "Content-Type:  multipart/mixed; ";
  $header .= "name=\"test.txt\"\r\n";
  $header .= "Content-Transfer-Encoding:base64\r\n";
  $header .= "Content-Disposition:attachment; ";
  $header .= "filename=\"product.txt\"\r\n\n";
  $header .= "$encoded_content\r\n";
  $header .= "--$num--";
  # Send email now
  $retval = mail ( $to, $subject, "", $header );

  if( $retval == true )
   {
      echo "Message sent successfully...";
   }
   else
   {
      echo "Message could not be sent...";
   }
  
  
   
?>

Monday, January 30, 2012

Upgrade Magento from 1.5.1 to 1.6.2 with magento connect in windows

I think upgrading using magento connect is not so risk

Step:1
Go to admin pannel and login.

step:2
Go to System ->Magento Connect->Magento Connect Manager

step:3
Login with your admin user and password and copy&paste this link
"http://connect20.magentocommerce.com/community/Mage_All_Latest"
in the paste extenstion key install and press 'install' button.Then you get a list of all modules with latest version.
Step:4
Before clicking commit Change you have to do this
  To allow MCM to overwrite existing files you need to edit this file:
  downloader\lib\Mage\Connect\Validator.php
  and remove this part:
 if (file_exists($dest)) {
                $this->addError("'{$file}' already exists");
                return false;
            }
 which is right at the bottom of the file
 If installation fails you will need to re-edit the file as it will be replaced by the version just  downloaded
If you install without changing you will get error "files already exists" and it will not install.

Step:5
After successfull installation when you open the front end you get a error
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtimeor capacity problems. Please try again later.
error 
To clear the error check if there is a file called maintenance.flag in your magento root. If so Delete it
and also clear the cache.

Step:6
Not over there is still error
Stops at "1025 Error on rename of catalog_category_flat_store_1
If you encounter the error
Error in file: "/xxx/app/code/core/Mage/Catalog/sql/catalog_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php" - SQLSTATE[HY000]: General error: 1025 Error on rename of './catalog_category_flat_store_1' to './#sql2-6221-31dae3' (errno: 152)” 
to solve this error by running the queries in the database
ALTER TABLE catalog_category_entity ENGINE=INNODB;
ALTER TABLE core_store ENGINE=INNODB;
ALTER TABLE catalog_category_entity ENGINE=INNODB;
ALTER TABLE core_store ENGINE=INNODB;


NOW YOUR PROBLEM IS SOLVED YOU HAVE UPDATED MAGENTO 1.5.1.0 TO MAGENTO 1.6.2.0

Tuesday, January 24, 2012

.htaccess Rewrite Rule for converting /names.php?name=boy&id=23&page=1 to names/boy/23/1

Pass the Query string through url not by traditional method but by using mod rule in .htaccess file
 /names.php?name=boy&id=23&page=1 to names/boy/23/1


RewriteEngine on
RewriteCond %{QUERY_STRING} ^name=(.+)&id=(.+)&page=(.+)$ [NC]
RewriteRule ^names\.php$  /names/%1/%2/%3? [R=301,NE,NC,L]

If you want to convert all the pages to
http://localhost/ram1/2/3
http://localhost/ram1.php?id=2&page=3
http://localhost/ram1/1
http://localhost/ram1.phppage=1
 use the rewrite rule below to automatically converts to corresponding Query String


RewriteEngine on
RewriteRule ^(.+)/([0-9]+)/([0-9]+)/?$ $1.php?id=$2&page=$3 [L]
RewriteRule ^(.+)/([0-9]+)/?$ $1.php?page=$2 [L]