Starting to get new attribute handlers set up.
Still a lot to do: - adding more handlers - ripping out the parts of uc_views that don't work with D7 - if needed, adding filters
This commit is contained in:
BIN
uc_views/.DS_Store
vendored
BIN
uc_views/.DS_Store
vendored
Binary file not shown.
@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Ubercart product list position handler.
|
||||
*/
|
||||
|
||||
class draggableviews_handler_ubercart extends draggableviews_handler {
|
||||
function init($field_name, &$view) {
|
||||
parent::init($field_name, $view);
|
||||
}
|
||||
|
||||
function save($nid, $value) {
|
||||
$node = node_load($nid);
|
||||
|
||||
switch ($this->type) {
|
||||
case 'order':
|
||||
db_query("UPDATE {uc_products} SET ordering = %d WHERE nid = %d AND vid = %d", $value, $node->nid, $node->vid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
BIN
uc_views/uc_views_attribute/.DS_Store
vendored
BIN
uc_views/uc_views_attribute/.DS_Store
vendored
Binary file not shown.
@ -14,4 +14,8 @@ files[] = views/uc_views_attribute_handler_field_order_product_attribute.inc
|
||||
files[] = views/uc_views_attribute_handler_field_combination.inc
|
||||
files[] = views/uc_views_attribute_handler_field_combination_price.inc
|
||||
files[] = views/uc_views_attribute_handler_filter_attr.inc
|
||||
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_attribute02.inc
|
||||
|
||||
|
@ -101,6 +101,30 @@ foreach($result as $row) {
|
||||
'handler' => 'uc_views_attribute_handler_field_order_product_attribute',
|
||||
),
|
||||
);
|
||||
|
||||
// Add viewhandler for uc_order_product attributes: Attribute 01
|
||||
$data['uc_order_products']['attributes01'] = array(
|
||||
'title' => t('Product attribute 01'),
|
||||
'help' => t('The first 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_attribute01',
|
||||
),
|
||||
);
|
||||
|
||||
// Add viewhandler for uc_order_product attributes: Attribute 02
|
||||
$data['uc_order_products']['attributes02'] = array(
|
||||
'title' => t('Product attribute 02'),
|
||||
'help' => t('The second 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_attribute02',
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// $Id: uc_views_attribute_handler_field_order_product_attribute.inc,v 1.1.2.2 2010/01/12 20:07:04 hanoii Exp $
|
||||
|
||||
/**
|
||||
* Field handler to provide a human-readable version of the selected combination of attributes
|
||||
*/
|
||||
class uc_views_attribute_handler_field_order_product_attribute01 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 = "heck yeah";
|
||||
if (is_array($data['attributes'])) {
|
||||
$result = 'even better';
|
||||
$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 first attribute.
|
||||
$result = $rows[0];
|
||||
//$result = theme('item_list', array('items' => $rows, 'title' => NULL, 'type' => 'ul', 'attributes' => array('class' => 'product-description')));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
// $Id: uc_views_attribute_handler_field_order_product_attribute.inc,v 1.1.2.2 2010/01/12 20:07:04 hanoii Exp $
|
||||
|
||||
/**
|
||||
* Field handler to provide a human-readable version of the selected combination of attributes
|
||||
*/
|
||||
class uc_views_attribute_handler_field_order_product_attribute02 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 = "heck yeah";
|
||||
if (is_array($data['attributes'])) {
|
||||
$result = 'even better';
|
||||
$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 second attribute.
|
||||
$result = $rows[1];
|
||||
//$result = theme('item_list', array('items' => $rows, 'title' => NULL, 'type' => 'ul', 'attributes' => array('class' => 'product-description')));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@ class uc_views_attribute_handler_filter_attr extends views_handler_filter_in_ope
|
||||
$this->value_title = t('Options');
|
||||
$result = db_query("SELECT name, oid FROM {uc_attribute_options} WHERE aid = :aid ORDER BY ordering", array(':aid' => $aid));
|
||||
|
||||
while ($row = db_fetch_object($result)) {
|
||||
foreach ($result as $row) {
|
||||
$options[$row->oid] = $row->name;
|
||||
}
|
||||
if (count($options) == 0) {
|
||||
|
@ -1,117 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Filter by attributes - by justindodge (original)
|
||||
* Modified to support product (not order) attributes plus inventory by jerry
|
||||
*/
|
||||
class uc_views_attribute_handler_filter_product_attr extends views_handler_filter_in_operator {
|
||||
|
||||
function has_extra_options() { return TRUE; }
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
|
||||
$options['type'] = array('default' => 'select');
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function get_value_options() {
|
||||
if (!isset($this->value_options)) {
|
||||
$aid = explode('_', $this->field);
|
||||
$aid = $aid[1];
|
||||
|
||||
$this->value_title = t('Options');
|
||||
$result = db_query("SELECT name, oid FROM {uc_attribute_options} WHERE aid = %d ORDER BY ordering", $aid);
|
||||
|
||||
while ($row = db_fetch_object($result)) {
|
||||
$options[$row->oid] = $row->name;
|
||||
}
|
||||
if (count($options) == 0) {
|
||||
$options[] = t('No options found.');
|
||||
}
|
||||
$this->value_options = $options;
|
||||
}
|
||||
}
|
||||
|
||||
function extra_options_form(&$form, &$form_state) {
|
||||
$form['type'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Selection type'),
|
||||
'#options' => array('select' => t('Checkboxes/Dropdown'), 'textfield' => t('Textfield')),
|
||||
'#default_value' => $this->options['type'],
|
||||
);
|
||||
}
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
parent::value_form($form, $form_state);
|
||||
if ($this->options['type'] == 'textfield') {
|
||||
$form['value'] = array (
|
||||
'#type' => 'textfield',
|
||||
'#title' => 'Text search',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function query() {
|
||||
$aid = explode('_', $this->field);
|
||||
$aid = $aid[1];
|
||||
|
||||
$this->ensure_my_table();
|
||||
$this->real_field = 'combination';
|
||||
$field = "{$this->table_alias}.{$this->real_field}";
|
||||
if ($this->operator == 'not in') {
|
||||
$not = 'NOT';
|
||||
}
|
||||
if(!is_array($this->value)) {
|
||||
$this->value = array($this->value);
|
||||
}
|
||||
$add = FALSE;
|
||||
$optval = array();
|
||||
foreach ($this->value as &$value) {
|
||||
if($this->options['type'] == 'textfield') {
|
||||
$optval[] = db_result(db_query("SELECT oid FROM {uc_attribute_options} WHERE UPPER(name) = UPPER('%s')", $value));
|
||||
}
|
||||
else {
|
||||
$optval[] = $value;
|
||||
}
|
||||
if (!empty($optval)) {
|
||||
$add = TRUE;
|
||||
}
|
||||
else {
|
||||
//If we let the query get added, only products with the attribute enabled & with the value of that attribute empty
|
||||
//will return. By default, I think it makes more sense to allow any product to return despite whether or not it
|
||||
//has the attribute if the user put nothing in to search for.
|
||||
//Adding a new type of filter that merely captures whether or not the attribute exists at all for the product may
|
||||
//be the best way to capture the alternative. Or, perhaps a config option could be added to this filter :
|
||||
//"Show products only if they have this attribute enabled". If this option is unchecked, a blank value returns all
|
||||
//products. If checked, a blank value at least filters out products that dont have this attribute available.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($add) {
|
||||
$match = '';
|
||||
foreach ($optval as &$oneopt) {
|
||||
$var = array($aid => $oneopt);
|
||||
$servar = serialize($var);
|
||||
$l = strpos($servar, '{') + 1;
|
||||
$r = strpos($servar, '}') - $l;
|
||||
$value = substr($servar, $l, $r);
|
||||
if (!empty($match)) {
|
||||
if ($this->operator == 'not in') {
|
||||
$match .= ' AND ';
|
||||
}
|
||||
else {
|
||||
$match .= ' OR ';
|
||||
}
|
||||
}
|
||||
$match .= "($field $not LIKE '%{$value}%')";
|
||||
}
|
||||
$this->query->add_where($this->options['group'], $match);
|
||||
if (is_null($this->query->get_table_info('uc_product_stock'))) {
|
||||
$stock_alias = $this->query->ensure_table('uc_product_stock');
|
||||
$this->query->add_where($this->options['group'], "{$stock_alias}.sku = {$this->table_alias}.model");
|
||||
$this->query->add_where($this->options['group'], "({$stock_alias}.active = 0) OR ({$stock_alias}.stock > 0)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
// $Id: uc_views_handler_field_order_id.inc,v 1.1.4.2 2010/12/15 02:16:37 longwave Exp $
|
||||
/**
|
||||
* @file
|
||||
* Contains the basic 'order' field handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Field handler to provide simple renderer that allows linking to the order adminstration page.
|
||||
*/
|
||||
class uc_views_handler_field_order_id extends views_handler_field {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['link_to_order'] = array('default' => FALSE);
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide link to order adminstration page
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['link_to_order'] = array(
|
||||
'#title' => t('Link this field to the order view.'),
|
||||
'#description' => t('The link will go to the admin view if the user has "view all orders" permission, or the user view if the order belongs to the current user and they have "view own orders" permission. This will override any other link you have set.'),
|
||||
'#type' => 'checkbox',
|
||||
'#default_value' => !empty($this->options['link_to_order']),
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
global $user;
|
||||
|
||||
$this->options['alter']['make_link'] = FALSE;
|
||||
|
||||
if (!empty($this->options['link_to_order']) && $values->{$this->field_alias}) {
|
||||
if (user_access('view all orders')) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = "admin/store/orders/" . $values->{$this->field_alias};
|
||||
}
|
||||
elseif ($values->{$this->aliases['uid']} == $user->uid && user_access('view own orders')) {
|
||||
$this->options['alter']['make_link'] = TRUE;
|
||||
$this->options['alter']['path'] = 'user/' . $user->uid . '/order/' . $values->{$this->field_alias};
|
||||
}
|
||||
}
|
||||
|
||||
return parent::render($values);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user