Posts

jQuery auto-focus on particular text field after page load

Below code will help us to focus on particular text field in page. It will be used for users to start typing their queries after page is loaded. We can use this in login, search pages etc., for quick access. jQuery(document).ready(function() { var txtField = jQuery("#autocomplete").get(0); var elemLen = txtField.value.length; txtField.selectionStart = elemLen; txtField.selectionEnd = elemLen; txtField.focus(); });

Avoid merging old cart items in customer session magento

In this post we will see how to avoid merging old cart items to the current checkout session. Scenario: It will be happen when we login to store and adds some products into cart and leaves store without purchasing. Then coming back to the store after sometime and adds some product into cart without login and proceeds to checkout. In checkout page we will be requested to login, after login we can see some additional products are added into the cart which we are added in previous session. In this case what we have to do is we need to clear old cart items( It was requested by one of my client ) and allow customers to show with the current session items.

Upload SWF file in wordpress

Here is the code to Upload swf file in wordpress. function swf_upload($mimes) { if (function_exists('current_user_can')){ $unfiltered = $user ? user_can($user, 'unfiltered_html') : current_user_can('unfiltered_html'); } if (!empty($unfiltered)) { $mimes['swf'] = 'application/x-shockwave-flash'; } return $mimes; } add_filter('upload_mimes', 'swf_upload'); We can use Kimili Flash plugin to embed the flash file.

Magento file validation - prototype

Add file extension validation in magento form by using below code. Validation.add('validate-jpg-png','Please upload only jpg/png file format!',function(the_field_value){ //console.log(the_field_value); if(the_field_value == '') return true; var extension = the_field_value.replace(/^.*\./, ''); if (extension == the_field_value) { extension = ''; } else { extension = extension.toLowerCase(); } switch (extension) { case 'jpg': return true; case 'png': return true; //you can add more case for valid extension. default: return false; } }); To make it work add validate-jpg-png class to input file type.

Get latitude and longitude using google map api - PHP

Google provides an API to get latitude and longitude based on the valid address. All we need to do is just pass address to that api. We can able to get response in various format. In below code i’m requesting api to return response a json format. If curl is enabled in your server you can use below function to get latitude and longitude by passing just address. function getLocation($address = null){ $url = 'http://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($address).'&sensor=false'; $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL,$url); $result=curl_exec($ch); $res = json_decode($result, true); if(isset($res['results'][0]['geometry']['location'])){ return $res['results'][0]['geometry']['location']; }else{ ...

Fixed - Quantity defaults to 0 in product view page magento

We might come across the problem, when we go to product view page in magento qty box will show 0 qty as default. We can change the default value by following below steps. Steps to change default qty in product view page 1. Goto Admin page -> System -> Configuration -> Inventory -> Product Stock Options. 2. Click Add Minimum Qty button. 3. Now add your minimum Qty (ex: 1) that you want to display in product view page in text box then click ‘Save config’. That’s it, now 0 qty in product view page will be replaced by the number that you have mentioned in Minimum Qty text box.

Migrate Twitter API from Version 1 to 1.1

My twitter feed response is started showing below message when i was tried to access users_timeline using this URL https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=karthi0110&count=1 “The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.” I have tried by replacing version 1 to 1.1 in the request URL https://api.twitter.com/1.1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=karthi0110&count=1 it shown “Bad Authentication data” error. So after some research i have fixed it in a proper way. If you are getting this error just migrate it to version 1.1 by following below steps. Process is easy Create App -> Get access codes -> Configure -> Start displaying your feed Go to https://dev.twitter.com/apps/new and fill the form fields like Name, Description, Website.. in-order to create your app. Now ag...