Customer-specified price in Drupal 7 Commerce

Today, I spent several hours messing about with the Rules UI and googling Commerce docs and forums, trying to figure out how to provide a field where the customer can freely choose the price of a donation-style product. In the end, I found pointers to a method which turns out to work pretty well.

My use case

Donation as a Drupal 7 Commerce product. Donation amount can be chosen freely, above a fixed minimum. The customer/donor receives a reward (but that is not actually relevant here).


This is how I did it:

  1. Install Commerce Customizable Products
  2. Add price field
    1. Add a line item type at admin/commerce/config/line-items. It is created with a bunch of default fields, which you cannot change.
    2. Add a field of the Price type (TODO: Figure out how to set a minimum)
  3. Make it visible
    1. At the field display settings of your product display content type (something like admin/structure/types/manage/product-display/display), edit the settings for the product reference field. Change Add to Cart line item type to your new line item type. Click Update and Save.
  4. Make it count
    1. Add a new rule at admin/config/workflow/rules. Choose the event Calculating the sell price of a product.
    2. Add an Entity has field condition with commerce-line-item for Entity and your price field for Field.
    3. Add a Set the unit price to a specific amount action with commerce-line-item for Line item and something like commerce-line-item:field-donation-price:amount for Amount.

PhpStorm keymap in Ubuntu

I am used to using PhpStorm on a Mac, but now I am with Ubuntu on a ThinkPad so the keymapping is all off. I want to use the Mac OS X keymap, but contrary to my expectation, pressing the Windows key does not produce the Meta symbol so I cannot access half the shortcuts. I tried to find out how to make that happen, but to no avail. For now, I’m settling with the Eclipse keymap, with some modifications for my most habitual shortcuts.

Easy SSL on NearlyFreeSpeech

There is a technology that encrypts your internet traffic. It’s called SSL and it prevents third parties from snooping on what you submit on web pages – passwords and other data. If the website address you’re visiting begins with https, the site is SSL-enabled. Your browser will probably also show a padlock icon near the address.

I must admit I never quite got the hang of how it works. Not the encryption itself, but also not the creation, nor the nature, of those certificates that apparently are an integral part of the SSL technology. You need one for the website you want to enable SSL for, and they are something you have to pay someone for. That’s my vague conception.

Until I found out, just now, that my go-to web host NearlyFreeSpeech (NFS) thas a one-line command that just does all that for you. That there is a project called Let’s Encrypt that (somehow) provides certificates for free, and NFS cooked up a script that sets it all up automatically. I literally ran the command and then it worked.

My conception about SSL is as vague as before, but at least I know it can also be really very easy.

Single-machine dev mail setup

I sometimes work on websites where sending email is a central task. To be able to efficiently test my code on my Ubuntu development machine, I have created a simple setup from the following requirements:

  1. No mail should reach the internet
  2. I should be able to quickly read every message that is “sent” from PHP

The strategy is to use Postfix to catch and save messages (and enable mail() at all), and Mutt to read them without any fluff. Continue reading “Single-machine dev mail setup”