Added a handler for the third attribute

This commit is contained in:
mattbk
2015-10-06 19:53:50 -05:00
parent 8eaf686064
commit 1b6f98c7cb
3 changed files with 46 additions and 0 deletions

View File

@ -17,4 +17,5 @@ files[] = views/uc_views_handler_field_attributes.inc
files[] = views/uc_views_attribute_handler_field_order_product_attribute01.inc files[] = views/uc_views_attribute_handler_field_order_product_attribute01.inc
files[] = views/uc_views_attribute_handler_field_order_product_attribute02.inc files[] = views/uc_views_attribute_handler_field_order_product_attribute02.inc
files[] = views/uc_views_attribute_handler_field_order_product_attribute03.inc

View File

@ -125,7 +125,20 @@ foreach($result as $row) {
'handler' => 'uc_views_attribute_handler_field_order_product_attribute02', 'handler' => 'uc_views_attribute_handler_field_order_product_attribute02',
), ),
); );
// Add viewhandler for uc_order_product attributes: Attribute 03
$data['uc_order_products']['attributes03'] = array(
'title' => t('Product attribute 03'),
'help' => t('The third attribute selection for the ordered product.'),
'group' => t('Ubercart order product'),
'field' => array(
'table' => 'uc_order_products',
'real field' => 'data',
'handler' => 'uc_views_attribute_handler_field_order_product_attribute03',
),
);
return $data; return $data;
} }

View File

@ -0,0 +1,32 @@
<?php
/**
* Field handler to provide a human-readable version of the selected combination of attributes
*/
class uc_views_attribute_handler_field_order_product_attribute03 extends views_handler_field {
/**
* Defines a few default options for the combination field
*/
function option_definition() {
$options = parent::option_definition();
return $options;
}
function render($values) {
$data = unserialize($values->{$this->field_alias});
$result = "";
if (is_array($data['attributes'])) {
$rows = array();
foreach ($data['attributes'] as $attribute => $option) {
$rows[] = t('@option', array('@attribute' => $attribute, '@option' => implode(', ', (array) $option)));
if (count($rows)) {
//Grab the value for the third attribute.
$result = $rows[2];
}
}
}
return $result;
}
}