How to check Magento module is installed or not?

Hello friends,

In last month I was working on a Magento module which works in the relationship of Magento Call for Price and Magento Partial Payment modules. So before executing the code of developing the module I had to check that Magento Call for Price and Magento Partial Payment modules were installed or not.

To find a code to check whether any Magento module is installed or not, I found a lot of different ways but here I will discuss the one which I had used.

$modules = (array)Mage::getConfig()->getNode('modules')->children();
if (isset($modules['Indies_Callforprice'])) {
    echo 'Indies Call for Price module is installed.';
    if ($modules['Indies_Callforprice']->is('active')) {
        echo 'Indies Call for Price module is active.';
    } else {
        echo 'Indies Call for Price module is not active.';
    }
} else {
    echo 'Indies Call for Price module is not installed.';
}

The above code will check that the specified module has been installed or not and it is active or not. In the code above I have checked whether the Indies_Callforprice module is installed and active or not. Now to use this code you just need to change the name of module, so instead of Indies_Callforprice you need to write your own module name.

Hope this will help you.

Thanks.

How to upgrade magento module

Hello  friends,

Today we will discuss here about  how to upgrade the sql file in magento. This is very useful technique used in the magento based developed store. The requirement of this technique is mandatory when there are any changes regarding the content included in your sql file . The sql file in magento runs only once so this technique help us to run sql file multiple times due to any changes is necessary in sql file.

There are only two simple steps to upgrade the magento sql file listed as below:-

1) You have to make a new sql file under the app –>code –>local –>namespace –>modulename –>sql  directory . Note one thing that this new sql file will include only  new feature that you want to add like any attribute or table not the same one that you have added previously .

There are some naming standards of the new created sql file. Suppose if your existing sql file name is mysql4-install-0.1.0.php then you have to keep the name of newly generated file as mysql4-upgrade-0.1.0-0.1.1.php and same thing will repeated in same manner if you want to create any more upgrade file.

2) In the very next step you will have to write the latest version of module in the config.xml file of your module.


<config>

  <modules>

   <module_name>

        <version> put your latest version number </version>

   </module_name>

  </modules>

</config>

In this file you have to put your latest module version number. So in this case if I will create only one upgrade file than I will write 0.1.1 between version tag and if there are two upgrade sql files than 0.1.2 and so on.

After performing this two steps you have to just reload your page in your browser and your changes will be reflected in your site.That’s it.

Hope this will help you….

Solved: Fatal error on reset password page after upgrade to Magento CE 1.7

Hello friends,

In last month, I had a task to upgrade one Magento site to the latest version 1.7.0.2.

I upgraded the site successfully to the latest version of Magento. But while testing of that site we found one critical error related to reset password, which I want to discuss here:

In login page on click of forgot password link, Magento asks customer’s email address to send reset password link to their email address.

Above functionalities were working fine.

But in the reset password mail while clicking on reset password link, the page gave the following error:

PHP Fatal error: Call to a member function setCustomerId() on a non-object in app/code/core/Mage/Customer/controllers/AccountController.php on line 587

I was just shocked, and tried hard to find the cause and the solution of that problem. For that I had searched the web, and at last found the cause and solution of the problem.

The error was occurred because of incompatible customer.xml file in our custom theme. Magento did many useful changes in customer.xml file in latest version 1.7.0.2.

Now the solution of above error is very simple. Just remove the customer.xml file used by your theme from /app/design/frontend/<your_package_name>/<your_theme_name>/layout/. By doing this Magento will use the customer.xml file from the base/default theme.

If you have did some useful changes in customer.xml file according to your theme and not able to remove that file then update your customer.xml file by putting the under given section in it.

<customer_account_resetpassword translate="label">
    <label>Reset a Password</label>
    <remove name="right"/>
    <remove name="left"/>

    <reference name="head">
        <action method="setTitle" translate="title" module="customer">
            <title>Reset a Password</title>
        </action>
    </reference>
    <reference name="root">
        <action method="setTemplate">
            <template>page/1column.phtml</template>
        </action>
        <action method="setHeaderTitle" translate="title" module="customer">
            <title>Reset a Password</title>
        </action>
    </reference>
    <reference name="content">
        <block type="customer/account_resetpassword" name="resetPassword" template="customer/form/resetforgottenpassword.phtml"/>
    </reference>
</customer_account_resetpassword>

That’s it.

Now see the result, the error will go away.

Also refer the under given link to get knowledge about some nasty issues which can occur after upgrading magento to 1.7.

https://indiestechtips.wordpress.com/2012/08/18/problems-with-magento-while-upgrading-to-1-7/

Hope this will help you.

Thanks.

Add custom attribute in magento admin product grid

We all know that magento admin product grid display some attribute of the product. Some time we require displaying the custom attribute value into that grid. So I post this blog to fulfill that requirement.

Step: 1: Create the attribute for the product and give the proper type.

Example: Crates attribute ‘newstatus’

 

Step: 2: Crate directory structure.

For that first we create the following directory structure in our magento.


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product

 

Step: 3: Overwrite the default product grid.

For adding new attribute to grid, overwrite the default grid file. For that we copy the file “Grid.php” from the following location


[Magento]\app\code\core\Mage\Adminhtml\Block\Catalog\Product

And paste this file at our new created location. So path become like this:


[Magento]\app\code\local\Mage\Adminhtml\Block\Catalog\Product\Grid.php

 

Step: 4­: Add Attribute to grid.

First find out the following function.


protected function _prepareColumns()

Now add the code for displaying the attribute to grid. Here I insert the attribute ‘newstatus’ created at step-1.


$this->addColumn('newstatus',

array(

'header'=> Mage::helper('catalog')->__('Company Status'),

'width' => '80px',

'index' => 'newstatus',

'type'  => ‘text’,

));

Step: 5­: Add Attribute to filter grid.

Find the following function.


protected function _prepareCollection()

 

Add the fields in that code for filtration.


->addAttributeToSelect('newstatus')

 

Refresh the cache memory and reindexing the data. Now this attributes display into admin product grid.

I hope this will help you.

Thank you.

Solving 404 error after upgrade magento to 1.7

Hello friends,

By doing many useful changes magento is improving a lot in the current competitive market. As a part of that Magento released the latest stable community version 1.7.0.2 on 5th July 2012.

Now it’s time for magento store owners to upgrade their store to latest version to get the maximum advantage of new functionalities.

To upgrade the magento store you can follow the steps given in the below link.

https://indiestechtips.wordpress.com/2012/05/19/magento-upgrade/

Now let’s come to the main topic. Just before a month I had a task to upgrade magento to 1.7. To do that task I followed the proper steps. But after upgrading I opened my site and it was giving “404 Error” on each page of site.

At that time I was surprised and confused about what happened with my site.

Then to solve that problem I searched the web and found the cause of problem and solution of it that I have discussed below.

Many times while doing any operation with magento connect manager such a 404 error encounters and our site get stopped working.

The cause of that problem is incorrect folder permission.

To solve that problem just download the magento-cleanup.php file from here, put it in your magento root folder and execute it.

Once you executed it you can see the list of messages that magento cleanup has reset the folder permission.

And if you have “maintenance.flag” file in your magento root folder then delete it.

That’s it.

Now open your site and see the result.

Also refer the under given link to get knowledge about some nasty issues which can occur after upgrading magento to 1.7.

https://indiestechtips.wordpress.com/2012/08/18/problems-with-magento-while-upgrading-to-1-7/

Hope this will help you.

Thanks.

Configure Magento Multistore with parked domain

The Magento script allows you to setup multiple stores using different domains which you would have to add as parked for your account. To setup Magento Multistore with parked domains follow this steps:

Note: This article assumes that you have already added a domain as parked for your account.

1) Login the Magento administration area

2) Navigate to “Catalog” -> “Manage Categories”

3) Click the “Add root category” button, which could be found on the left.

mage-root-cat

4) On the right side for “Name” enter your parked domain. For example : example.com. For “Is active” and “Is Anchor” select “yes” from the dropdown menu.

5) Click the “Save Category” button.

6) Now navigate to “System” -> “Manage Stores”

7) Click the “Create website” button.

8) For “Name” use example.com (in your case your parked domain). For code use example (or one by your choice). It is important to remember these settings as you will need them later.

mage-new-website

9) Save the website.

10) Now click on the “Create Store” button.

11) For website choose your example.com (your parked domain) from the dropdown menu. For “Name” you may enter “Example”. For “Root Category” select your parked domain again from the dropdown menu. Hit the “Save” button.

mage-new-store1

Once saved, click the “Create Store View” button.

12) For the “Store” select “Main Store” from the dropdown menu. For “Name” enter “English”. For the code you may use one by your choice. For “Status” select “Enabled”.

13) Save the “Store View”.

14) Navigate to “System” -> Configuration

15) Change “Current Configuration Scope” from “Default Configu” to example.com (or your parked domain).

16) From the left side menu select “Web”

17) For the “Secure” and “Unsecure” sections remove the mark for “Use Default” box. It could be found next to “Base URL”. Now enter the URL for your magento store: http://www.example.com.

mage-base-url

(you should change that with your actual URL)

18) Click the “Save Config” button.

19) Still under “System -> Configuration” change the “Current Configuration Scope” to “Default Config”.

20) Select “Web” from the left sidebar under the General section.

21) For “URL Options -> Auto-redirect to Base URL” set to “No”.

mage-url-redirect

22) Click the “Save Config” button.

23) Now using a text editor open the .htaccess file of your Magento script. Add the following lines in the end of the file:

SetEnvIf Host www\. example\.com MAGE_RUN_CODE=YOUR_CODE_HERE
SetEnvIf Host www\. example \.com MAGE_RUN_TYPE=website
SetEnvIf Host ^ example \.com MAGE_RUN_CODE=YOUR_CODE _HERE
SetEnvIf Host ^ example \.com MAGE_RUN_TYPE=website

You should change:
“example \.com” with your parked domain.

YOUR_CODE_HERE – with the actual code which you have used upon creating the store.

Done ! 🙂
Hope this will help you.
Thanks.

Magento Admin Custom Module Common Problems

Hello friends,

Custom development in any technology is continuous process. The common reason for custom development is frequently changing requirements.

By applying same rule in Magento, developers are developing more and more custom modules. And some of those modules are related to admin functionality.

Just before a week I was developing a magento custom module in which 60% of functionalities were related to admin. While developing those admin related functionalities I faced some common problems.

So here I want to discuss those problems and its solutions.

Problem 1: In my module I have successfully created admin grid. Where add and edit functionalities were working fine. But while editing an item, there was no DELETE button in the form. I surprised, checked my code but didn’t get an idea for that problem. So I searched the web and found the under given solution.

Solution 1: The problem is in Edit.php block, I put

parent::__construct();

at the first line of

 __construct()

method.

But it should be after the

$this->_controller

line.

I did that change and my problem get solved.

Problem 2: In my module, an admin form has facility to upload the file. There I was able to add the item and upload the file successfully. Whenever I edit the item a very small thumbnail image of the uploaded file along with the browse button and delete option was displaying. Then I tick marked the delete option and click on “Save and Continue” button and it gave me the under given error.


Warning: preg_match() expects parameter 2 to be string, array given  in /lib/Varien/Data/Form/Element/Image.php on line 56

Solution 2: Above error occurred, just because there wasn’t any code in custom module’s controller to delete the uploaded file.

So to solve the problem I did the changes in the /app/code/local/Company/Modulename/controllers/Adminhtml/ModulenameController.php file.

Where I looked for the code block like:

if(isset($_FILES['image_file']['name']) && $_FILES['image_file']['name'] != '')

And added the under given else condition block right after the above if condition block.

elseif (isset($data['image_file']['delete']) && $data['image_file']['delete'] == 1) {
    $path = Mage::getBaseDir('media') . '/';
    if(file_exists($path . $data['image_file']['value'])) {
        unlink($path . $data['image_file']['value']);
    }
    $data['image_file'] = '';
} elseif (isset($_POST['image_file']['value'])) {
    $data['image_file'] = $_POST['image_file']['value'];
} else {
    $data['image_file'] = '';
}

And the problem got solved.

That’s it.

Hope this will help you.

Thanks.