Magento checkout agreements missing

Magento I had to work on a Magento template that was bought and assumed to be in a “fully functional and anatomically correct form” (cit), except that it was not able to show the checkout agreements in the checkout process even if the standard procedures are all done correctly.

The problem was (of course) in the XML layout of the checkout page (checkout.xml) where the block that was supposed to output the agreements, here below:

<block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/>

Was positioned in the wrong place, in my case it was inside the “Review” element of the checkout:

<block type="checkout/onepage_review" name="checkout.onepage.review" as="review" template="checkout/onepage/review.phtml">
-- stuffs --
</block>

That is pretty wrong! This error will make impossible for customers to complete the checkout process as the system will spam pop “Hey you did not accept the agreements!”. That block is supposed to stay inside the info block of the review:


<block type="checkout/onepage_review_info" name="root" output="toHtml" template="checkout/onepage/review/info.phtml">
-- many stuffs --
   <block type="checkout/agreements" name="checkout.onepage.agreements" as="agreements" template="checkout/onepage/agreements.phtml"/>
</block>

At this point a simple cache refresh fixed the issue and get the checkout agreements in the checkout page.

Enjoy!

How to solve Google Maps Javascript API v2 “Invalid key” error

Recently I had to work with the Google Maps JavaScript API v2 (I know, it is deprecated, but isn’t my project and I can’t just update it to the v3) and I was getting spammed by this error:

Google has disabled use of the Maps API for this application. The provided key is not a valid Google API Key, or it is not authorized for the Google Maps JavaScript API v2 on this site. If you are the owner of this application, you can learn about obtaining a valid key here: http://code.google.com/apis/maps/documentation/javascript/v2/introduction.html
#Obtaining_Key

I tried everything Google suggested and I couldn’t make it work at all, then I discovered that this few lines in the “Allowed referrers” will get the problem solved instantly:

sitename.com
sitename.com/*
http://www.sitename.com
http://www.sitename.com/*
*.sitename.com
*.sitename.com/*

This pattern will make you get back to work in few seconds.

Enjoy!

Drupal SA-CORE-2012-003 quick fix

Drupal Recently Drupal released the new version (7.16) to fix a security issue that would allow an attacker to reinstall an existing Drupal site with an external database server and then execute custom PHP code, more information available here: http://drupal.org/node/1815912.

There are many way to prevent this instead of updating a Drupal installation (always recommended), probably the quickest is to deny access to the interested file with few lines for the .htaccess file:


<Files install.php>
  deny from all
  ErrorDocument 403 "Access denied."
</Files>

Enjoy!

Vodafone key on ubuntu 12.04

Ubuntu 12.04 Recently I had to connect to internet using the Vodafone Key from the Vodafone station, here a brief guide about how to do it quickly:

1) Click on the icon that manage the network connections and select “Edit connections”
2) Select “Mobile Broadband”
3) Click on “Add”
4) Now you should see your Internet key connection, select “Modify”
5) Your vodafone APN is web.omnitel.it

That is, this mainly apply to users from Italy.

Drupal 7: how to create a form within a module

Drupal If you develop modules and you need to create a form in one of your page, there is a nice Drupal function that can render an array into a pretty HTML form: drupal_get_form().

This handy function is usually needed in a menu callback as it does not require an existing form.

You can use it like this:

/**
* Implements hook_menu()
*/
function mymodule_menu() {
 $items['mymodule'] = array(
  'title' => 'My title', //The name of the menu that will be displayed
  'page callback' => 'mymodule_page_callback', //The name of the function that will output a page
 );
 return $items;
}

function mymodule_page_callback() {
 //The argument is the name of the function with the form details
 return drupal_get_form('mymodule_form');
}

function mymodule_form($form, &$form_state) {
 $form = array (
  '#action' => '#', //The action attribute of the HTML form tag
  'name' => array ( //We define a simple text field for the "name"
   '#type' => 'textfield',
   '#title' => t('My pretty name'), //The label that will be placed with the field
   '#description' => t('My descrition'), //The description will be placed right below the field
   '#required' => TRUE, //If true the system will perform a simple check on submit so that it is never empty
  ),
  'submit' => array ( //We define a simple submit button
   '#type' => 'submit',
   '#value' => t('My submit'),
  ),
 );

 return $form;
}

After you have defined the form, you can implement 2 extra functions that will handle the validation (_validate) and the processing (_submit) of the form values.


function mymodule_form_validate($form, &$form_state){
 // My validation parameters
 if(strlen($form_state['values']['name']) > 10) {
  form_set_error('', t('Hey, your name is too long!'));
 }
}

function mymodule_form_submit($form, &$form_state) {
 //My success processing
 drupal_set_message(t('Yay, your name is fine!'));
}

And that is, pretty simple uh?