Hi,

I am developing a sports web store. I would like to be able to create a solr filter to let my users browse by color/size.

So far, I have developed a code that generate different SKU's for each product/color/size combination available. But now I'm stuck, and I don't know what to do next. I reckon the ability to index attributes would be a nice extension to this module. I am willing to put in the work and would appreciate some pointers.

I'm using Drupal 6.x / Ubercart / Views 3 / ApacheSolr Views / ApacheSolr Ubercart.

Cheers,
Joao

Comments

mrP’s picture

Category: task » feature

+1 on this.

I was going to give http://drupal.org/project/uc_attribute_cck a stab and see if I could index attributes in this round about way via CCK fields. Pretty good intro here (http://acquia.com/blog/understanding-apachesolr-cck-api) on working with CCK fields and Solr...seems like it could be doable.

If anyone has tried this, successfully or otherwise, chime in. I'll report what I turn up.

zkrebs’s picture

Subscribing. This would be really excellent. As far as I can tell, there's no way to browse through product attributes easily. Could I suggest that Apache Solr can know if the products are in stock or out of stock (per attribute - size)? This is useful, because if I want to say

Buy now, 10% off remaining medium Tshirts, I want to present a list of ones we actually have! If its out of stock, that's useful too, for backordering.

nick_vh’s picture

I'm not so familiar with product attributes but it seems trivial indeed. If someone could post me a .make file + db dump for a good usecase of attributes of product so we can all develop towards the same use case. This would prevent us from getting confused with eachother!

If someone likes to take a stab to this, please report back here

joe_pixelrow’s picture

Being able to use attribute options like size and color as a solr search filter would be so great!

zkrebs’s picture

Nick_VH, I have no idea how to make a .make file but if you gave me access to a dev site I'd be more than happy to create a standard ubercart attribute set up.

How about a tshirt store, with color and size as attributes applied to the product class, "Tshirt".

"Awesome" Tshirt - base price, $15.00
Colors: Blue, Red, Green, Orange, Purple
Size: Small, Medium, Large, Extra Large, Extra Extra Large

Product attribute adjustments

Small Blue - sb001
Medium Blue - mb001
Large Blue - lb001
Extra Large Blue - xlb001
Extra Extra Large Blue - xxlb001

Stock *important part of filtering*

sb001 - 20
mb001 - 0
lb001 - 2
xlb001 - 3
xxlb001 - 5

Price Adjustments -

sb001 - 0
mb001 -0
lb001 - 0
xlb001 - 2.50
xxlb001 - 3.00

And so on and so forth.

If I could see a listing of all tshirts first, then with filtering options:

TYPE: TSHIRT
SIZE
COLOR
STOCK - In Stock / Out of Stock
PRICE: <$10 <$20 <30 etc.

Hope that helps?

mrP’s picture

StatusFileSize
new160.11 KB
new2.18 KB

Hey Nick_vh. If you get this working I'd totally throw in a bounty on it.

I've attached a simple .make file and a really basic database for a site. database/site passwords are in the make file.

What I've made is a three term taxonomy: products = shirt, shoes, pants

I made two attribute sets with three options each. One for shirt sizes (Small, Medium, and Large) and another for shirt colors (red, black, white). The "red shirt" is available in all sizes but only color red. The "small shirt" is available in all colors but only the small size.

This serves as a basic example of searching based on attributes. The goal with this is to be able to drill down on products based on which attributes are associated with a particular product node.

If you want something more complex I'll be happy to add more products or attributes.

@slavojzizek: price search facets already exist via http://drupal.org/project/apachesolr_ubercart. Stock is also separate from attributes and should probably be handled in a different feature request (unless of course Nick_vh is feeling ambitious :-) )

nick_vh’s picture

Sorry for replying too late - Working on this ;-)

nick_vh’s picture

StatusFileSize
new8.69 KB

First stab at this issue

Generates a block per attribute and fills the solr database with all the options that are used in the nodes (not in the system)
Indexes the option id but displays the human readable name for these options.

Let me know what you think

The patch also cleans up some code and a little bug I found

Ps : Using the database + make file previously added. I did have to enable some modules to make it a bit usable but no problems encountered. For possible problems, please upload a database with the generated data that is causing problems

zkrebs’s picture

