Indented Grouping

Events happening in the community are now at Drupal community events on www.drupal.org.
jessSchn's picture

I was recently asked if I could create a list of products on our website. My catch is that a few of the products require the install of another product. So I need to indent the products that depend on another product.

Something like this:

<Product 1 Title>
<Product 1 Description>

     <Product 2 Title>
     <Product 2 Description>

     <Product 3 Title>
     <Product 3 Description>

<Product 4 Title>
<Product 4 Description>

<Product 5 Title>
<Product 5 Description>

I have tried setting a taxonomy on the content type where you select a product that is required. (So on node Product 2, I would select from the taxonomy list that Product 1 is required.) I then tried using views to group on this taxonomy. This issue is that only some products require another product. So my list will display something like this:

<Product 1 Title>
<Product 1 Description>

<Product 4 Title>
<Product 4 Description>

<Product 5 Title>
<Product 5 Description>

<Taxonomy Product>
<Product 2 Title>
<Product 2 Description>

<Product 3 Title>
<Product 3 Description>

I also tried using an entity reference on products so on the Product 2 node, I can directly select the Product 1 node on the content type. I then tried grouping on the entity reference and I got the same results as I did when I tried grouping on the taxonomy value.

Any Ideas on how to group my products within the list?

Comments

I have an idea, but you may not like it...

JBack's picture

Way to sell it, I know.
What I propose is using a mixture of php and mysql to construct your list in your tpl.php file, or you could place it inside your template.php file and access it from your tpl.php file. You could even go as far as creating a module if you like. But here is the general approach...

If you know the taxonomy id of the second tier term you are looking for, and it is constant across all of your first tier products, you can first grab a list of your first tier products using a SQL query like this;
(I'm not sure if you are using a CCK field for taxonomy, but the example uses one)

mysql> select distinct(nid), field_taxonomy_value from content_field_taxonomy where field_taxonomy_value = 83 order by nid asc limit 5;
+------+----------------------+
| nid  | field_taxonomy_value |
+------+----------------------+
|  319 |                   83 |
|  673 |                   83 |
|  788 |                   83 |
| 1088 |                   83 |
| 1268 |                   83 |
+------+----------------------+
5 rows in set (0.01 sec)

You can remove the "limit 5" I just put that in there to limit the output.

This will give you a list of all node ids associated with the first tier product taxonomy term. Next, you use the same query to grab the second tier taxonomy term associated with the first term. You will have to run this query for each of your first tier products, and optimize it if you can.

Here is an example:

$products = new array();
  $sql = '
    select
      distinct(nid),
      field_taxonomy_value
    from
      content_field_taxonomy
    where
      field_taxonomy_value = ?
    order by
      nid asc';

  $result = db_query($sql, 83);

  // Generate first teir of products
  while ($row = db_fetch_object($result)) {
    $products[$row->nid] = $row;
  }

  // Next we loop through each of the first teir products and get their associated second tier products
  foreach ($products as $k=>$v) {
    $sql = '
    select
      distinct(nid),
      field_taxonomy_value
    from
      content_field_taxonomy
    where
      field_taxonomy_value = ?
    order by
      nid asc';

    $result = db_query($sql, $v->nid);
   
    // Inject the second tier products into the product array at the first teir product key
    while ($row = db_fetch_object($result)) {
      $products[$k][$row->nid] = $row;
    }
  }

It's kind of psuedo code, and not tested, but it should give you a rough idea of how to structure your code.

At the end of the day, what you are looking for is a multidimensional array of your products, a master list that you can simply loop through in your tpl.php file to produce your list in html.

Hope that helps.

need more info?

maryannking's picture

What kind of a website is this?
I assume each product has its own node?
Including the dependency?

Info Answers

jessSchn's picture

It's a website for a software company. Each product is a node. I haven't figured out how to setup the dependency yet - so that is still up in the air.

Did you find the solution

jmev's picture

I'm trying to create select lists with items indented under some categories as well. Have you found this solution?

Drupal rocks and I roll — together we play the classics

Twin Cities

Group events

Add to calendar

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: