Add to cart form, change output - separating attributes from buy button

This one was not easy. Changing product display, which is node is possible in different ways, but then you have a field_product_reference, which outputs buy button and attributes buttons. So you moved around price in your node template, body/description etc, but you want to separate attributes changing widget and buy. You just can't.

Choosing which PHP to run with Drush, changing CLI php

Using drush on mac with mamp gave me some problems with default setup. I didnt set
DRUSH_PHP variable anywhere so default php was used, also with that no php.ini setting was set and in my drush status I got empty "Drush configuration" variable. So to set this up, I needed to add this to either .profile or to .bash_profile (depends of load order, later goes first if you have it)

Changing Product attributes in drupal commerce, maintain data with ajax reload

What I needed is to preprocess this whole group of data, that consist add to cart button and attributes fields. "Add to cart form" is basically the one that consists attributes and add to cart button. To do that the only way to make it work with AJAX is with form alter. So change the forms data in

Get address lat and long with google api

This will give you a nice array of all the data.

 $request = drupal_http_request('https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA');
 $out = drupal_json_decode($request->data);

Change Views filters, add dynamic date value as range

Using EVA field added to Order entity I needed to use order created date as starting range and ending range for dates.
UI by default doesn't offer this in views, so some preprocessing was done. You could fetch date from argument or as I did directly from

Quick out of memory or out of time debugging

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('memory_limit', ''728M');
ini_set('max_execution_time', 120)

add this to index.php and see what is the output, act on that.

Huge load time, over 700 MB of memory and WSOD when adding/editing node

On a big site with more then 20 000 nodes, when creating particular node I first experienced WSOD, then as I reported errors, max_time_execution passed, then when this was raised memory limit passed. So I raised both to high limits, memory to 1gb and maxe_execution time to forever. Then I run the node/add and what I have to see is

Remove some crayze chars like ? ?

I was doing an import of data from some old DB, that had some chars like ? ? in them, so how to remove them and keep all the other UTF-8 chars in them?

I used iconv("UTF-8", "UTF-8//IGNORE", $vars). And it saved me from going crayze myself.

Create unique username before user_save

When using user_save to create new user, you want to have username unique, if you are importing data or just want to be safe that someone hasn't have chosen username you already have in DB (and not to get nasty error PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry...). Here is some nice code to run on that username variable before saving an object.

Krumo/Devel output in watchdog

If you want to have Krumo/Devel style output in watchdog, just do this.

watchdog('debug',kprint_r($var, TRUE, NULL));