Friday, December 31

How to add search by category option In Magento

On the advanced search page, “search by category” is not an option by default, but can be very helpful. To add this, you will need to edit the following 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:

<?php
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:

<?php
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() ?>

        <li>

            <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; ?>

        </li>

        <?php endforeach; ?>

add

<li>

            <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>

        </li>

Now, If you are going to search only by Category then you will face an error message like “You have to specify at least one search term”. To solve it you need to modify following file:

*
app/code/core/Mage/CatalogSearch/Model/Advanced.php

<?php
      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:

 <?php
      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'));
   
              }?>

Now you won’t face any problem in advanced search only by Category or any single attribute search.

Hope it Helps... Thanks......

Saturday, December 11

Change default Home page url to any page url in Magento

To change default index page of magento any cms page or any page like login page is quite easy .To do so you need to login to the admin panel then goto System -> Configuration , then click on web tab from the right side tab.Now click on Default Pages tab and change the Default web url as per your required Url.Here is one example where I have changed my Homepage url to Login page Url


Monday, December 6

A clean way to move Magento from Local to Server without edit any file (12 steps)

1.  Compress your local Magento folder in a zip file, and put the package in a safe place in your hard drive.

2.  Export Magento data base with phpmyadmin (make sure to check SQL and the “save as file” option) and save the data base in a safe place in your hard drive

3.  Upload the Magento zip package in your live server (root directory), and uncompress it (I use c-panel file manager).

4.  Once unzipped the package, make sure there is nothing in the cache directory (if you found some files delete them)

a.  var/cache /

b.  var/session/

5.  Delete this file: app/etc/local.xml (This run a new installation, that we start on step 10)
(Making sure that Magento connect will work)

6.  Download an original installation package of your Magento version, and copy this file:

a.  downloader/pearlib/clean

b.  downloader/pearlib/ pear

c.  downloader/pearlib/ peardev

d.  downloader/pearlib/ pecl


7.  Go to your live server Magento folder: downloader/pearlib/ and replace the files that you find, with files copied in step number 6 (you need to use on more time an ftp client)
(data base setup)

8.  Open your live server phpmyadmin and create a new data base for example magdb

9.  Import inside your new data base (for example magdb) the SQL data base that you have exported in step number 2
(Installation of Magento)

10.  Go to your domain using your favorite browser, and run a new installation of magento

11.  Connect it to the data base created on step number 8

12.  Choose your final data ex: admin patch, user and password, etc. And make sure to save the new Key encrypt
That’s all.
Note that all of your extensions are installed and operating, including Magento Connect
Possible problems divided by step

• Step 3: If you don’t’ have an unzipper tool on your hosting upload the uncompressed folder using an ftp client

• Step 9: if your data base is too big, try to upload it in phpmyadmin as a zip file

• Step 10: If you find any errors, make sure folder permissions are set to 755 and file permissions to 644. If your administration submenu pulldowns don’t work, make sure /js/index.php is 644.

• Step 11: If your Magento installation does not connect to the data base, make sure to use the data access of your live server data base, and make sure that the step number 4 is done

Thursday, December 2

Display Subcategory Listing in Parent Caategories

1. In cms select Static Pages
a. Set the Block Identifyer to for example “Sub Category Listing”
b. Set the Identifyer to “subcategory_listing”
c. In the content section add “{{block type="catalog/navigation" template="catalog/navigation/subcategory_listing.phtml"}}"

2. Now take this code and create a new file called for example “subcategory_listing.phtml” this file needs to live in the “catalog/navigation” directory


<?php $_categories=$this->getCurrentChildCategories(); ?>
<div class="listing-type-list catalog-listing">
    
<?php foreach ($_categories as $_category): ?>
    
<table width="100%" border="0" cellspacing="0" cellpadding="0">
            
<?php if($_category->getIsActive()): ?>
            
<tr>
                <
td width="30%">
                <
div class="listing-item">
                <
div class="cat-box-text">
                      <
h6><a href="<?php echo $_category->getURL() ?>"

  title="<?php echo $this->htmlEscape($_category->getName()) ?>"> 
<?php echo $this->htmlEscape($_category->getName()) ?></a></h6>
                        </
div>
                        <
div class="product-image">
                            <
a href="<?php echo $_category->getURL() ?>" 

 title="<?php echo $this->htmlEscape($_category->getName()) ?>">
                                <
img src="<?php echo $_category->getImageUrl() ?>"

 width="100" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" />
                            </
a>
                                
<?php /* echo "Find this item->" */ ?>
                        
</div>
                    </
div>
              
                </
td>
                <
td width="40%">
                    <
div class="listing-item">
                        <
div class="cat-box-text">
                        
<?php echo $_category->getDescription() ?>
                        
</div>
                    </
div>
                </
td>
            
<?php endif; ?>
            
</tr>
        </
table>
    
