Archive for the 'Tech Stuff' Category

Q: Is it possible to use the ubercart Option Images module (uc_option_image) with a custom product display template, via Content Template (contemplate) or a custom node.tpl.php?

 

A: Yes, you just need to manually call the attribute image into your template with a line of PHP code.

 

The ubercart Option Images module (uc_option_image) is a really nice module that allows you to provide an alternative image for product attribute options – when the visitor views a product and chooses an attribute option (say colour: Red) the attribute displayed image will change to the one for that option – very nice especially for online shops that sell, say clothes in different colours and patterns etc. 

 

The strange thing is that (at the time of writing) the Option Images 6.x-1.4 doesn’t work and doesn’t even install!  Luckily some good folks have worked around the problems and come up with a fixed version that does work (with a bit of TLC) - I have written an article about  getting option images to work with the patched version on the Pride Design website  here –>

 

http://www.pridedesign.ie/content/ubercart-option-images-installs

 

This should hopefully help you to get it up and running…

 

Now, by default this module only attaches the option image to the default ubercart product display, if you are using a custom product template (as I always do) via the Content Template (contemplate) module or via a custom node.tpl.php file then the option images will not be displayed. 

 

To get around this you just have to pop a bit of PHP code into you template at the point at which you want the image to display as follows:

?

print $node->content['option_image']['#value'];

 

This should do the trick.  If you want only the attribute option image to be displayed (i.e. instead of the product image) then just replace your current product image display code with this.

Software development can sometimes be a comical affair, I have just been caught out badly by a strange gotcha - it appeared that #pragma once stopped working on a Visual Studio C++ project on which I have been working.  I was getting plenty of error messages about redefined classes! 

 

Well it turns out that I had left a copy of one of my header files lying around in one of the project folders.  As pragma once uses a header file’s full path to figure out if it has already opened it, a situation arose whereby both files were included and compile errors flooded in (despite the pragma onces)!

 

Well removing the (accidential) copy of the header file fixed the problem – boy do I feel stupid, I hope this post may help someone with a similar problem in the future!

I ran into a problem the other day with .NET’s Convert.ToDecimal() , it turns out that it doesn’t handle scientific Notation! Pass it something like “8E-5″ and the poor thing just throws an exception…

 

The software in which the problem surfaced was developed as a web application that must deal with numbers read from an Excel chart and so the formats encountered are many and varied!

 

This post points out that you can use this instead:

 

Decimal.Parse(val, System.Globalization.NumberStyles.AllowExponent);

 

But just to be safe I am now using:

 

Decimal.Parse(val, System.Globalization.NumberStyles.Any);

 

And it does work for Exponents, hopefully along with everything else!

I have been developing a web application for one of our clients using drupal, it’s a dashboard type data visualisation system that consumes and displays data over an intranet from their software systems.  I have been using google charts with great success.

 

The Chart API module for drupal is very nice, it lets you quite easily incorporate google charts into your web site or application without having to get into the details of the google chart API itself, and the charts themselves look great – just the kind of thing to cheer up a busy software developer.  However it deosn’t seem to support Radar or Polar charts.  There is no mention of them in the documentation, no example on the examples page.  There is also no symbol such as ‘CHART_TYPE_RADAR’ defined in the module as there is for the other chart types, for example ‘CHART_TYPE_LINE’ defined for line charts.

 

So is it possible to plot radar charts using the Chart API module?  I consulted the google chart api and found that the radar chart type is donated as ‘r’, so I tried creating a simple chart and just set it’s type to ‘r’ (rather than say CHART_TYPE_LINE) and it worked just fine!

 

$chart = array( '#chart_id' => 'sink_radar', '#title' => chart_title(t('Failures by Sink'), '001334', 15), '#type' => 'r', '#size' => chart_size(400, 240), ); $chart['#data'][] = array(20, 30, 15, 70, 90, 20); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink1'); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink2'); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink3'); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink4'); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink5'); $chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label('sink6'); echo chart_render($chart);

 This code yileds a chart like this:

 

Radar Chart

I ran into a funny problem recently with Ridge’s debian fileserver – I connected a second external USB drive to it and it stopped working! It always had one external USB drive connected, this was mapped to /dev/sda1 and auto-mounted in /etc/fstab along the lines of:

 

/dev/sda1    /mnt/usb   auto    rw    0       0

 

Everything was running nicely until I introduced a second usb device, this time a large flash disk onto which our automatic backup script is going to periodically dump an encrypted tarball (to provide an easy way for us to move encrypted backups off-site.)

 

Anyway, I saw that the second disk was mapped to /dev/sdb1 and I optimistically modified /etc/fstab to cater for the new flash disk along the lines of:

 

/dev/sda1    /mnt/usb   auto    rw    0       0
/dev/sdb1   /mnt/flash  vfat  rw,users,umask=0   0    0

 

So far so good, after reboot both file systems successfully mounted. But after the next reboot things were not as expected, the original disk was mounted onto the new ‘flash’ mount point and the FAT flash disk was not mounted at all!

 

With the second USB disk connected the way in which the disks were mapped to Linux devices would change randomly every time the system was rebooted – sometimes a disk would appear as /dev/sda1 and sometimes as /dev/sdb1.  As you can imagine this completely ruined the file system setup as configured in /etc/fstab!!

 

I had never encountered this before, but after a little research I found a work around – this involved mounting the disks by label rather than by the more traditional device name.

 

All labelled disks/volumes can be found in /dev/disk/by-label/ , these labels are static and can be used to mount their volumes (instead of using the non-static /dev/sda1 etc.).  Only labelled device appear in the by-label directory, so if you don’t see a disk you may have to give it a label using the tune2fs command. I had to give my original USB disk’s volume a label, I determined that it was currently mapped to /dev/sdb1 and issued the following command to label it as ‘external’:

 

