Repository navigation
Add logo and favicon to stores - #6657
IslamElsayed wants to merge 3 commits into
Conversation
tvdeyen
left a comment
There was a problem hiding this comment.
I like the feature. Thanks for contributing.
But we should not add the extra complexity for the legacy paperclip adapter. The extra module that was extracted for that reason should not be necessary. Let's just add has_one_attached :logo and :favicon directly into the store model.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6657 +/- ##
==========================================
+ Coverage 92.46% 92.47% +0.01%
==========================================
Files 1058 1059 +1
Lines 21493 21527 +34
==========================================
+ Hits 19873 19907 +34
Misses 1620 1620 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@tvdeyen thanks, that makes sense. Done in 63cdfad: (I used AI assistance while working on this; I reviewed and tested the changes myself.) |
| <% end %> | ||
| <%= render component('ui/panel').new(title: t('.branding')) do |panel| %> | ||
| <% panel.with_section(class: "flex flex-col gap-4") do %> | ||
| <% %i[logo favicon].each do |attachment| %> |
There was a problem hiding this comment.
Render a component for each attachment separately. We can then remove the helper.
|
|
||
| # Only a saved attachment has a URL: after a failed save the form is shown | ||
| # again with a new file assigned but not stored yet. | ||
| def attachment_preview_url(name) |
There was a problem hiding this comment.
this helper takes every method name as an argument and simply sends it. it will fail if we call with anything different from the the attachment names. we dont need this helper if we render each attachment component separately.
| </div> | ||
| <% end %> | ||
| <% end %> | ||
| <%= render component('ui/panel').new(title: t('.branding')) do |panel| %> |
There was a problem hiding this comment.
we need a conditional for stores not using active storage. it will fail otherwise
| describe "logo and favicon" do | ||
| let(:admin_user) { create(:admin_user) } | ||
| let(:store) { create(:store, default: false) } | ||
| let(:image) { Rack::Test::UploadedFile.new(Spree::Core::Engine.root.join("lib/spree/testing_support/fixtures/blank.jpg"), "image/jpeg") } |
There was a problem hiding this comment.
there is a fixture_file_upload helper we could use.
| # hosted by a single Solidus implementation can be built. | ||
| # | ||
| class Store < Spree::Base | ||
| has_one_attached :logo |
There was a problem hiding this comment.
we need to safe guard these for stores not using active storage adapter. it will fail without active storage available
|
Thanks, all five are in 9ab97f0:
Specs pass with Active Storage and with |
AlistairNorman
left a comment
There was a problem hiding this comment.
Thanks for all the work on this. Can you clean up the commit history? It looks like there is a lot of code here that is added and then deleted in a later commit. That obscures the actual approach being taken here. Please use small and atomic commits that represent a coherent series of changes.
Stores can now have their own logo and favicon, so that each store of a multi-store setup can be branded differently. They are declared with has_one_attached and are only defined when images use the Active Storage adapter; Spree::Store.attachments_available? tells callers whether they exist.
2b331ae to
d9d7b38
Compare
|
Thanks @AlistairNorman, fair point. I've rebuilt the branch on current main as three commits:
The Paperclip variant and the merge commits are gone; the resulting diff is the same as before. (AI-assisted: prepared with Claude, reviewed by me.) |
tvdeyen
left a comment
There was a problem hiding this comment.
Thanks. One change and we should be ready
| <% end %> | ||
| <% end %> | ||
| <%# Only stores on the Active Storage adapter, with a Solidus that has them, have a logo and favicon. %> | ||
| <% if Spree::Store.reflect_on_attachment(:logo) %> |
There was a problem hiding this comment.
Why aren't we using Spree::Store.attachments_available? here as well?
| ] | ||
| # This check can be removed once we drop support for Solidus 4.7 and earlier. | ||
| permitted << {address_attributes: Spree::PermittedAttributes.address_attributes} if Spree::Store.reflect_on_association(:address) | ||
| permitted.push(:logo, :favicon) if Spree::Store.reflect_on_attachment(:logo) |
There was a problem hiding this comment.
Should we use Spree::Store.attachments_available? here as well?
The store form gets a file field for each attachment, showing the current image when there is one, and skips them when the store has no attachments. The form input component now accepts the file type, and the field component gets a file_field helper to render it.
The layout, header and footer use the current store's favicon and logo when it has them, and keep the Solidus ones otherwise.
d9d7b38 to
0904e82
Compare
|
Done: both now use (AI-assisted: prepared with Claude, reviewed by me.) |
jarednorman
left a comment
There was a problem hiding this comment.
I think this is good now.
|
@AlistairNorman the history is now three atomic commits (core, admin, storefront) as you asked. Could you take another look? The one red job ( (AI-assisted: drafted with Claude, reviewed by me.) |
Summary
Fixes #6092, with the scope agreed there with @jarednorman: a logo and a favicon per store, uploaded in
solidus_admin, and used by the storefront.Spree::Storedeclareshas_one_attached :logoandhas_one_attached :favicon, validated againstSpree::Config.allowed_image_mime_typeslike product images. There's no Paperclip variant and no change to the image adapter, soSpree::ImageandSpree::Taxonare untouched.solidus_admin: a "Logo and favicon" panel on the store form, with a file field for each and a thumbnail of the current image. The input component now allowstype: :file, and the field component gets afile_fieldhelper.Admin uploads only replace an image; there's no way to remove one yet. Happy to add that here or in a follow-up.
The first version added Paperclip support and split the Active Storage adapter to allow two attachments; that's been removed after @tvdeyen's review (63cdfad).
Tests: model specs for the attachments and their validation, request specs for the admin form and uploads, the admin stores feature spec, and storefront specs for the default and the store's images. I ran the core specs with Active Storage and with
DISABLE_ACTIVE_STORAGE=true, the admin specs, and the storefront specs in an app generated from this branch with the starter template.standardrbreports no offenses.I used an AI assistant while preparing this PR; I reviewed and tested the changes myself.
Checklist
I agree that my PR will be published under the same license as Solidus.
I have written a thorough PR description.
I have kept my commits small and atomic.
I have localized any and all user-facing strings that I added to the source code.
I have used clear, explanatory commit messages.
✅ I have added automated tests to cover my changes.