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

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.

Pass PHP array as argument to JavaScript function

We all know that, we widely use JavaScript in our PHP page to perform some task. Those tasks could be either any small calculation or anything else. We know that we use array in PHP for our tasks. Some time it’s a requirement to use PHP array into JavaScript function. So I write this blog to fulfill that requirement.

There are two ways to pass the PHP array to JavaScript function as arguments. I have explained both of them here.

Method 1: USE JSON_ENCODE

First method is to convert the PHP array into JSON_ENCODE so that function that receives that array use as a JavaScript array. Complete example is given as follows:

<script type="text/javascript">
function displayarrayelement(demoarray)
{
	for(i=0;i< demoarray.length;i++) 
	{
alert(demoarray [i]); 
}
}
</script>
<?php
	$newarray = array();
	For($i = 10; $i<100; $i=$i+10)
	{
		$newarray [] = $i;
	}
?>
<a onclick="displayarrayelement(<?php echo json_encode($newarray) ?>);"> Array in JavaScript </a>

Method 2: Manually make PHP array like JavaScript array (use implode and split)

In Second method, we make the PHP array format like the JavaScript array manually. So the function direct use that array. Complete example is given as follows:

<script type="text/javascript">
function displayarrayelement(demoarray)
{
	demoarray = demoarray.split(",");
	for(var i=0;i<demoarray.length;i++) 
	{
		alert(demoarray [i]); 
	}
}
</script>
<?php
	$newarray = array('a','b','c');
	$mov_str = implode(",", $newarray);
?>
<a href="#" onclick="displayarrayelement('<?php echo $mov_str ?>');"> Array in JavaScript </a>

Hope this will help you as it did to me.
Thanks.

Sign In with LinkedIn and Twitter on Your Website

LinkedIn and Twitter have become large in the social network world and both networks offering oAuth support. We developed a system to login with Twitter and LinkedIn. Nowadays web users not interested to filling the big registration forms. This script helps you to avoid registration forms, It’s is very useful and simple to integrate.

1) Sign In With Twitter

Some @Anywhere functionality doesn’t require the user to login to Twitter or authorize your site for access When user login and authorization is required, @Anywhere handles all of that for you out of the box.

The “Connect with Twitter” button provides a method for users to authenticate securely with Twitter, yielding your application with an access token for use in API calls.

Adding “Connect with Twitter” buttons to your application is easy: simply call T passing in a selector indicating where you want the button to appear, and call the connectButton method.

For example, the following will place a “Connect with Twitter” button into the element with an id of “login”:

<!DOCTYPE HTML>
<html>
      <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>Anywhere Sample</title>
        <script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script>
	</head>
<body>
<span id="login"></span>
    <script type="text/javascript">  

      twttr.anywhere(function (T) {
        T("#login").connectButton();
      });    

    </script>
      </body>
</html>

@Anywhere provides an authComplete and signOut event that can be used to determine whether or not users of your web site or web application have logged in to Twitter and authorized your application for access.

Using the “Connect with Twitter” button it is possible to bind listeners for both the authComplete and signOut events via an object literal passed to the connectButton method. Listeners for the authComplete are passed the logged in user as a single argument.

<script type="text/javascript"> 
      twttr.anywhere(function (T) {    
        T.bind("authComplete", function (e, user) {
          // triggered when auth completed successfully
        });    

        T.bind("signOut", function (e) {
          // triggered when user logs out
        });    
      });     
</script>

For further information :- https://dev.twitter.com/docs/anywhere/welcome#login-signup

2) Sign In With LinkedIn

The LinkedIn JavaScript API makes it incredibly easy to let you customers authenticate using their LinkedIn account. You can then use that information to register them for your own site, identify them in a blog comment, or otherwise use this to streamline their experience. This provides you with increased registrations with minimal work.

The most important piece of data for you to capture and store is the LinkedIn member id. This is an application-specific unique identifier for every member. With this token, you can easily retrieve profile information about any of your users who have authenticated using Sign In with LinkedIn.

An alternative approach is using the JavaScript API to directly fetch the person’s information. You can then pass that back using either a web form, like above, or an AJAX call.

Place the following in your :

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: YOUR_API_KEY_GOES_HERE
  authorize: true
onLoad: onLoadLinkedIn

function onLinkedInLoad() 
{
   IN.UI.Authorize().params({"scope":["r_basicprofile", "r_emailaddress"]}).place();
   IN.Event.on(IN, "auth", loadFields);
}
function loadFields() 
{
   IN.API.Profile("me")
   .fields(["id,firstName,lastName,positions,emailAddress"])
   .result(function(me){
     profile = me.values[0];
     position = profile.positions.values[0];
     console.log(profile);
    })
}
</script>

And the following in your :

<script type="IN/Login" data-onAuth="onLinkedInAuth"></script>

This generates a Sign In with LinkedIn button and triggers the onLinkedInAuth() function upon completion. That function makes an IN.API.Profile() API call for the current viewer and provides you with the member id in the callback function. You can then use the AJAX framework of your choice, such as Dojo, YUI, or jQuery, to pass that value back to your server.
For further information :- http://developer.linkedin.com/documents/sign-linkedin

Done !🙂
Hope this will help you.
Thanks.