Friday, 20 November 2015

Extension PHP Intl is missing during magento 2 installation - Magento 2

As we all know Magento 2 is out and every one is trying to install and learn.When i was installing the magento 2 on my local i got the error of PHP Extension intl missing while in the PHP extension check during the magento 2 installation

so solution to this error is look for the php.ini file in the local open that file and find the below line from that file

;extension=php_intl.dll

and remove starting semicolon and save the file and then restart your xampp or wampp server and refresh the installation page.This error will be gone.

screen shot of this error is as follows:-



Monday, 9 November 2015

How to Remove Discount Coupon code form from the Shopping cart page in Magento - Magento

To Remove the Discount Coupon form from Magento Shopping Cart Page follow the following steps

Add the following code in your theme's local.xml

<?xml version="1.0" encoding="UTF-8" ?>
<layout>
<checkout_cart_index>
<reference name="content">
<remove name="checkout.cart.coupon"/>
</reference>
</checkout_cart_index>
</layout>


Please Note clear the cache and check

Shopping cart quantity not able to update after magento upgrade - Magento

After upgrading your magento to 1.8.1.0, there has been problem with update quantity of shopping cart in community version 1.8.1.0. For example just change quantity from 1 to 2 and hit update, the quantity did not change.

If you are facing this issue that means you are using the custom template file for the /checkout/cart.phtml in yout theme.with the recent upgrade magento has been introduced in the base version of the magento since you are using the custom template this changes won't be reflected in your page.

The better approach is to add the updated lines to your own cart.phtml file.

In your theme directory

In your /app/design/frontend/<theme>/default/template/checkout/cart.phtml file or /app/design/frontend/default/<theme>/template/checkout/cart.phtml file

Just place on line 50 just after
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
paste the below code

<?php echo $this->getBlockHtml('formkey'); ?>


it will work fine now.

Sunday, 8 November 2015

How to check whether user is logged-in or not in magento - Magento

Some times we want to check whether user is already logged in or not in magento for this we can use the following code


<?php
    if(!Mage::getSingleton('customer/session')->isLoggedIn()){
        //not logged in
    }else{
        // logged in
    }
?>

Tuesday, 3 November 2015

Adding A Suffix or Prefix to Title Tag in Magento - Magento

SEO best practices dictate that you should include your website name at the end of your title tag. This is really very important for brands who have retailers competing for their keywords and because it also helps with branding.

You might see a title tag like this:

Keywords | YourWebsiteName.com
or
Keywords - YourWebsiteName.com

To get set up your store title tag suffix or prefix go to System > Configuration > Design > Html Head their you can see "Title Suffix" you can give your title "- YourWebsiteName.com" or "| YourWebsiteName.com" here which will add in all the page at last like

for eg:-

Keywords - YourWebsiteName.com
or
Keywords | YourWebsiteName.com

If you add "Title Prefix" as "- YourWebsiteName.com" or "| YourWebsiteName.com" then you will be seeing the prefix which you have been added at the start of the keywords in all pages

for eg:-

YourWebsiteName.com - Keywords
    or
YourWebsiteName.com | Keywords

How get the current loggedin admin user details in magento - Magento

Some times we want to get the current loggedin admin user details to process the data.so in magento we can get currently logged in admin user details.we can get currently logged in admin user id, firstname, lastname , username, email, by using the following code

<?php
$admin_user = Mage::getSingleton('admin/session')->getUser();
echo $admin_user->getUserId();
echo $admin_user->getFirstname();
echo $admin_user->getlastname();
echo $admin_user->getEmail();
echo $admin_user->getUsername();
?>

Saturday, 31 October 2015

How to get Most Viewed Products of Current Product Category in Magento - Magento

Get most viewed products of current product categorywise in magento

$storeId = Mage::app()->getStore()->getId();
$category_ids = $_product->getCategoryIds();

$products = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('category_ids',array('finset'=>$category_ids))
    ->setStoreId($storeId)
    ->addStoreFilter($storeId)
    ->addViewsCount()

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);

foreach($products as $product){
    echo $product->getName();
    echo $product->getPrice();
}

Please make sure your passwords match in magento – Magento

From Magento 1.9.1.0 version the users are getting errors at the checkout or from the 'Create an Account link'. When user register,user keep getting the password mistmatch error even though the password is correctly entered.

Form the Magento 1.9.1.0 the validate fuction in the Mage_Customer_Model_Customer class has changed following line.

before 1.9.1.0

