Customize Ubercart Product Page

| | Comments (0)

Here's a little snippet of code to customize ubercart product page template so that the contents are grouped into tabs.

You need Tabs and CCK Fieldgroups Tabs.

Go to yoursite/admin/content/node-type/product/fields and add some cck groups and fields, then display them properly (tabs for full node).

Create node-product.tpl.php. Paste the following php code in (enclose it with php tags):

$form = array();
$form['ptabs'] = array(
'#tabset_name' => 'ptabs',
'#type' => 'tabset',
);
$i = 0;

// shows a summary of the product
$summary;
$summary .= $node->content['weight']['#value'];
$summary .= $node->content['dimensions']['#value'];
$summary .= $node->content['body']['#value'];
$form['ptabs'][$i] = array(
'#type' => 'tabpage',
'#title' => t('Summary'),
'#content' => $summary,
);
$i++;

// add other tabs if applicable
if (!empty($node->content['fieldgroup_tabs'])) {
	foreach ($node->content['fieldgroup_tabs'] as $key => $value) {
		if (is_array($value)) {
			if ($value['#type'] == 'tabpage') {
				$form['ptabs'][$i] = array(
				'#type' => 'tabpage',
				'#title' => $value['group']['#title'],
				'#content' => $value['group']['#children'],
				);
				$i++;
			}
		}
	}
}

The page should always have a tab called Summary, and other tabs that you added for the content type if they are not empty (cck fieldgroup tabs module validates this). If you don't wish to have the Summary tab, simply delete that part of code.

Feel free to share the code.

For more info on Dovecot: http://wiki.dovecot.org/LDA

Add the following at the bottom of master.cf

# spamassassin then dovecot LDA
dovecot    unix  -       n       n       -       -       pipe
    flags=DRhu user=vmail:mail argv=/usr/bin/spamc -u randomuser -e /usr/libexec/dovecot/deliver -f ${sender} -d ${recipient}

Basically, postfix pipe the mail into spamc, and since you don't want to run it as root you use another user (-u). -e redirects the output from spamc for dovecot to deliver. And postfix tells dovecot who the sender is, and who the recipient is.

Add the following to main.cf

mailbox_command = /path/to/dovecot/deliver
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1

Now just restart postfix and you are done. Depending on how you setup the virtual domain database, it works for multiple domains.

How to start a new Activity

| | Comments (0)

Android has a weird way of constructing UI. At least I haven't got used to it.

First of all, AndroidManifest.xml must have activities listed:


<activity android:name=".FirstActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>


<activity android:name=".SecondActivity" android:label="Second Activity">
    <intent-filter>
        <action android:name="com.example.app.activities.SECOND" />
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

There are several ways to set the components (action, type, category) of Intent, below are the 2 easiest ways.

Intent i = new Intent();
i.setAction(“com.example.app.activities.SECOND”);

Or this:

i.setClass(getApplicationContext(), SecondView.class);

Create a bundle to pass data to the new activity:

Bundle bundle = new Bundle();
bundle.putString("TEXT", "Lorem ipsum");
i.putExtras(bundle);

To start the activity:

startActivity(i);

To get the data from the bundle that’s passed to our new activity:

Bundle bundle = getIntent().getExtras();
String prompt = bundle.getString("TEXT");

Starting Android Development

| | Comments (0)

I decided earlier this week that it’s time to see how developing on Android feels like, and installed Eclipse and the ADT plugin. Setting up the development environment was pretty fast; took about 5 minutes.

Here is a screenshot of the Android Emulator running my HelloWorld app. android-emulator.jpg

The emulator takes a while to boot (the first time I ran it I thought it froze so I force quitted it). I’m running Leopard on my macbook pro and I every time I start the emulator I get this waring: “Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.” It doesn’t affect the emulator in anyway so there is nothing to worry about; just ignore it. This issue might be addressed in future versions.

Here’s some links:

Updates to this blog

| | Comments (0)

I apologize for the encoding and mysteriously disappeared images, everything should be working now.

In the meanwhile I will be updating the format of some old posts.

Webform is a great module, but it doesn't send confirmation email, so here is a quick fix if you are running on Drupal 6.x.

To get the submitted value of a form component, you can use $form_values['submitted_tree']['component_key'] where component_key should be replaced by your component key. If the component is in a fieldset, access it by $form_values['submitted_tree']['fieldset_key']['component_key'] where fieldset_key should be replaced by your fieldset key.

To send the email I chose to use drupal_mail() function, of course there are other ways.

Here is an example:

$from = "example@example.com";
$to = $form_values['submitted_tree']['email'];
$user = $form_values['submitted_tree'['name'];
$body = "Hello " . $user . ",\nThis is a message.";
drupal_mail('webform_extra', 'confirmation_key', $to, language_default(), array('body' => $body), $from, TRUE);
function webform_extra_mail($key, &$message, $params) {
$message['subject'] = "Confirmation email";
$message['body'] = $params['body'];
}

The possibleTitles property of UIBarButtonItem is pretty useful if you need to change the title and also animate the changes. I was trying to animate both the back button and the title of the right barbutton at the same time, but the back button wouldn't disappear properly (i.e. not animated) until I set the possibleTitles of the right barbutton.

First create the button. Do this in viewDidLoad.

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(toggleEditing)] autorelease];
self.navigationItem.rightBarButtonItem.possibleTitles = [NSSet setWithObjects:@"Edit", @"Done", nil];

To change the title just set the title property. Very easy. Both changes will be animated.

- (void)toggleEditing {
	if (!self.editing) {
		self.navigationItem.rightBarButtonItem.title = @"Done";
		[self.navigationItem setHidesBackButton:YES animated:YES];
	} else {
		self.navigationItem.rightBarButtonItem.title = @"Edit";
		[self.navigationItem setHidesBackButton:NO animated:YES];
	}
}

This works in OS 3.0.

It's confirmed that if you have a 2G iPhone that is unlocked with BootNeuter (running firmware 2.2.1), you can safely update to OS 3.0 using iTunes (yes just press that Update button).

For detailed and step-by-step instructions see here