Drupal Archive

Drupal Commerce: first impressions

I’ve been running an online shop for a year now which hasn’t really taken off due to a mixture of lack of time and secondly, hating OSCommerce that it’s running on.

Having spent a large portion of the last year using Drupal 7 for work I decided to re-develop the shop using that. I check it out and two main options for contributed modules to provide the shop functionality came up: UberCart and Drupal Commerce. I started with Ubercart since I’d heard with it and it was more established, however I didn’t like some aspects of it and after an update, it crashed the site. So I installed the Drupal Commerce module and started to play with that.

The standard configuration was easy enough being a mix of Drupal knowledge and the fundamentals of commerce software. After that it was a case of adding my 250+ products. This is where the first bit of confusion came in. Drupal Commerce works by having a content type called Product Display which can have fields in the same way as other nodes, but also has within the shop Products which are completely seperate and have their own set of fields. It seemed a little confusing at first since I didn’t get why you’d want double entry – having to add the product with the price etc as a Product and then add it again as a Product Display with a description.

After more reading I found out that the seperation of product and display is due to a feature that I specifically needed. My shop sells lingerie and as such each item I sell has options for size and sometimes, colour. In the real world these can be considered seperate products, they are different – you can’t send a green one out if the customer has requested red. So with Drupal Commerce you add each option as a seperate Product and then add a Product Display for all of the different options. The Product Display node can then be used to create the site, either as part of a menu, tagged with taxonomy to create product categories or however you would normally use Drupal to create your site.

The benefit though is when you arrive on the Product Display node. Drupal Commerce can then take all the different Products and create option dropdowns so a customer can select the size and colour they want and then add to basket. That chosen Product is then added to their order.

I’m not sure if this may be annoying for shops where there are no options and you have to add a Product and then Display for each item, but if it is and you have quite a few products then there’s always Commerce Feeds to the rescue. This is a module that utilises the Drupal Commerce and Feeds modules to allow you to use CSV files or other formats and import them directly into Drupal.

So far I’ve got the 1,000+ Products added. Tomorrow night I’ll look at the 250+ Product Displays.

First impressions: impressed

Strange problem when creatng Drupal 7 Module form_submit and db_update

Today we were creating a new custom module in Drupal and we had a form we had created and a submit handler. In the submit handler we had a db_update to update the row in the database. For ages we couldn’t find out why it wasn’t working until we noticed we’d set the update variables using

$form_state['values']['name']

This is wrong. This stores the values of the form fields as they were when the form was generated. To get the values of the fields as they were submitted, you need:

$form_state['input']['name']

One of those things that takes hours to spot! ARRRGGHH!!!

Drupal 7: Get the tpl.php name of a certain View

I was trying to theme a certain view in a D7 site since I couldn’t get Views to do what I needed without using my own PHP and jQuery.

It took me ages to track down what name to use in the tpl file for my theme. The easiest way of finding out what tpl.php name to use, either for a single view, type of view (e.g. unformatted list) or all views is to go into:

Structure > View > Edit your view

Then under Advanced of the right you will find a “Theme: Information” link that gives you extensive information on the files in use. Enjoy.

Tags:

Drupal 7 doesn’t use tpl files for nodes or content types

If you are copying the default page.tpl.php to use for either a specific node or a specific content type but Drupal is ignoring it there are usually two main reasons:

  1. tpl file name
    If you are used to the D6 naming conventions, be aware it has changed in D7. The new naming conventions are here
  2. Preprocess function
    You may have forgotten to put a preprocess hook in your theme file. For example I have this in most of my Zen sub themes:
    function MYTHEME_preprocess_page(&$variables, $hook) {
    //some other stuff
    if (isset($variables['node']))
    {
    $variables['theme_hook_suggestions'][] = 'page__type__'. $variables['node']->type;
    $variables['theme_hook_suggestions'][] = "page__node__" . $variables['node']->nid;
    }

    }

  3. Hope that helps

Updating Drupal 7 Core using Drush

If you want to save the hassle of upgrading Drupal 7 core from say, 7.4 to 7.7, you can install Drush and then use it from SSH to back up your site and then update core with the follwoing command:drush update
Just make sure you’re in the directory of the Drupal installation you want to update.

Tags: , ,

Removing “My Account” and “Logout” form header in Zen on Drupal

I’m just developing a new site in Drupal using the Zen STARTERKIT and it’s been a while since I’d done a design without the “My Account” and “Logout” links being needed in the header.

To get rid of them, simply go to admin/structure/menu/settings and change or remove a menu in the Secondary Menus.

Simples