$confirmation = $this->getPasswordConfirmation();


After (or from) 1.9.1.0

$confirmation = $this->getConfirmation();


So i was having the login popup extension where in the create function it sets the confirmpassword as follows

$customer->setConfirmation($this->getRequest()->getPost('confirmation'));


and before magento 1.9.1.0 the validate function was taking this setConfirmation value in the validate function as $this->getConfirmation(); but due to change in the validate function to $this->getPasswordConfirmation(); some users are getting the error as “Please make sure your passwords match”.

Due to the method change in core code on Magento 1.9.1.0, if any of the 3rd party extension like 'onepagecheckout' or 'quicklogin' which was using this method, will not work as expected.

To ensure that extensions work as expected with Magento 1.9.1.0, we need to check the version in code & accordingly call the required method –

So i had changed following code in my extension file as follows

$info = Mage::getVersionInfo();
$version = "{$info['major']}.{$info['minor']}.{$info['revision']}.{$info['patch']}";

if($version >= '1.9.1.0'){
$customer->setPasswordConfirmation($this->getRequest()->getPost('confirmation')); // just check the name of confirm password field in the registration form accordlingly add the name in the get Post
} else {
$customer->setConfirmation($this->getRequest()->getPost('confirmation')); // just check the name of confirm password field in the registration form accordlingly add the name in the get Post
}

List all or get all enabled or disabled products in magento

Lets look at query to get disabled product or enabled products collection in magento

to get list of enabled products use following query

$productsCollection = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToFilter('status', 1)


to get list of disabled products use following query

$productsCollection = Mage::getModel('catalog/product')->getCollection()
                    ->addAttributeToFilter('status', 2)

Friday, 30 October 2015

How to override createPost Action in Account Controller in Magento

Here we are going to override createpost function in magento

Lets create a small module for overriding the account controller

Step 1:- Create YourPackageName_Customer.xml file at app/etc/

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


Step 2:- Create module's config.xml file at app/code/local/YourPackageName/Customer/etc/

Let's take a look at the code that goes into the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <YourPackageName_Customer>
            <version>0.0.1</version>
        </YourPackageName_Customer>
    </modules>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <yourpackagename_customer before="Mage_Customer">YourPackageName_Customer</yourpackagename_customer>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>


In the config node its child has to define whether we are changing the frontend or admin file and we define router node that will override core customer module with its arguments. In the bottom node goes the current module frontend name (<yourpackagename_customer in my example) with the "before" or "after" attribute name with the value of which module is being overriden (Mage_Customer) and our own module name inside the tags (YourPackageName_Customer).

Step 3:- Create AccountController.php controller file at app/code/local/YourPackageName/Customer/controllers/AccountController.php

If you noticed, there are no strict files defined. With this we have defined only the path that will look for the controller files by their names. So if we would like to override app/code/core/Mage/Customer/controllers/AccountController.php a file with the same name will have to be created (app/code/local/YourPackageName/Customer/controllers/AccountController.php).

Class definition inside our new file:

<?php
    include_once("Mage/Customer/controllers/AccountController.php");
    class YourPackageName_Customer_AccountController extends Mage_Customer_AccountController
    {
        public function createPostAction()
        {
            // echo "done"; exit;
        }
    }
?>

How to override create new Product Controller in Magento Admin Panel - Magento

Here we are going to override create new product function in magento during admin product creation

Lets create a small module for overriding the product controller

Step 1:- Create YourPackageName_Adminhtml.xml file at app/etc/

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

Step 2:- Create module's config.xml file at app/code/local/YourPackageName/Adminhtml/etc/

Let's take a look at the code that goes into the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <YourPackageName_Adminhtml>
            <version>0.0.1</version>
        </YourPackageName_Adminhtml>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <yourpackagename_adminhtml before="Mage_Adminhtml">YourPackageName_Adminhtml</yourpackagename_adminhtml>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

In the config node its child has to define whether we are changing the frontend or admin file and we define router node that will override core adminhtml module with its arguments. In the bottom node goes the current module frontend name (<yourpackagename_adminhtml in my example) with the "before" or "after" attribute name with the value of which module is being overriden (Mage_Adminhtml) and our own module name inside the tags (YourPackageName_Adminhtml).

Step 3:- Create ProductController.php controller file at app/code/local/YourPackageName/Adminhtml/controllers/Catalog/ProductController.php

If you noticed, there are no strict files defined. With this we have defined only the path that will look for the controller files by their names. So if we would like to override app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php a file with the same name will have to be created (app/code/local/YourPackageName/Adminhtml/controllers/Catalog/ProductController.php).

