Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

product_picker.js sku lookup actually works #1106

Conversation

jrochkind
Copy link
Contributor

@jrochkind jrochkind commented Apr 29, 2016

This is used in the backend UI for picking products for
Spree::Promotion::Rules::Product, might be used other places too.

There was code in there that looked like someone was trying to
let the query match a product name or sku. But it totally didn't work,
didn't do anything, was wrong in like two or three different ways. (useless ransack attribute name for sku; m has to be inside the q; value of m has to be lowercased or not OR).

Took me a couple hours to figure out what was going on, so I figured
I'd share the fix. Sorry, don't know how to test this, looks like
there aren't any tests for this kind of JS yet?

This is used in the backend UI for picking products for
Spree::Promotion::Rules::Product, might be used other places too.

There was code in there that looked like someone was trying to
let the query match a product name or sku. But it totally didn't work,
didn't do anything, was wrong in two different ways.

Took me a couple hours to figure out what was going on, so I figured
I'd share the fix. Sorry, don't know how to test this, looks like
there aren't any tests for this kind of JS yet?
@jhawthorn
Copy link
Contributor

jhawthorn commented Apr 29, 2016

Nice catch. Looks good to me 👍

For testing this we would normally use a feature test. There is a select2_search helper that can be used for this. IMO that isn't necessary here for this to get merged (but would always be appreciated).

@jrochkind
Copy link
Contributor Author

Thanks! Last time I looked the CI was failing although I couldn't figure out why; unrelated?

I also wonder if the sku lookup in this area should be exact match only, not partial match -- or they're going to be flooded with imprecise results after sku lookup actually works.

I suggest I add that before merging (I've done that in my local fix in my local app).

@cbrunsdon
Copy link
Contributor

I'm also good with this, thanks @jrochkind, looks like that would be pretty terrible to debug 👍

@jhawthorn
Copy link
Contributor

How about using sku_start? IMO that's the best compromise between wildcard on both ends and exact match.

@mamhoff
Copy link
Contributor

mamhoff commented May 3, 2016

This solution only looks for master variant SKUs. 👍 for `sku_start.

@jrochkind
Copy link
Contributor Author

Okay on sku_start.

Ah, true on the master variant only thing, that's a problem. Not sure how to solve that, I'll see if I can figure it out.

Keep in mind that at present, sku lookup simply does not work at all, it's not looking up skus.

@jrochkind
Copy link
Contributor Author

Okay, here's my stab at it.

Haven't really tested this. It probably needs automated tests, but I'm not sure I'm going to be able to do it.

@mamhoff
Copy link
Contributor

mamhoff commented May 3, 2016

You could test it with a feature spec that runs with JS enabled. Create two products, one with variants, and then check for the presence of the right variants in the select input.

@jrochkind
Copy link
Contributor Author

I'm not sure how to start here regarding specs. Can anyone suggest an existing feature spec I can model this off of?

Or is there anyone that wants to help by writing a feature spec?

Or do any committers want to @jhawthorn that a feature spec may not be required for a merge? (Although I realize things have turned out slightly more complicated since his comment to that effect).

I suspect the product_picker.js currently has no specs because it's kind of painful to write.

@jhawthorn
Copy link
Contributor

Thanks @jrochkind

I've created #1171 which adds some feature specs to test the fixed behaviour.

@jhawthorn jhawthorn merged commit 15c5f4c into solidusio:master May 20, 2016
@jrochkind jrochkind deleted the backend_product_picker_by_sku_should_work_ branch May 20, 2016 19:22
jhawthorn added a commit that referenced this pull request May 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants