Attribute Views (Views Integration for uc_attributes)

Contrib type: 
Module
Status: 
Work in progress

Downloads

Latest version: 
0.3
Compatibility: 
Ubercart 1.x

I've written a Views integration for uc_attributes (it also requires uc_stock). Primary features include:

  • Field to show all options for a given attribute
  • Field to show all possible attribute option combinations
  • Field to show only those attribute option combinations that are in stock (aka above the threshold)
  • Filter on the availability of one or more options for a specific attribute (including only those options that are in stock).
  • Filter on the availability of a specific combination of product attribute options, with a form that shows options according to the attribute sort hierarchy.
  • Argument handler for attribute option availability that allows pass-through of a single option name or multiple option IDs in and/or fashion similar to Taxonomy argument handlers.

Known issues:

  • Summary view shows attribute options multiple times
  • NOR handling for attribute options filter is not complete

This has turned out to be kind of a tricky contribution to implement, so I'd definitely appreciate help that others can give in the form of testing, code contributions, or suggestions. Hopefully others will find these capabilities to be as useful as I expect them to be for me.

Updated Installation instructions:
Unzip the views_uc_attribute folder into modules/ubercart and go to Admin > Site Building > Modules to Activate the Attribute Views module.


PreviewAttachmentSize
views_uc_attribute.zip4.99 KB
NewZeal's picture
Offline
Joined: 04/18/2008
Juice: 56
Great module

This is a great module and works well, however I'm getting some sorting errors, such as:

* warning: uasort() [function.uasort]: Invalid comparison function in /home/tasmanit/public_html/SubDomains/dev7/modules/views_uc_attribute/views_uc_attribute/views_uc_attribute.module on line 318.
* warning: uasort() [function.uasort]: Invalid comparison function in /home/tasmanit/public_html/SubDomains/dev7/modules/views_uc_attribute/views_uc_attribute/views_uc_attribute.module on line 318.

All I'm doing at present is to disable these lines of code. I am using attributes to display products as small, medium and large. Current url is http://dev7.tasmanit.com/. Eventually it will be http://sentimenz.co.nz/.

zmove's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Internationalizationizer
Joined: 08/13/2007
Juice: 1195
Same error here : warning:

Same error here :

warning: uasort() [function.uasort]: Invalid comparison function in \sites\all\modules\ubercart\contrib\views_uc_attribute\views_uc_attribute.module on line 552.

Can we have some feedback from the author ?

doomed@drupal.org's picture
Offline
Bug Finder
Joined: 04/05/2008
Juice: 334
Re: Attribute Views (Views Integration for uc_attributes)

Whats the current status on this mod?

Is there a way of getting Views on Attributes ?

vivianspencer's picture
Offline
Joined: 01/13/2009
Juice: 27
Re: Attribute Views (Views Integration for uc_attributes)

I'm getting the same errors as described above, is there any progress with this module?

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Join forces?

