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.

Liferay Popup’s

When developing a portlet in liferay sometimes there will be need to display content, page or even a portlet in popups. Liferay provides its inbuilt methods to have the facility of popups. In this article I will explain you the same and some other ways to use popups using Jquery and Ajax in liferay.

 Liferay Popup using Ajax + Alloy

In 6.1, Liferay uses pop-ups extensively. Here is the code you can simply put in your jsp to load a portlet or any other content asynchronously (Ajax) using Alloy. This will open an iFrame inside the alloy:

<aui:script>
               Liferay.provide(window,'showSiteManagement',function() {
                      var instance = this;
                      var url='<%= themeDisplay.getURLManageSiteMemberships().toString() %>';
                          Liferay.Util.openWindow(
                          {
                            cache: false,
                             dialog: {
                            align: Liferay.Util.Window.ALIGN_CENTER,
                             after: {
                            render: function(event) {
                            this.set('y', this.get('y') + 50);
                                     }
                                      },
                             width: 820
                           },
                           dialogIframe: {
                             id: 'siteManagementIframe',
                             uri: url
                                         },
                             title: 'Site Management',
                             uri: url
                             }
                             );
                             },
                             ['liferay-util-window']
               );
</aui:script>

I have used the “themeDisplay.getURLManageSiteMemberships().toString()” to get the URL to the portlet. However this below code can be used to render a JSP page:


<portlet:renderURL var="somePageURL" windowState="<%=LiferayWindowState.POP_UP.toString() %>">
               <portlet:param name="jspPage" value="/jsp/some/page.jsp"/>
               <portlet:param name="redirect" value="<%= currentURL %>"/>
</portlet:renderURL>
 

Using the popup without Alloy
Add the below code in your controller:

<portlet:renderURL var="somePageURL" windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">

<portlet:param name="jspPage" value="/jsp/some/page.jsp"/>

<portlet:param name="redirect" value="<%= currentURL %>"/>

</portlet:renderURL>

Add the below script in your jsp page

<script type="text/javascript">

function showPopup() {

AUI().use('aui-dialog', 'aui-io', 'event', 'event-custom', function(A) {

var dialog = new A.Dialog({

title: 'Popup Title',

centered: true,

draggable: true,

modal: true

}).plug(A.Plugin.IO, {uri: '<%= somePageURL %>'}).render();

dialog.show();

});

}
 

Liferay popup using Jquery

Follow the below steps to integrate jquery with liferay:
1. Add the following content into your jsp page  

 <portlet:resourceURL var="resourceURL">
 </portlet:resourceURL>
 <table>
 ...
 <input id="popup" type="button" value="Popup"/>
 <script type="text/javascript">
 var $dialog;
 function <portlet:namespace/>showDialog(html, status,request)
 {
 $dialog.dialog('open');
 $dialog.html(html)
 return false;
 }
 $(document).ready(function() {
 $dialog = $('<div></div>').dialog({
 autoOpen: false,
 title: 'Export Dialog'
 });
 $('#popup').click(function()
 {
 jQuery.ajax(
 {
 url : '<%=resourceURL%>',
 dataType : 'String',
 success : <portlet:namespace/>showDialog,
 data : '<portlet:namespace/>',
 type : 'post'
 }
 );
 }
 );
 });
 </script>  

2.Call serveResource on Backing Portlet using Spring MVC Controller

 @Controller
 public class PopupController {
 ......
 @ResourceMapping
 public String renderResource(@RequestParam(value = "action") String action,
 @RequestParam(value = "refresh", required = false) boolean refresh, ResourceRequest request) throws PortletException,
 IOException {
return "popupJspName";
}

3.Supporting xml files

A.portlet.xml

 <portlet>
 <portlet-name>PopupPortlet</portlet-name>
 <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
 <init-param>
 <name>contextConfigLocation</name>
 <value>/WEB-INF/context/popup-portlet.xml</value>
 </init-param>
</portlet> 

B. popup-portlet.xml

 <bean id="popupController"/>
<bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
 <property name="defaultHandler" ref="popupController"/>
      <property name="portletModeMap">
<map>
<entry key="view">
<ref bean="popupController"/>
</entry>
         </map>
    </property>
</bean>  

We are done….. Enjoy using popups with liferay. 🙂

How to get image height and width dynamically using PHP?

Hello friends,

In last week while performing my task I had a requirement to get image height and width dynamically with PHP programming. To satisfy that requirement I had searched the web and found the optimum way to do so, that I want to discuss here.

PHP provides an inbuilt function named getimagesize() to get the size of an image.

The getimagesize() function accepts one argument i.e. image path and returns an array with 7 elements.


array getimagesize (string $filepath)

The returning array consist dimensions of given image file along with the file type.

Index 0 and 1 indicates the width and height of the image respectively.

Index 2 is the constant indicating the type of the image.

Index 3 is a text string with the height=”yyyy” width=”xxxx” string.

The last argument mime is the correspondent MIME type of an image.

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