From 806ee544ce40efe19302a98abcf94d1f59955ced Mon Sep 17 00:00:00 2001 From: mattbk Date: Tue, 6 Oct 2015 14:03:00 -0500 Subject: [PATCH] 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 --- uc_views/.DS_Store | Bin 6148 -> 0 bytes uc_views/draggableviews_handler_ubercart.inc | 22 ---- uc_views/uc_views_attribute/.DS_Store | Bin 6148 -> 0 bytes .../uc_views_attribute.info | 4 + .../views/uc_views_attribute.views.inc | 24 ++++ ...andler_field_order_product_attribute01.inc | 35 ++++++ ...andler_field_order_product_attribute02.inc | 35 ++++++ ...uc_views_attribute_handler_filter_attr.inc | 2 +- ..._attribute_handler_filter_product_attr.inc | 117 ------------------ .../views/uc_views_handler_field_order_id.inc | 49 -------- 10 files changed, 99 insertions(+), 189 deletions(-) delete mode 100644 uc_views/.DS_Store delete mode 100644 uc_views/draggableviews_handler_ubercart.inc delete mode 100644 uc_views/uc_views_attribute/.DS_Store create mode 100644 uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute01.inc create mode 100644 uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute02.inc delete mode 100644 uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_product_attr.inc diff --git a/uc_views/.DS_Store b/uc_views/.DS_Store deleted file mode 100644 index ee357bd7bb456187643fd760a25af6410406f47c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK%}T>S5T0$TMpOub=yCB}q(!9`JcLleqtHSRR%&7j4V0!di9N(;zCa{7S#^6;< z^cPLE_I*g<0oVLkT7LowEYaelH-U-2iWmMY@-hC+U(CWdX|+B?t=`z!+_F%1N5gO) zL@PH+=RthipGK>G7)*R`d8hQmOVZf&mdbPEB~$b$eGo-6)JG_o6A= z=iR(1vrebglxL@%Jl{sK->rk=lgsOYmp$drFPc_CJ0aQAui8Y|2IGr$Zm1Iz$1 zU~UX+hv{Gjm;q+s8v}GcNNj|T!9t@tIHa-f^wum$6%omJt#t_BI;CO zN(`aX(JoD#W3bSu(?OWxLzpjr6)!@49p{%S9E78hduD(cC^JykL!0jZEBs|Di~Mp5 zkC*{w;GZ!d8ohqc#Z8&J^~d(;u9evCv5`<*K?(}$rAGh`=o~pxPVJYZW1M5K&`7h8 SU8N)PLqHM29W(F?415A9b4Kw1 diff --git a/uc_views/draggableviews_handler_ubercart.inc b/uc_views/draggableviews_handler_ubercart.inc deleted file mode 100644 index 5b618e5..0000000 --- a/uc_views/draggableviews_handler_ubercart.inc +++ /dev/null @@ -1,22 +0,0 @@ -type) { - case 'order': - db_query("UPDATE {uc_products} SET ordering = %d WHERE nid = %d AND vid = %d", $value, $node->nid, $node->vid); - break; - } - } -} diff --git a/uc_views/uc_views_attribute/.DS_Store b/uc_views/uc_views_attribute/.DS_Store deleted file mode 100644 index 355158eefa1f36682e0bb28dbf304ac92c692365..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK&2Q936n}5C0h zX<#{Vp+!h-uZU7kmAF+%oH!vQPDlvBg$w@xS5EN8GpUGDt~9Frq?zBmule|mJ!1m^ z_SW2801N;ODiYI6sQMR?ep%*8N?Rmi+=nPN#AL}2OY>qAL&8A9z`|odzPqhZ2M;(j z;O+PKc4^Z0M3l=t!Bk7SboEx498^fNFY5XnN>ygp@pN__rkPnfu=2QFWUMCmY3@6b zSLc0B#6^*{30l)YIShuXyzcQvk+qi{zg(jre#rNSy&t(KltaH(3B+i`ry^+?6Ja$v z92-YH%9XYvTOspLO-5cAh%>w@2u;&?wrqJDYhUrf%2gkJvT56nu03D(jh4eog$I%N z)}>KSI3hYV$ph}5lj`9rr`pX6>T|?*O5D%?KzmTAs~+=#Q{m$>@MP$E-+SDB+_AcI z%|~m^%m{_?sgZ`{`m7_$JaE0>e4*|MujF&KxE-^m5l36=GZ|*E2ZmBNZy`0s{?_Ve z+cPF>VMB%)2k*?88P>{No!k8-?NyoyQ+fC9Bkv+MD7^frt( z)HBjR=0^KdwUry~oZeFdIw1=O;53Xu83KAdufWgn3tWXi;4iof_u(Ntf+z4CUcgIu z1+TFc+pq&WaV>s~>u@V>!|j;G&v7^I!F~7@?#F&SiUW8Y2QiOla1_tt7?zRad7MBG zs~BM&8#slR@G@S-YxpbvhQH%=yn#3IPrQY<)!b6EkKv%6s|LI?S6|qgUWAcZ*wajA zmoShp@Ef4 zw{)DXv8hm{1I8m$KYC=;e<&D_PIfB}2ecI?b;3Zxz+47el*;7&-~aCa|G7ztmN1Yo z@V{aJ(|yBzy|g5Kx6WIfylX8g-%*hw`uyqZcZD+6x;q7&wY diff --git a/uc_views/uc_views_attribute/uc_views_attribute.info b/uc_views/uc_views_attribute/uc_views_attribute.info index edca74b..01d70e2 100644 --- a/uc_views/uc_views_attribute/uc_views_attribute.info +++ b/uc_views/uc_views_attribute/uc_views_attribute.info @@ -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 diff --git a/uc_views/uc_views_attribute/views/uc_views_attribute.views.inc b/uc_views/uc_views_attribute/views/uc_views_attribute.views.inc index 40bd1fc..35af658 100644 --- a/uc_views/uc_views_attribute/views/uc_views_attribute.views.inc +++ b/uc_views/uc_views_attribute/views/uc_views_attribute.views.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; } diff --git a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute01.inc b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute01.inc new file mode 100644 index 0000000..69904b4 --- /dev/null +++ b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute01.inc @@ -0,0 +1,35 @@ +{$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; + } +} diff --git a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute02.inc b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute02.inc new file mode 100644 index 0000000..0a25c87 --- /dev/null +++ b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_field_order_product_attribute02.inc @@ -0,0 +1,35 @@ +{$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; + } +} diff --git a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_attr.inc b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_attr.inc index 350cf84..c1f22e6 100644 --- a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_attr.inc +++ b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_attr.inc @@ -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) { diff --git a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_product_attr.inc b/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_product_attr.inc deleted file mode 100644 index f2bd4fd..0000000 --- a/uc_views/uc_views_attribute/views/uc_views_attribute_handler_filter_product_attr.inc +++ /dev/null @@ -1,117 +0,0 @@ - '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)"); - } - } - } -} diff --git a/uc_views/views/uc_views_handler_field_order_id.inc b/uc_views/views/uc_views_handler_field_order_id.inc index 08b6fb2..e69de29 100644 --- a/uc_views/views/uc_views_handler_field_order_id.inc +++ b/uc_views/views/uc_views_handler_field_order_id.inc @@ -1,49 +0,0 @@ - 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); - } -}