<?php endforeach; ?></div>



3. Now Goto Manage Categories. 
a. Pick a Sub Category Entry 
b. Set the display mode to “Static Block Only” 
c. From the CMS Block dropdown select the Static Page “Sub Category Listing” 
d. Set the is anchor to no

i have just set a site live you can see this in action http://www.shrinova.com

Wednesday, November 17

Delete test orders in Magento

If you try to delete orders in the backend, you will find out that you can only set the status to “cancelled” and the order is still there. There is not option in the admin to delete orders at the moment. You can simply copy and paste a MySQL query that will do the job for you…

set @increment_id='100000001';
select @order_id:=entity_id from prefix_sales_order_entity where increment_id=@increment_id;
delete from prefix_sales_order_entity where entity_id=@order_id or parent_id=@order_id;
delete from prefix_sales_order where increment_id=@increment_id;

Notice:

1. changing prefix_ for any database table prefix (if you use any);
2. changing 100000001 for the actual order number.

You can use another variant (After you have it executed, the test orders will not be in the database any more. Keep in mind that this will delete ALL orders, in the database. So, you should execute this queries immediately after launch. Some tables will be empties completely.)

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;

ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;

-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;

-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Checked in Magento ver. 1.4.

I think will work in other versions.

You can use “Delete Any Order in Magento” Extensions for Magento.

The YireoTM Delete-Any-Order module allows you to delete orders with any status (Cancelled, Completed, etcetera). By doing this, it deletes the following information:

* Order
* Order Comments
* Order Items
* Order Addresses
* Order Status History
* Order Tax
* Order Invoices
* Order Invoice Comments
* Order Shipments
* Order Shipment Comments
* Order Payments
* Order Payment Comments
* Order Creditmemos
* Order Creditmemo Comments
* Downloadable Items

Price of 20 Euro


Friday, November 12

Add a Image Slider Banner in Magento Home page

 We can Implement from Admin->CMS->Pages->Home Page
<!--Image Slider Start-->

 <div align="center">
<script type="text/javascript">

var image1=new Image()
image1.src="{{skin url=images/banner_1.jpg}}"
var image2=new Image()
image2.src="{{skin url=images/banner_2.jpg}}"
var image3=new Image()
image3.src="{{skin url=images/banner_3.jpg}}"

</script>
<a href="http://##">
<img src="{{skin url=images/banner_1.jpg}}" border="2" name="slide" width="890" height="277" /></a>
<script>

//variable that will increment through the images
var step=1
function slideit(){
//if browser does not support the image object, exit.
if (!document.images)
return
document.images.slide.src=eval("image"+step+".src")
if (step<3)
step++
else
step=1
//call function "slideit()" every 2.5 seconds
setTimeout("slideit()",5000)
}
slideit()

</script>

</div>
<!--Image Slider End-->

Friday, October 15

Magento How to Change the Favicon

1. Create your Favicon.
First create a roughly square image with your logo in it, then upload it here to create your favicon itself:
http://tools.dynamicdrive.com/favicon/
2. Find the path to your Favicon.
All you need to do is go to your home page, view source and look for two lines like this:
HTML:
  1. <link rel="icon" href="http://www.******.co.uk/skin/frontend/****/****/favicon.ico" type="image/x-icon" />
  2. <link rel="shortcut icon" href="http://www.****.co.uk/skin/frontend/****/****/favicon.ico" type="image/x-icon" />
You now know where your favicon is being stored on your server.
3. Upload your Icon
Fire up your favourite FTP client, connect to your server, browse to the path you go from above skin/frontend/****/****/
Now rename the favicon that is up there to favicon.ico.backup
Now upload your custom one.
4. Check it out
Just reload your page. Note you may need to clear cache for the new favicon to display properly.

Thursday, October 14

Replacing logo with swf format in Magento

Edit your header.phtml file and update the below code:


<div class="header-container">
   <div class="header">
       <?php if ($this->getIsHomePage()):?>
       <h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong>
<a href="<?php echo $this->getUrl('') ?>"
 <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="115" height="115" id="****" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="<?php echo $this->getSkinUrl('images/endless.swf')?>" />
<param name="quality" value="high" />
<param name="bgcolor" value="#EDE2C8" />
<embed src="<?php echo $this->getSkinUrl('images/endless.swf')?>" quality="high" bgcolor="#EDE2C8" width="250" height="154" name="****" align="left" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

<?php endif?>
</div></div>


Remove the Categories and Products through PHPMyAdmin

Truncate Magento Categories

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');
------------------------------------------------------------------------------------------------
Truncate Magento Products

TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

insert  into `catalog_product_link_type`(`link_type_id`,`code`) values (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
insert  into `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) values (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
insert  into `cataloginventory_stock`(`stock_id`,`stock_name`) values (1,'Default');


Ref: http://www.magentocommerce.com/boards/viewthread/20553/