I am maintaining a module for views support for Ubecart (http://drupal.org/project/uc_views and http://www.ubercart.org/contrib/9429).

I have not yet implemented support for attributes, so I was thinking that maybe we could merge our projects, if you are interested.

marinex's picture
Offline
Joined: 07/27/2009
Juice: 38
Maybe help to users that uses this module

warning: uasort() [function.uasort]: Invalid comparison function in ....

This error is due to missing _uc_attribute_sort function. So you need to add to end of module following code:

/**
* usort() callback.
*/
function _uc_attribute_sort($a, $b){
  if ($a->ordering == $b->ordering){
    return 0;
  }
  else{
    return ($a->ordering < $b->ordering) ? -1 : 1;
  }
}

You can see in the uc_attribute.module mentioned function on end of file.

I attach altered file of module as attachment Smiling

Marinex

AttachmentSize
views_uc_attribute.module.txt 23.06 KB
sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
Development

So this project seems a bit abandoned by the creator so I am going to start work on it.
My first goal is to upgrade it to work with uc2.
If you want to help I have created a public repo for it at http://github.com/sanguis/UberCart-Attribute-Views-/tree

JOsh

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

Hilyin's picture
Offline
Joined: 08/13/2009
Juice: 2
Re: Development

Great! I am looking for this functionality in my next project, thank you Josh!

sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
Developers Log one day in

So after one day I have gotten the module so that it will install.
How ever using the coder modules I have found the bellow list of things that need to be upgraded.
its is large and I would be great if people wanted to take chunks of these do I will push my changes to the repo often. Lets get this done.
____
#
Line 31: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'sortable' => false,

#
severity: normalLine 35: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'notafield' => true,

#
severity: normalLine 125: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'notafield' => true,

#
severity: normalLine 165: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'instock' => true,

#
severity: normalLine 174: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'notafield' => true,

#
severity: normalLine 175: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'instock' => true,

#
severity: normalLine 186: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'instock' => true

#
severity: normalLine 212: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'instock' => true

#
severity: normalLine 218: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

'instock' => true

#
severity: normalLine 231: Arrays should be formatted with a space separating each element and assignment operator

foreach ($form['filter'] as $key=>$filter) {

#
severity: normalLine 232: missing space after comma

if (strpos($filter['id']['#value'],'uc_product_adjustments') !== false) {

#
severity: normalLine 232: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

if (strpos($filter['id']['#value'],'uc_product_adjustments') !== false) {

#
severity: normalLine 234: missing space after comma

$default_option = explode(',',$default_option);

#
severity: normalLine 244: missing space after comma

if (strpos($filter['field'],'uc_product_adjustments') !== false) {

#
severity: normalLine 244: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

if (strpos($filter['field'],'uc_product_adjustments') !== false) {

#
severity: normalLine 267: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$filter_name = 'filter' . $key;

#
severity: normalLine 312: Control statements should have one space between the control keyword and opening parenthesis

foreach($sorted_options as $key=>$current) {

#
severity: normalLine 312: Arrays should be formatted with a space separating each element and assignment operator

foreach($sorted_options as $key=>$current) {

#
severity: normalLine 327: Arrays should be formatted with a space separating each element and assignment operator

foreach ($option_objarray as $key=>$combo_array) {

#
severity: normalLine 363: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

_views_uc_attribute_add_options(strtoupper($filter['operator']), $array, false, &$query);

#
severity: normalLine 382: Control statements should have one space between the control keyword and opening parenthesis

switch($op) {

#
severity: normalLine 384: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

$query->ensure_table('uc_attribute_options', true);

#
severity: normalLine 392: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

$query->ensure_table('uc_attributes', true);

#
severity: normalLine 431: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

function views_uc_attribute_option_form($attribute_list = array(), $multiple = true) {

#
severity: criticalLine 520: new hook_theme() function is required to register theme_ functions (Drupal Docs)

function theme_attribute_option_select($element) {

#
severity: normalLine 559: use a space between the closing parenthesis and the open bracket

while ($attr = db_fetch_object($result)){

#
severity: normalLine 582: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$choice->option = array(implode(',', $this_option) => str_repeat('-', $depth - 1) . ' ' . $option->name);

#
severity: normalLine 596: use a space between the closing parenthesis and the open bracket

function _views_uc_attribute_combination_sort($a, $b){

#
severity: normalLine 618: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

function _views_uc_attribute_add_options($op, $value, $instock = false, &$query) {

#
severity: normalLine 632: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where_sub = '(' . implode(' AND ', $where_sub) . ')';

#
severity: normalLine 637: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where = '((' . implode(' OR ', $where) . ') AND active = 1 AND stock > threshold)';

#
severity: normalLine 640: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where = '(' . implode(' OR ', $where) . ')';

#
severity: normalLine 658: Use uppercase for PHP constants, e.g. NULL, TRUE, FALSE

$num = $query->add_table('uc_product_adjustments', false, 1, $joininfo);

#
severity: normalLine 693: Use an indent of 2 spaces, with no tabs

$tablename = $query->get_table_name('uc_product_adjustments', $num);

#
severity: normalLine 702: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where_sub = '(' . implode(' AND ', $where_sub) . ')';

#
severity: normalLine 707: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where = '((' . implode(' AND ', $where) . ') AND active = 1 AND stock > threshold)';

#
severity: normalLine 710: string concatenation should be formatted without a space separating the operators (dot .) and a quote

$where = '(' . implode(' AND ', $where) . ')';

#
severity: normalLine 720: use a space between the closing parenthesis and the open bracket

function _uc_attribute_sort($a, $b){

#
severity: normalLine 721: use a space between the closing parenthesis and the open bracket

if ($a->ordering == $b->ordering){

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
syntax cleared now down to the real work

Line 518: new hook_theme() function is required to register theme_ functions (Drupal Docs)

function theme_attribute_option_select($element) {

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Great news! If you need help

Great news!

If you need help with this work please delegate, I should be able to find some time to help out - just let me know.

sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
the repo is open

I am relatively new to drupal module code and am doing this out of necessity. So if you need thsi module sooner then later pelase feel free to check what ever you need in.

JOsh

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

ddagradi's picture
Offline
Joined: 08/25/2009
Juice: 15
Quick fix for Ubercart 2

I needed to have attribute filtering for a client's site, so I wrote this fast module based on the work done with uc_views (http://drupal.org/project/uc_views)

It's a bare minimum implementation to get a drop-down filter for attributes, but it fits my use case. Hopefully some of y'all will find this helpful as well!

Let me know what issues crop up.

Dominic
http://beardedstudio.com

AttachmentSize
uc_attribute_view.zip 4.22 KB
selinav's picture
Offline
Joined: 08/17/2009
Juice: 155
Nice module ddagradi ! Is it

Nice module ddagradi !

Is it possible to you to add the 'product attributes' in the selection list of fields?
See the attached image.

Best regards

AttachmentSize
views.jpg 97.31 KB
madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
The repo is rather empty

@JOsh

I just cloned the github repo - but it seems to be rather empty - are you using another repo?

ddagradi's picture
Offline
Joined: 08/25/2009
Juice: 15
Re: Nice module ddagradi ! Is it

I'll give that a shot later on today. Hopefully it's as quick a fix as filters were.

sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
Re the repo is rather empty

@madsph
Um I am relatively new to git (a recent convert from svn. but it seems that my changes are being pushed in at git hub. but honestly I don't know what you would be getting a blank bunch of files.

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

sanguis's picture
Offline
Joined: 05/15/2009
Juice: 78
Time better served

So I have been working on this module (well not this week I got bogged down by other clients) but as I have gotten into it I think that some of the above comments and posts are right.
This would be a better merged with ucViews so I am going to take what I started here and start working on adding these functions to the module found at http://drupal.org/project/uc_views.

I guess this means that I am going to abandon the git repo (unless you guys have any ideas how I can make my work public for contribution)

Left Click Computers
www.sanguisdevelopment.com over 6 years of custom eCommerce experience
on irc I am sanguisdex

madsph's picture
Offline
Joined: 02/25/2009
Juice: 56
Re: Time better served

You are very welcome to join development of uc_views.

I have had quite a few requests for attribute support, so it will really be appreciated.

By the way - there is a discussion of this in the uc_views forum: http://drupal.org/node/449324

/madsph
maintainer of uc_views

doublejosh's picture
Offline
Joined: 09/26/2009
Juice: 55
Exposing as fields rather than used as filters

What would be necessary to expose attribute option values as view fields rather than used only as filters?

I'd love to have those values for use in the table format to do sortable dashboards.

Anyone accomplished this?

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Exposing as fields rather than used as filters

This is actually exactly what I am looking to accomplish. My table will be for administrative purposes so just showing the attribute sku, etc would really help!

ryanschmidt's picture
Offline
Joined: 11/17/2008
Juice: 235
Re: Re: Exposing as fields rather than used as filters

As an update, if anyone stumbles across this post: http://drupal.org/project/uc_views

That module has views that really helped!

melanie_me's picture
Offline
Joined: 03/29/2009
Juice: 109
Not compatible with 6.19

I'm currently running Drupal 6.19 and this module is not compatible with this version.

allabouttea's picture
Offline
Joined: 11/14/2010
Juice: 23
re Quick fix for Ubercart 2 - any progress?

Did you ever manage to implement this for fields as well as filters? it would be very useful.

toby53's picture
Offline
Joined: 01/23/2011
Juice: 39
Re: Attribute Views (Views Integration for uc_attributes)

I need to break out each individual attribute as a field so I can export the view's output to excel ?
I am getting a attributes field with all attributes in a list.
thanks

jddeli's picture
Offline
Joined: 11/15/2010
Juice: 38
Attribute views problem with attributes

i have a client that have a product salats and a attribute small, big. I cant show in my view the attribute prices.
I want to show
title - small - big - Buy it now button
salat mexikan - 10.00euro - 15.00 euro - buy now
How can show this

Covenant Web Design's picture
Offline
Joined: 01/09/2009
Juice: 132
This module merged into uc_views

Since this module is defunct, it was hard to find a replacement. Turns out uc_views now has uc_views_attributes as a submodule with exactly the attributes functionality I needed. I upgraded uc_views (had a 3.0-dev version) and voila - there are the attributes fields in Views!

Full thread here: http://drupal.org/node/449324#comment-2069478 (starting at comment where it was committed to project)

Hope that saves someone else some searching time!

Joshua

Joshua Stewardson
Client Consultant
Covenant Web Design

MarvicWebDesign's picture
Offline
Joined: 09/27/2012
Juice: 7
Who Bought What module

Hi all, I've been struggling for ages to get Views to include the attributes & options. This morning, I discovered a little gem of a module: Who Bought What, for Drupal versions 6 & 7(!)

http://drupal.org/project/uc_who_bought_what

A huge thank you to the developer!! Smiling

Living the Adventure. Guiding Online Adventures.
http://webdesign.marvic.biz/
http://www.website-laten-bouwen.nl/