openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.1k stars 713 forks source link

Filtering product by supplier property breaks when enterprise has custom sorting by category set #12656

Closed mkllnk closed 1 month ago

mkllnk commented 1 month ago

Description

When looking at a shop, customer have the ability to filter products by product category, supplier property or product property using the the "tag" under "filter by" on the left hand side of the page.

In the specific scenario where a supplier as set a custom sorting by category, filtering by supplier property doesn't work. When clicking on a supplier property, the "tag" will be selected, but the filtering won't happen and the loading products spinner never disappear. The bug can be reproduced here : https://staging.openfoodnetwork.org.au/noname-hub/shop when filtering by "Free Range"

This was introduced by the Product refactor

Expected Behavior

Only product inheriting "Free Range" supplier property should be displayed

filter_bug_expectedl

Actual Behaviour

All product are shown, no filtering is happening and Loading products spinner doesn't disappear. There is a request returning a 422 error (see bugsnag below)

filter_bug_actual

Steps to Reproduce

As a enterprise manager

  1. Go to the shop setting, and select "shop preferences" on the left hand side menu
  2. Set "Display ordering in shopfront" to "By category" and select one or more categories and save change
  3. Now select "Properites" on the left hand side menu
  4. Add a property
  5. Go to the "Products" page and choose a product
  6. Add a property to the product and tick "Inherit properties from ", and update

As a customer

  1. Navigate to the shop page 2.Try to filter by the supplier property added above -> filtering doesn't work

Error in Coopcircuits

ActiveRecord::StatementInvalid in api/v0/order_cycles#products PG::UndefinedColumn: ERROR: column first_variant.supplier_id does not exist LINE 4: ...t.product_id JOIN enterprises ON enterprises.id = first_vari... ^

View on Bugsnag

Another one on AU prod: https://app.bugsnag.com/yaycode/openfoodnetwork-aus/errors/668cc120963f0b000858abbf?event_id=668dd06e00efe4c55a620000&i=sk&m=nw

Stacktrace

app/services/products_renderer.rb:91 - filter
app/services/products_renderer.rb:41 - products
app/services/products_renderer.rb:20 - products_json
app/controllers/api/v0/order_cycles_controller.rb:26 - products

View full stacktrace

Created by Coopcircuits Admin via Bugsnag

Workaround

Can still browse product it just less convenient to not be able to filter.

Severity

bug-s3: a feature is broken but there is a workaround

cyrillefr commented 1 month ago

Hello @mkllnk , @filipefurtad0 , @sigmundpetersen , @RachL

May I work on this issue ? (Sorry for the multiple ping, but I guess some of you might enjoy well deserved holidays and I do not know which account I should ping).

RachL commented 1 month ago

@cyrillefr FYI you can use groups @openfoodfoundation/core-devs for devs and @openfoodfoundation/train-drivers-product-owners for PO in doubt ;)

Yes please go ahead I will assign you, many thanks!

rioug commented 1 month ago

@cyrillefr this one is tricky I think. Let me know if you need some help.

cyrillefr commented 1 month ago

Hello @rioug ,

Thanks for your help. I have just uploaded some code and indeed I would need your feedback.(I will made another comment on PR).