Blogs

Storing monetary amounts in db? Use decimals, not floats!

Lot’s of people will be surprised (or shocked, when it happens in production) when they see that mysql can work like this:

Query:

SELECT transaction_id, amount FROM transactions WHERE amount>20.5

Response:

123|20.5

Query:

SELECT transaction_id, amount FROM transactions WHERE amount=20.5

Response:

No rows

So, 20.5 is really greater than 20.5 in sql database. Sometimes. Read more »

Rules won't work properly when run during cron, if you use node access restrictions

I’ve recently created USPS tracking module for Drupal, so Qwintry.com users could get notifications when their international packages change state. I’ve used queue operations to build requests to USPS API by cron, and it seems to work great for our customers, but this story is not about the module.

My plan was to provide rules event “The package [tracking number] changed active state from [old state] to [new state]”. (words in square brackets are Rules arguments). Read more »

Image title as text description for colorbox image formatter (Drupal 7)

When you have core “image” field on your node type and you want to output “title” (or “alt”) of this image just under the image thumbnail as text - you can use image_caption_formatter module for that.
But only in the case when you don’t need another image formatter in place - e.g. Colorbox - because Colorbox provides its own image formatter, and image_caption_formatter module also provides its own image formatter. You obviously can’t use two formatters at the same time. Read more »

Be careful with drupal_get_form() in theme layer

When you create Drupal code for 7 years, it’s easy to mistakenly assume that you know everything regarding such basic things as theme_preprocess_node() and drupal_get_form() functions.
And that is a wrong feeling. Today I’ve discovered that you shouldn’t mix these functions!

The bug description:
I was creating “join” form which was rendered in node.tpl.php of organic group.
When the form was submitted, validation/status messages were shown only after additional page refresh. So, after form submit page was reloading without any messages, and all the messages were appearing on the screen after additional page reload. Read more »

Improving user experience: using Dialogs for profile edit in modal forms

We are now developing big Drupal 7 project where users have profiles with lots of fields.
They also have a node tied to them (“My story”) which is created during registration.

Initially, these were “edit my profile” and “edit my story” links which were leading to a huge forms where user was scared by amount of elements.

And that is the result of UI improvements:
Modal 1

and after clicking “Edit” near “Hobby” item…
Modal 1

So, basically, user has separate small form for photo upload, separate form for about field, and separate form for small details. Read more »

Using Ubercart to sell files: ui improvements and creating file feature programmatically

uc_file module that allows selling files in Ubercart is definitely not perfect in terms of API, but it is a nice piece of functionality.
We’ve just finished creating one e-book store which has product-import feature.
Each product has multiple formats (pdf, epub, rtf) - some products can have pdf+epub, some can have just pdf, others have all three formats attached.

On product page, we wanted to show nice block like this:

Ubercart file downloads

where pdf and doc are just text for regular users, and download links for users that already bought this book.

All the code was created for Drupal 7 + Ubercart 7.x-3.x Read more »

Calendar with highlighted dates

In Drupal 7, it’s easy to show calendar (ui.datepicker) date selector to user. (it’s not hard in Drupal 6, too - but in d6 you need to enable http://drupal.org/project/jquery_ui to get the calendar, I think)

You just write several lines of js code, and you get a calendar.
But things are quickly getting more complicated when you need to allow visitors to choose from dates that have some nodes “attached” to them only. E.g. if you have news view, and you don’t have news for 13 Nov 2011, there is no sense in allowing user to click on this date in calendar (I’m talking about the case when clicking on calendar redirects user to views page /news/2011/11/02 , where 2011/11/02 is a context filter for news nodes)

Here is the screenshot illustrating the desired functionality: Read more »

Writing robust code that uses fields, in Drupal 7

In Drupal 7, the direct access to entity fields (CCK in d6) is different. In Drupal 6 you write:

<?php
$field_val
= $node->field_yourfield[0]['value'];
?>

in Drupal 7 you have to write:

<?php
$field_val
= $node->field_yourfield[LANGUAGE_NONE][0]['value'];
?>

(this is a way suggested by core docs).
So, we have different languages here now.

I haven’t built any d7 multilanguage websites yet, so I don’t know if that approach makes it really easy to create language-aware code for i18n websites (I hope it does!), but for regular single language websites this approach just adds some headaches to the developers. Read more »

Commerce Product Constructor

Today I’ve made another decision to postpone using Commerce in our project where customer needed simple e-shop. I’ve actually made such decisions several times already, and that makes me feel unhappy.
I would like to say that I really enjoy Commerce presentations, (like everyone of you, huh?), and test installations are working great!
The idea of Drupal-way, and Rules, and Views-everywhere rocks.

But… Commerce is being developed for a long time already, and you still can’t show it to your customers if they need to log in to admin section of their website!

Why?

That’s node display + product entity problem.

In Commerce, product entity is a primary thing, and this is an item that holds product-specific data like SKU and price. Read more »

Additional CCK powered price for product in Ubercart

I was not updating my blog for a while - it’s summer here :)
I’ve just returned back from my business trip to US, Alaska, where I helped guys from shipito.com killer to automate their warehouse and create good user control panel in their website (everything is Drupal-powered here!). I’ve also spent several days surfing in San Diego. It’s so exciting to realize that Drupal knowledge can give you an opportunity to visit such amazing places and meet interesting and smart people all over the world!

Today I will tell you about small, but cool feature which makes Ubercart website pricing even more flexible.
The code was designed to work in Drupal 6.x + Ubercart 2.4.

There is a lot of Ubercart modules that provide separate prices for some specific conditions. Read more »

Recent comments

"test "
by Anonymous2 days 15 hours ago
"This is truly a great read for me... Things are much better in Drupal 7, but 6.x branch is still very strong in terms of popularity. saffron extract "
by Rhase Bingg3 days 16 hours ago
"This article was written for Drupal 6.x - and in Drupal 7.x, CA was replaced by Rules module. "
by Anton Sidashin2 weeks 2 days ago
"Am unable to find the CA module in drupal? Please help me. Thanks in advance "
by Ravi4 weeks 4 days ago
"Our theme demo website now uses simulcasting for code, but divide database. And I think we are going to switch to single file later. "
by Anonymous5 weeks 17 hours ago
Drupal association member