sites/all/modules/apachesolr_ubercart$ patch -p0 < 947584-apachesolr_ubercart.patch
patching file apachesolr_ubercart.module
Hunk #1 FAILED at 1.
Hunk #2 FAILED at 40.
Hunk #3 succeeded at 73 (offset -10 lines).
Hunk #4 succeeded at 113 (offset -10 lines).
Hunk #5 succeeded at 124 with fuzz 2 (offset -15 lines).
Hunk #6 FAILED at 167.
Hunk #7 succeeded at 163 with fuzz 2 (offset -18 lines).
Hunk #8 FAILED at 214.
Hunk #9 FAILED at 253.
Hunk #10 FAILED at 263.
Hunk #11 FAILED at 368.
Hunk #12 succeeded at 267 with fuzz 2 (offset -138 lines).
7 out of 12 hunks FAILED -- saving rejects to file apachesolr_ubercart.module.rej

with the recent DEV - ideas?

nick_vh’s picture

Please patch to the HEAD version, not the DEV :)
No problems here while patching

patch -p0 < nameofpatch.patch

zkrebs’s picture

Where do I get that? Is that the 1.2 version? Sorry, n00b question.

nick_vh’s picture

Please look here for detailed instructions :-)

http://drupal.org/project/apachesolr_ubercart/cvs-instructions OR http://drupal.org/node/290118/cvs-instructions/HEAD

In attachment you can find the complete .module file so you can try it out that way also.

mrP’s picture

Thanks for putting this together! I'm just getting around to testing this out and it seems that HEAD is r1.11 and patch is for 1.10. Did you apply this patch to HEAD already?

Also, when working with the HEAD version, I've been getting a couple of errors:
(1) Recoverable fatal error: Object of class stdClass could not be converted to string in theme_status_messages() (line 1168 of .../includes/theme.inc).
(2) Fatal error: Call to undefined function dsm() in .../modules/contrib/apachesolr_ubercart/apachesolr_ubercart.module

For (2) I changed the call to dsm() to drupal_set_message() and resolved the error message. However, the blocks page and admin/settings/apachesolr/enabled-filters are inaccessible when the module is enabled. (1) also disappears when the module is disabled.

mrP’s picture

FYI to others testing, current HEAD (as of v 1.11 2011/02/04) already has patch in #8 applied.

mrP’s picture

@Nick_vh: My .make file capabilities wane at install profiles... I did think that there was two products in the database already. Was this not the case?

nick_vh’s picture

Sorry for delayed reply. I indeed committed this to HEAD as it seemed bit more reasonable for testing purposes.
I removed the "DSM call" and committed this to HEAD (no need for separate patch I suppose)

About the fatal error - could you be so kind to investigate where this comes from because on the install profile/make file you supplied I do not have this error. Also the enabled-filters are working as expected here so I do not completely understand the cause of the problem.

nick_vh’s picture

FYI : dsm is a function used by the devel module for debugging purposes. By renaming this to drupal_set_message will cause conflicts since drupal_set_message is not able to print array or objects of any kind. This explains the 2 error messages.

Recent head ships without this so please download and test this version.

mrP’s picture

Status: Active » Needs review

This is absolutely awesome! Works perfectly.

I'm marking as needs review to see if someone else can try it out. Shoot me a paypal email and I'll throw you some bounty.

melon’s picture

I applied the patch manually in 6.x-1.2 and it's working great for me also. Thanks for this feature.

melon’s picture

I just found that the only the attribute option oid value is shown in the apachesolr breadcrumb.
You can add this code to enable themed output of the attribute option name in the breadcrumb:


/**
 * Implementation of hook_apachesolr_theme_breadcrumb_alter().
 */
function apachesolr_ubercart_apachesolr_theme_breadcrumb_alter(&$fieldname) {
  $matches = preg_split('/_sm_uc_attribute_/', $fieldname);
  if (isset($matches[1])) {
    $fieldname = 'apachesolr_ubercart_breadcrumb_uc_attribute_option';
  }
}

/**
 * Implementation of hook_theme().
 */
function apachesolr_ubercart_theme() {
  return array(
    'apachesolr_ubercart_breadcrumb_uc_attribute_option' => array(
      'arguments' => array('field' => NULL),
    ),
  );
}

/**
 * Return the human readable value of an attribute option.
 */
function theme_apachesolr_ubercart_breadcrumb_uc_attribute_option($field) {
  $option = uc_attribute_option_load($field['#value']);
	return $option->name;
}
mrP’s picture

Very nice!! thanks melon

nick_vh’s picture

StatusFileSize
new16.11 KB

Finally some work with this. Did a diff on the latest dev version. Seems that I made some mistakes before

nick_vh’s picture

StatusFileSize
new16.05 KB

Latest one, also tested

nick_vh’s picture

Status: Needs review » Fixed

Committed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.