tune2fs -L external /dev/sdb1

 

Now with both disks labelled I modified /etc/fstab as follows:

 

/dev/disk/by-label/external    /mnt/usb   auto    rw    0       0
/dev/disk/by-label/CORSAIR    /mnt/flash  vfat  rw,users,umask=0   0    0

 

And thankfully that fixed the problem! – with the IT systems purring along I can get back to the many more mundane aspects of running a software development consultancy…

I was making some mods to an old ASP .NET web app today when I discovered that I could no longer properly debug it – when I started the debugger, VS2005 would launch IE8 and load the app but would then just detach and exit debug mode!  I have been running IE8 for a few months now and figured that the problem might have something to do with IE8 and sure enough it did!!

 

I found this excellent post which details a simple fix for the problem - I can now happily debug again!  It seems that the fix prevents IE8 from spreading itself across multiple processes this was confusing the poor VS2005 debugger..

Just in case I forget how to do it – here a link to a post that tells you how to change the add to cart button in ubercart, http://www.pridedesign.ie/content/ubercart-style-add-cart-button

very handy indeed!

I was on-site with a client at a pharamacutical production facility last week and they they showed me a strange problem that they were having with .NET Remoting running on a sub-network configured with a multihomed host that sits on both the sub-net and the factory ethernet.

 

The sub-network consisted of 11 Machine Vision inspection station PCs that happily inspect product on the production line and report their results and status asynchronously to a single ‘dashboard’ system running on the multi-homed host. We had developed the inspection stations with vanilla C++ and the ‘dashboard’ system in C# .NET, they all communicate via .NET Remoting.

 

The dashboard system connects to each of the inspection stations in turn and passes a remoting object of a shared interface, the inspection stations raise events across the sub-net by calling back on this shared interface.

 

All was well with tonnes of nice events being raised and received, until one day they all just stopped! The client was sure that nothing could have changed to cause this as the whole system was under qualification and therefore everything (software/configuration etc.) must stay static. However on further investigation it turned out that the dashboard PC had recently been added to the factory ethernet – and sure enough, once the factory network was whipped out and the dashboard restarted the events came flooding back!

 

Anyway it seems that when the dashboard system was connected to the factory network it communicated to the inspection stations using its factory NIC identity and IP address.  When the stations tried to callback they used this factory IP address and the callback events were lost as the PC knew of no  way to route the traffic onto the factory network (and hence back to the dashboard system).  On further investigation we found that the inspection station PCs (which were given static IP addresses) did not have a default gateway configured so we configured the dashboard’s local IP address as the gateway for each and the problem was solved!  This change ment that any network traffic destined for any network other than the local sub-net would be automatically sent to the dashboard system.

So, to cut a long and boring story short, if you’re having .NET remoting callback problems with a multihomed host take a look at the network configuration and make sure that t he PCs that raise the events are able to route them back to the receiver PC no matter which network it initially calls on..

Here’s something I was googling last week – How do you change the text of Drupal’s ‘Home’ breadcrumb to something else? Well, it turns out that a small mod to your theme may be required…

 

While using Drupal 6 to develop a web application we ran into a little snag with Drupal’s breadcrumbs, the app is to integrate in with our client’s existing web site, it will look and feel the same and the visitor should not really know that it is separate from the main website (which is not implemented with drupal).  With drupal this was all easy enough to achieve, but we hit a speed bump when it came to the web app’s breadcrumbs.  Breadcrumb navigation is very important for the new web application, but Drupal always calls the first breadcrumb ‘Home’ – this was a problem as ‘Home’ did not refer to the larger web site’s home page as would be expected, but instead to the first page of the web application.

 

So how do we change the ‘Home’ breadcrumb text to something else, say the title of our web application?  It turns out that there’s no easy way to do this through settings, but thanks to this thread we can see that it is possible via a small change to the active theme. The modification hooks into phptemplate_breadcrumb(), it removes the existing primary breadcrimb (‘Home’) and then inserts a replacement with the new text.

 

So to make the change, edit your theme’s template.php file, and search for the function called:

 

phptemplate_breadcrumb()

rename it to:

original_phptemplate_breadcrumb()

Then paste in the following, changing ‘New Home Text’ to what ever you want your ‘Home’ breadcrumb to be called.

function phptemplate_breadcrumb($breadcrumb) {   if (!empty($breadcrumb))   {     // remove the exisitng Home link     $old_home_link = array_shift($breadcrumb);     // insert the new link     array_unshift($breadcrumb,                    l(t('New Home Text'), '<front>'));     // Get the original function to     // output the breadcrumb     return original_phptemplate_breadcrumb($breadcrumb);   } }

With this theme modification in place the breadcrumbs should display with the new text in place, bit of a pain but at least it’s do-able!

 

 

Hats off to gwen for the tip & code!

If you’re using the TinyMCE wsywig editor in drupal then you may find that the editor’s background color gets set to that of your website rather than being the more normal white-ish color – this can cause the wysiwyg editor look like the proverbial dog’s dinner and depending on your websites background color/image, can make reading the text very difficult.

 

Well, the good news is that it’s easily fixed – in Drupal, go to Adminsiter/Wysiwyg menu and for each import format with which you are using TinyMCE, click ‘edit’. Once in the settings editor click on the ‘CSS’ section and in the ‘Editor CSS’ drop-down choose ‘Editor default CSS’ and save. Do this for each import format and the editor’s background should revert to a calming white.