Remove all category in magento

We can use the following steps to clear the all category for magento by running the sql query.

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;
  
INSERT INTO `catalog_category_entity`
  (`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) 
VALUES 
  (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),
  (2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
 
INSERT INTO `catalog_category_entity_int`
  (`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) 
VALUES 
  (1,3,32,0,2,1),
  (2,3,32,1,2,1);
 
INSERT INTO `catalog_category_entity_varchar`
  (`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) 
VALUES 
  (1,3,31,0,1,'Root Catalog'),
  (2,3,33,0,1,'root-catalog'),
  (3,3,31,0,2,'Default Category'),
  (4,3,39,0,2,'PRODUCTS'),
  (5,3,33,0,2,'default-category');
SET FOREIGN_KEY_CHECKS = 1;

Source : https://gist.github.com/jklance/9664371

Convert a password the Magento way

Here’s how to convert passwords from plain text to the alghorithm used by Magento.

This can result useful when you need to import users from an external application which was managing passwords with no encryption.

So, let’s assume we already imported the customers from magento import tool and they can’t login because their password don’t fit Magento’s way, which is defined this way ( read it as a PHP developer ):

md5(salt.password):salt

So, to convert all customers passwords you only need to login into mysql and run a single query:

mysql -u root -e "UPDATE customer_entity_varchar SET value = CONCAT( MD5(CONCAT('salt', value)), ':salt') WHERE attribute_id = '12'"
-- don't care about my local config 😉

Source : http://odino.org/convert-a-password-the-magento-way/

Reduce magento database size

Sometime we may face the problem of huge database size even after all product is deleted.
Run the following code in the sql,

TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;

Sometime we may get error so try to run code one by one. And enable cache for folder only not for database during installation.

Source : http://www.tipsaid.com/reduce-magento-database-size/

Magento Adding search by category in advance search

Sometime we may need to change the options provided by the magento by default. Here are dealing with adding the “Search By Category” in the advance search page. For this case we need to change in the followinf files
➣ app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php
➣ app/code/core/Mage/CatalogSearch/Model/Advanced.php
➣ app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml

At the very end of app/code/core/Mage/CatalogSearch/Block/Advanced/Form.php (before the closing brace), add:

public function getStoreCategories()
{
    $helper = Mage::helper('catalog/category');
    return $helper->getStoreCategories();
}

In app/code/core/Mage/CatalogSearch/Model/Advanced.php, replace the getSearchCriterias() function (line 157) with the code below:

     public function getSearchCriterias()
        {
            $search = $this->_searchCriterias;
            /* display category filtering criteria */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) {
                $category = Mage::getModel('catalog/category')->load($_GET['category']);
                $search[] = array('name'=>'Category','value'=>$category->getName());
            }
            return $search;
        }

replace the next function, getProductCollection(), with:

public function getProductCollection(){
        if (is_null($this->_productCollection)) {
            $this->_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
                ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                ->addMinimalPrice()
                ->addStoreFilter();
                Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
                Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
            /* include category filtering */
            if(isset($_GET['category']) && is_numeric($_GET['category'])) $this->_productCollection->addCategoryFilter(Mage::getModel('catalog/category')->load($_GET['category']),true);
        }
 
        return $this->_productCollection;
    }

In app/design/yourdesign/yourdesign/template/catalogsearch/advanced/form.phtml, after this code:

 <?php foreach ($this->getSearchableAttributes() as $_attribute): ?>
        <?php $_code = $_attribute->getAttributeCode() ?>
            <label for="<?php echo $_code ?>"><?php echo $this->getAttributeLabel($_attribute) ?></label>
            <?php switch($this->getAttributeInputType($_attribute)):
                case 'number': ?>
                <div class="range field-row">
                    <input name="<?php echo $_code ?>[from]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'from')) ?>" id="<?php echo $_code ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text" />
                    <input name="<?php echo $_code ?>[to]" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute, 'to')) ?>" id="<?php echo $_code ?>_to" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text validate-number" type="text"/>
                </div>
                <?php break;
                case 'select': ?>
                    <?php echo $this->getAttributeSelectElement($_attribute) ?>
                <?php break;
                case 'yesno': ?>
                    <?php echo $this->getAttributeYesNoElement($_attribute) ?>
                <?php break;
                case 'date': ?>
                    <?php echo $this->getDateInput($_attribute, 'from') ?>
                    -
                    <?php echo $this->getDateInput($_attribute, 'to') ?>
                <?php break;
                default: ?>
                <input name="<?php echo $_code ?>" id="<?php echo $_code ?>" value="<?php echo $this->htmlEscape($this->getAttributeValue($_attribute)) ?>" title="<?php echo $this->htmlEscape($this->getAttributeLabel($_attribute)) ?>"  class="input-text <?php echo $this->getAttributeValidationClass($_attribute) ?>" type="text" />
            <?php endswitch; ?>
        <?php endforeach; ?>

add:

            <label for="category_search_field">Search by Category:</label>
            <select name="category" id="category_search_field">
                <option value="">-- Any Category --</option>
                <?php foreach ($this->getStoreCategories() as $_category): ?>
                <?php if($_category->hasChildren()): ?>
                <option class="parent-cat" value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php foreach ($_category->getChildren() as $subcategory):
                if($subcategory->getIsActive()) : ?>
                    <option value="<?php echo $subcategory->getId(); ?>"<?php echo ($this->getRequest()->getQuery('category') == $subcategory->getId() ? ' selected="selected"': "") ?>><?php echo $subcategory->getName(); ?></option>
                <?php endif; endforeach; ?>
                <?php elseif($_category->getIsActive()): ?>
                <option value="<?php echo $_category->getId(); ?>"><?php echo $_category->getName();?></option>
                <?php endif; ?>
                <?php endforeach ?>
 
            </select>

Then open app/code/core/Mage/CatalogSearch/Model/Advanced.php
Open the file and search this function addFilters. In this function you can see following codes, replace this

    if ($allConditions) {
                $this->getProductCollection()->addFieldsToFilter($allConditions);
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));
            }

with following codes:

    if (($allConditions) || (isset($values['category']) && is_numeric($values['category']))) {
                $this->getProductCollection()->addFieldsToFilter($allConditions);
            } else if (!count($filteredAttributes)) {
                Mage::throwException(Mage::helper('catalogsearch')->__('You have to specify at least one search term'));
            }

After above steps is done you will get the output as below
search by category

Source : http://www.magentocommerce.com/wiki/5_-_modules_and_development/search_and_advanced_search/how_to_add_search_by_category_to_advanced_search

Magento quantity increments using jQuery

If we need to add increments in the quantity then we can follow the below simple method .
First of all we need to add the jQuery code. Add the following to one of your jQuery js files (or create a new one if that’s your thing).

jQuery("div.quantity").append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
        jQuery(".plus").click(function()
        {
            var currentVal = parseInt(jQuery(this).prev(".qty").val());
            
            if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;
             
            jQuery(this).prev(".qty").val(currentVal + 1);
        });
     
        jQuery(".minus").click(function()
        {
            var currentVal = parseInt(jQuery(this).next(".qty").val());
            if (currentVal == "NaN") currentVal = 0;
            if (currentVal > 0)
            {
                jQuery(this).next(".qty").val(currentVal - 1);
            }
        });

Then Move the file app/design/frontend/base/default/template/catalog/product/view/addtocart.phtml into your theme directory if you haven’t already, open it up and look for line 34. You should see the code for the input which will look something like:

<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />

Change the AS BELOW

<div class="quantity">
<input type="text" name="qty" id="qty" maxlength="12" value="<?php echo $this->getMinimalQty($_product) ?>" title="<?php echo $this->__('Qty') ?>" class="input-text qty" />
</div>
Source : http://jigowatt.co.uk/blog/magento-quantity-increments-jquery-edition/

Magento – Display Address Fields on Create an Account

By default Magento doesnt show the address fields within “Create an Account”. To make the sign up process more user friendly you can enable the address fields by adding the following:
Simple way to show that is to add the below code in customer.xml or in local.xml

<customer_account_create>
        <reference name="customer_form_register">
            <action method="setShowAddressFields"><value>true</value></action>
        </reference>
</customer_account_create>
Source : http://www.pauldonnelly.net/magento-display-address-fields-in-create-an-account/ 

Customer cannot login to magento 1.8.1.0

Using the free theme sometime may result  of customer not logged in problem issue. To resolve this issue we need to put the for key field in the login form.
In app/design/frontend/default/…/template/persistent/customer/form/login.phtml , around line 41 should look like

 <form action="<?php echo $this->getPostActionUrl() ?>" method="post" id="login-form">
 <?php echo $this->getBlockHtml('formkey'); ?> 

If the code is not seen then add it then customer login works

“Error 404 Not Found” in Magento Admin Login Page

I got “Error: 404 Not Found” when  transfered my magento installation from one local machine server to another. Now, I cannot login to admin panel and I got “Error: 404 Not Found”

The reason for this error is that store_id and website_id for admin should be set to 0 (zero). But, when you import database to new server, somehow these values are not set to 0.
Open PhpMyAdmin and run the following query in your database:-

SET FOREIGN_KEY_CHECKS=0;
UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;
Source : http://stackoverflow.com/questions/5178066/error-404-not-found-in-magento-admin-login-page 

Magento no input file specified error in Godaddy Hosting

A common error, which usually comes up if you’re hosted by GoDaddy, is the no input file specified error.
Try this first:
add this to your .htaccess file

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^.+.php$ /bogusfile

Then try to reload your setup page.
If you do not have Magento setup in the root of your server, make sure to add the following to your .htaccess file.

RewriteBase /yourbasepath/

Once that is verified, there are a couple things you can do to fix this, but we’ll start with the one that usually works.
In your web root directory, there should be a file called php.ini. Rename this to php5.ini.
If there is no php5.ini file. Create the file and upload it to your root directory.
If that doesn’t work, add the following to the end of your newly renamed php5.ini file:

cgi.fix_pathinfo = 1

And if you’re still getting the error, add the following to the top of your .htaccess file:

Options -MultiViews

The first one usually does the trick. If you don’t see this file in there, then create a blank php5.ini file add add the line listed on the second suggestion.
If all of the above has not worked, KEEP your changes, wait exactly 24 hours. Go back to youraddress.tld/downloader and try again. You may just be cached and for some reason it takes a bit longer then I was used to. Keep your chin up!
If nothing above worked, call GoDaddy up and have them either rename this for you, or make sure you’re on PHP 5.

Source : http://www.magentocommerce.com/wiki/groups/227/error/no_input_file_specified