Class definition inside our new file:

<?php
    include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
    class YourPackageName_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
    {
        public function newAction()
        {
            // echo "done"; exit;
        }
    }
?>

Tuesday, 20 October 2015

Magento - dbModel read resource does not implement Zend_Db_Adapter_Abstract

We came across the following error in magento after git pull of the code from the git and later when i refreshed the site i got the error and when i saw the reports file for error i got this error "dbModel read resource does not implement Zend_Db_Adapter_Abstract"

the solution for this to get rid of this error is to clear the cache and delete the cache folder from the var/ .

Done refresh the site your error has gone

How to override Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select block in Magento

Sometimes you need to change the behavior of Magento core functionality and add our custom code and it's a bad habit and bad programming if core files are modified and it's not recommended at all.Magento brought in an excellent way how to override/overwrite those files for adding our custom code.

Overriding Magento Blocks

Here we will see how to change a basic block of Magento. Suppose that in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select class we need to add some changes have to be done. What we would like to have here is to add our own file that will extend the original file with all of its methods. All the job that has to be done is to add the code below in the current module's config.xml:

Step 1:- Start rewriting the Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select block in config.xml of your custom module

<config>
<global>
<blocks>
<adminhtml>
            <rewrite>
                <catalog_product_edit_tab_options_type_select>
                    [YourPackageName]_[YourModuleName]_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select
                </catalog_product_edit_tab_options_type_select>
            </rewrite>
        </adminhtml>
</blocks>
</global>
</config>

Step 2:- create the file and add your code modification in this class of the respective method from the core block class.

As the class name says, a file has to be created in app/code/local/YourPackageName/YourModuleName/Block/Adminhtml/Catalog/Product/Edit/Tab/Options/Type/Select.php and a class has to be defined:

class [YourPackageName]_[YourModuleName]_Block_Adminhtml_Catalog_Product_Edit_Tab_Options_Type_Select extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Type_Select{
// your code
}

How to solve Jquery and Prototype conflicts in Magento.

Magento uses Prototype JS.Most of us prefer working with jQuery because of many reasons.So when we use Jquery in magento we get the error. this error is basically due to the conflict between prototype and jquery libraries.

When we call a jQuery with $ we will notice a conflict because Prototype.js also uses $ variable for itself whereas jQuery tries to register the variable causing conflict.So, if you have to use jQuery within a Magento store which rely heavily on Prototype.js just put your jQuery in compatibility mode.

The default call for jQuery function goes like this

$(document).ready(function(){
$("#someid").click(function(){

});
});

The above function will not work within a Magento store due to conflict with Prototype.js. You need to solve this conflict.

Instead follow the steps

1) Create one js file called noConflict.js with the following content.

var $j = $.noConflict();

and include this file after your jquery.js in the magento

2) And you can use this jquery wih the following code

<script type="text/javascript">
    $j(document).ready(function(){
        $j("#someid").click(function(){

});  
    });
</script>

Since we are using jQuery in compatibility mode it’s wiser not to call $ variable instead make a call to $j which is reference of jQuery.noConflict();. Simple isn’t it? Keep in mind that call to jQuery should be after the call to Prototype.

Friday, 16 October 2015

How to change magento default admin url – Magento

To protect your magento website backend against hackers we recommend you to change the default url of the magento admin.It is easy to change the admin url from default http://www.yourdomainname.com/admin or http://www.yourdomainname.com/index.php/admin to yourcustom admin url

In the following steps we are going to see how to have custom admin url name of our magento backend

Follow these steps to change the admin URL/path.

Step 1 – Change Path

Open the local.xml from the app/etc/ directory and locate the following content

<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>

Now replace admin from <frontName><![CDATA[admin]]></frontName> with your new admin url key.This should be something hard to guess,then save the file.I assume you has changed to <frontName><![CDATA[yournewadminpath]]></frontName>.

Step 2 – Refresh Cache

Now Refresh the cache of the site from the backend or you can mannually delete the content of the var/cache dir from your ftp.

Step 3 – Complete

You have done now.you can check by visiting http://www.yourdomainname.com/yournewadminpath (yournewadminpath is the name of urlkey which you gave on the step 1).

if you try http://www.yourdomainname.com/admin you will get 404 Page not found.

Note: Do NOT use the Magento Backend in the Magento Admin Panel to change the admin URL, as this is known to cause problems.

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.