Getting image assets links using the API #4383
-
Hello. Hope you're doing well. I want to thank you for this great product. It's really awesome. I am building an ecommerce website with its own frontend so basically using Solidus API and Backend only. On the frontpage of the store website I wanna show the categories to allow customers to shop by category. I'm able to get the available categories (as Taxons) but the JSON response doesn't contain the icon of the taxon. Is there a way i could get this from the API request ? Otherwise how can I have this? Also is there a plan to provide this feature in the near future? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Starting from Solidus 3.1 (#4039), we can configure the JSON response attributes of API's endpoints (including the ones related to taxons) with a standard preference. In your Spree::Api::Config.configure do |config|
config.taxon_attributes += [ :api_icon_url ]
end And defining a new method on the taxon to retrieve the right size of the icon that you want to use: # app/overrides/your_store_name/spree/taxon/add_api_icon_url
module YourStoreName
module Spree
module Taxon
module AddApuIconUrl
def api_icon_url
icon.url(:small) # :or :original
end
::Spree::Taxon.prepend self
end
end
end
end which will be reflected in the corresponding jbuilder template. Please note that, the specific partial linked is also used elsewhere and depending on the attributes you'll add, it could cause some performance degradations of other endopoints as well. |
Beta Was this translation helpful? Give feedback.
-
Issue solved: it was the attachment issue. After attaching images to taxons it's working fine. Many thanks. |
Beta Was this translation helpful? Give feedback.
Starting from Solidus 3.1 (#4039), we can configure the JSON response attributes of API's endpoints (including the ones related to taxons) with a standard preference.
In your
config/initializers/spree.rb
, you can add the following:And defining a new method on the taxon to retrieve the right size of the icon that you want to use: