Hot questions for Using Spree in taxonomy
I am trying to generate a Spree Commerce taxonomy programmatically within a Ruby script (a la seeds.rb). In the customer-facing product pages the Taxons appear, but they do not work from the Admin pages.
- The "tree" view of the Taxonomy shows the root node, but no children
- On the product edit page, I cannot add any of my Taxons
Here's an example:
taxonomy_stones = Spree::Taxonomy.where(:name => 'Gemstone Type').first_or_create tax_stones = Spree::Taxon.where(name: "Gemstone", parent: nil, taxonomy: taxonomy_stones).first_or_create tax_diamond = Spree::Taxon.where(name: "Diamond", parent: tax_stones, taxonomy: taxonomy_stones).first_or_create tax_fancy_yellow = Spree::Taxon.where(name: "Fancy Yellow Diamond", parent: tax_diamond, taxonomy: taxonomy_stones).first_or_create tax_fancy_pink = Spree::Taxon.where(name: "Fancy Pink Diamond", parent: tax_diamond, taxonomy: taxonomy_stones).first_or_create
When I run this, entries appear in the database for my Taxonomy and Taxons. I am able to programmatically associate Products to the Taxons:
product_BL212.taxons << tax_diamond
I'm guessing that my Taxon-creation code is incomplete or incorrect in some way, but I am not sure how. Can anyone who is more familiar with Spree's internals provide an example of doing this correctly?
I used the Admin UI to create sample Taxonomies and have compared the database entries to my generated ones. The
permalink fields in
spree_taxons are blank for my generated Taxons, but not the Spree-created ones. When I manually populated some of the values for the root node and two sample children, the taxonomy/taxons still don't work correctly in Admin.
Is it important to have these values populated in
spree_taxons_translations has the needed information?
If so, how do I get Spree to populate the values for these fields correctly?
Spree::Taxon.rebuild! after adding the Taxons resolves the issue.
According to documentation [https://guides.spreecommerce.com/user/configuring_taxonomies.html] I am supposed to see a taxonomies menu under the admin lateral menu, however I am not seeing anything.
Should I do something to enable it?
It is in the "Products" section:
We are developing eCommerce website using Spree, the categories link getting like /t/brand/ruby.
But we have to remove /t on taxon.
Thanks Thiyagarajan Veluchamy
I am able to do.
add following code into routes.rb
get '*id', :to => 'spree/taxons#show', :as => :categories
add following code into app/helpers/spree/base_helper_decorator.rb
Spree::BaseHelper.module_eval do def seo_url(taxon) # return spree.nested_taxons_path(taxon.permalink) return main_app.categories_path(taxon.permalink) end end
Now you can see, without /t
How to get all taxons that are children of a certain taxonomy.
I retrieve the taxonomy like this:
A Spree::Taxonomy has_many :taxons so you should be able to do:
I have a spree store in production and every time I add a taxon to the taxon tree, it only shows up in the frontend after I run
bundle exec rake tmp:clear.
While I would like to maintain the caching in Spree, this shouldn't be the normal behaviour.
I searched in Google but couldn't find any relevant information on the matter. Searched through Spree preferences and couldn't find any useful information as well.
Summing up, what I would like to know is how can I display the new taxons immediately in the frontend without having to clear the the application cache in the console?
After going through the error with @gmacdougall found out it was a bug in Spree that was causing this problem.
If you're having the same problem you can follow the resolution here: https://github.com/spree/spree/issues/5810