I posted this in the forum but didn't get any reply. I hope someone can help me here.

I'm using views bonus grid to display my catalog. Currently when there is a sale, the old and new price show on two lines. I would like the prices to show on one line and if the item is not on sale, the only price showing should be centered. How do I theme this? I'm not good with PHP so please bear with me.Thanks in advance.

CommentFileSizeAuthor
grid_nosale.jpg4.99 KBfehin
grid_goal.jpg7.33 KBfehin
grid_now.jpg6.58 KBfehin

Comments

fehin’s picture

I was able to achieve this with views table for a block that I created. I can't find much info about theming grid anywhere. Would someone please advice me on how I can change my code to works with grids? Thanks.

Note: I changed my comments to say rows instead of columns.

/* Coverts 5-row grid to 4 rows by combining the last 3rd and 4th rows to the 3rd row*/
function phptemplate_views_bonus_view_grid_catalog($view, $nodes, $type) {
   $fields = _views_get_fields();

  foreach ($nodes as $node) {
    $row = array();
    foreach ($view->field as $field) {
      if ($fields[$field['id']]['visible'] !== FALSE) {
        $cell['data'] = views_theme_field('views_handle_field', $field['queryname'], $fields, $field, $node, $view);
        $cell['class'] = "view-field ". views_css_safe('view-field-'. $field['queryname']);
        $row[] = $cell;
      }
    } 
    //check the fields that I want to add class to status
    //if available, add class to the row
    if ($row[1]['data']=='Title'){
      $row[1]['class'] .= ' '. 'title-row';
    } elseif ($row[1]['data']=='List price'){
      $row[1]['class'] .= ' '. 'list_price-row';
    }  elseif ($row[1]['data']=='Sell price'){
      $row[1]['class'] .= ' '. 'sell_price-row';
    }elseif ($row[1]['data']=='Author Name'){
      $row[1]['class'] .= ' '. 'author-row';
    }
    //if data in the first row
    if (isset($row[0]['data'])){
	   /*Combines the 3rd and 4th rows*/
      /*check check to see if List price is higher than Sell price; if yes print all the fields else leave List price out*/
      if ($row[2]['data'] > $row[3]['data']){
        $row[2]['data'] = $row[2]['data'] .'  '. $row[3]['data'];
      } else {
        $row[2]['data'] = $row[3]['data'];
      }
    } else {
	//If List price=$0.00, don't print
      if ($row[2]['data'] == '0.00'){
        $row[2]['data'] = $row[3]['data'];
      }
    }
    //unset the row "Sell price"
    unset($row[3]);
    //save the rows. We have Row1: image; row2: Title; row3: List price and/or sell price; row4: Author name.
    $rows[] = $row;
  }
  unset($view->table_header[3]);
  return theme('table', $view->table_header, $rows);
}
esmerel’s picture

Status: Active » Closed (fixed)

Nobody's really maintaining 5.x at this point