Friday 26 June 2015

How to get top search terms in magento - Magento.

To get Top Search Terms on your Magento Store Programmatically.Use the Following Condition.

<?php 
$topsearchterms = Mage::getModel('catalogsearch/query')->getCollection()
->setPopularQueryFilter()
->setPageSize($limit); // if you want only Top 5 Search Terms just replace $limit in the above line with that number like in this case 5.
?>

<?php foreach($topsearchterms as $topsearchterm) { ?>

<?php $topsearchterm->getName(); // if you want only the search terms name use this code. ?>
<a href="<?php echo Mage::getBaseUrl().'catalogsearch/result/?q='.$topsearchterm->getName(); ?>"><?php echo $topsearchterm->getName(); ?></a><?php //if you want this top quries as the clickable use this code. ?>
<?php } ?>

Wednesday 17 June 2015

Remove Customer Account Navigation Links using Layout XML - Magento

Magento gives big and expansive library of features and some of us we don't need all features.If we keep all the features provided by magento then it could create a frustrating experience for site users as some features might not do anything.One of this type feature is customer account navigation menu



I will show you how to remove some of these links by implementing a layout XML method to remove them via a class rewrite. As an example of a link we're going to remove, let's take a look at the Recurring Profiles link in that list.

That link is added with this layout XML declaration in app/design/frontend/base/default/layout/sales/recurring_profile.xml:

<customer_account>
<reference name="customer_account_navigation" >
<action method="addLink" translate="label">
<name>recurring_profiles</name>
<path>sales/recurring_profile/</path>
<label>Recurring Profiles</label>
</action>
</reference>
</customer_account>

So removing or commenting the above code makes us to get rid of the links in the customer navigation links but in how many files you do same thing (commenting) and it will many xml files to do so. and you need to copy the xml file into the your theme directory and comment.

So best approach is to make a small module and remove all this links from one xml file. to do so follow the following steps

Step 1) Create module's xml file 'Prasan_CustomerNavigationLinks.xml' at app/etc/modules/ with following code in it.

<?xml version="1.0"?>
<config>
<modules>
<Prasan_CustomerNavigationLinks>
<active>true</active>
<codePool>local</codePool>
</Prasan_CustomerNavigationLinks>
</modules>
</config>

Step 2) Create module's config.xml file at app/code/local/Prasan/CustomerNavigationLinks/etc/ with the following code in it

<?xml version="1.0"?>
<config>
<modules>
<Prasan_CustomerNavigationLinks>
<version>0.0.1</version>
</Prasan_CustomerNavigationLinks>
</modules>
<frontend>
<layout>
<updates>
<customernavigationlinks>
  <file>prasan_customernavigationlinks.xml</file>
</customernavigationlinks>
</updates>
</layout>
</frontend>
<global>
<blocks>
<customer>
<rewrite>
<account_navigation>Prasan_CustomerNavigationLinks_Block_Account_Navigation</account_navigation>
</rewrite>
</customer>
</blocks>
</global>
</config>

Step 3) Now create module's block file 'Navigation.php' at app/code/local/Prasan/CustomerNavigationLinks/Block/Account/ with the following code in it

<?php
class Prasan_CustomerNavigationLinks_Block_Account_Navigation extends Mage_Customer_Block_Account_Navigation
{
/**
* Description : Unset the Link by name in the customer Navigation
* @author Author Name
* @param Name of the link to be removed
* @return link is removed.
*/
public function removeLinkByName($name)
{
unset($this->_links[$name]);
return $this;
}
}

Step 4) Now create prasan_customernavigationlinks.xml file at app/design/frontend/base/default/layout/ with the following content in it

<?xml version="1.0"?>
<layout>
<!-- Removes Customer Navigation Links from My Account -->
<customer_account>
<reference name="customer_account_navigation">
<action method="removeLinkByName">
<name>account</name> <!-- Removes Account Dashboard Link -->
</action>
<action method="removeLinkByName">
<name>account_edit</name> <!-- Removes Account Information Link -->
</action>
<action method="removeLinkByName">
<name>address_book</name> <!-- Removes Address Book Link -->
</action>
<action method="removeLinkByName">
<name>orders</name> <!-- Removes My Orders Link -->
</action>
<action method="removeLinkByName">
<name>billing_agreements</name> <!-- Removes Billing Aggrements Link -->
</action>
<action method="removeLinkByName">
<name>recurring_profiles</name> <!-- Removes Recurring Profiles Link -->
</action>
<action method="removeLinkByName">
<name>reviews</name> <!-- Removes My Product Reivews Link -->
</action>
<action method="removeLinkByName">
<name>tags</name> <!-- Removes My Tags Link -->
</action>
<action method="removeLinkByName">
<name>wishlist</name> <!-- Removes My Wishlist Link -->
</action>
<action method="removeLinkByName">
<name>OAuth Customer Tokens</name> <!-- Removes My Applications Link -->
</action>
<action method="removeLinkByName">
<name>newsletter</name> <!-- Removes Newsletter Subscriptions Link -->
</action>
<action method="removeLinkByName">
<name>downloadable_products</name> <!-- Removes My Downloadable Products Link -->
</action>
</reference>
</customer_account>
</layout>

Note: Add only that links which you want to remove from the customer account navigation links and then clear cache.link will be removed

Monday 15 June 2015

Magento Upgrade from 1.7 to 1.9

Upgrade Roadmap for CE 1.9.0.1 from 1.7

  1. Take a backup of current database and current 1.7 code. place maintenance.flag file inside 1.7 code folder to put website offline.
  2. Download latest magento from the http://www.magentocommerce.com/download
  3. Remove all folders and files from your 1.7 code except maintenance.flag (but you should have backup somewhere) and place all folders and files from the 1.9.
  4. Now from your 1.7 merge your following custom folders into the 1.9
    • Community app/code/community
    • Local app/code/local
    • Media
    • your theme or package (app/design/frontend/default/<your theme> or app/design/frontend/<your package>)
    • custom folders from Skin (both for adminhtml and frontend).
    • copy your custom xml files from app/etc/modules/ to current app/etc/modules/
    • any custom admin theme folder from adminhtml/default/yourtheme.
    • copy your custom folders from adminhtml/default/default/ (1.7) to adminhtml/default/default/ (1.9).
    • custom js files if any from app/js/.
  5. Now go to app/etc/local.xml.Edit database details their.put your database username and password and database name.
  6. Remove maintenance.flag file and check the site in the browser. it is done.