Posts

Magento: Do some action after magento form validation

In Magento, we are having default validation function called VarienForm , if we pass our form id it will validate the input fields based on the class we specified into it. Ex. required-entry, validate-email . If we want to do some action before submitting form, follow below code to catch the success action. var dataForm = new VarienForm('reach-form-validate'); $('reach_us_submit').observe('click', function(){ if(dataForm.validator.validate()){ jQuery('#reach_us_submit').attr('disabled','disabled'); dataForm.form.submit(); } else { jQuery('#reach_us_submit').removeAttr('disabled'); } }.bind(dataForm));

Condition based MySQL left join with CASE

Image
Happy to write post after long time :) I had a scenario that there is are some fields in a table like `id`,`group`,`object_id`. `group` field(ENUM) has three groups named `user`, `deal`, `scene` and `object_id`(it will have the primary key for corresponding group). ie., If the row has group name of `user`, then `object_id` refers to `user_id` and if the row has group name of `deal`, then object id will refers to `deal_id`. What i want to achieve is i need to have a field called `name` in result so that if the current row group is user then username should be displayed in `name` field and if the row group is `deal` then the `name` field should have `deal_name`.

Get current page handler list magento

$this->getLayout()->getUpdate()->getHandles();

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.