Open vbujas opened 1 year ago
Currently I am not using the API / vue / nextjs functionality, only the legacy frontend. I'm a little short on time right now to check this myself, although I will be happy to review and merge a pull request with a fix.
I think the problem is coming from the get_taxons method here: https://github.com/spree/spree/blob/main/core/app/models/concerns/spree/product_scopes.rb#L342
It's the only place I can find that generates this query. That is in main branch, not necessarily the same as in 4.4. In the 4.3. version the query was written differently (and I think would work in this case, I'm not sure about the new Arel version, might work or might not):
Taxon.find_by(name: t) ||
Taxon.where("#{taxons}.permalink LIKE ? OR #{taxons}.permalink = ?", "%/#{t}/", "#{t}/").first
So fixing this would probably require a decorator for Spree::Product which overrides the get_taxons method with a fixed version.
Thanks a lot for the answer!
I came to the same conclusion the other day.
In my version of spree (4.4.0 , downloaded with spree starter kit.) that query is written like this:
Taxon.where(name: t).or(Taxon.where(id: t)).or(Taxon.where("permalink LIKE ? OR permalink = ?", "%/#{t}/", "#{t}/")).first
my workarrond was to rewrite the query like this:
Taxon.where(name: t).or(Taxon.where(id: t)).or(Taxon.where("spree_taxons.permalink LIKE ? OR spree_taxons.permalink = ?", "%/#{t}/", "#{t}/")).first
and it worked, but It is certainly better to write it like you suggested above.
I will test it and let you know.
@vbujas cool, let me know what you find. I suggest to try the version from main branch first: https://github.com/spree/spree/blob/main/core/app/models/concerns/spree/product_scopes.rb#L342 I think it might work, then you only need to backport that into your 4.4.x.
steps to reproduce.
install spree 4.4.0 install spree mobility run next.js commerce storefront.
tested with pg and mysql on new installs.
there is a internal server error (500) when executing the following query which is due to the fact that permalink column is not prefixed with its table.
I also get a bunch of unpermitted parameters errors all over the rails console like those below:
Unpermitted parameters: :image_transformation, :product Unpermitted parameter: :taxon Unpermitted parameters: :image_transformation, :product
Can you help on this one ?