Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌸✨ Marketplace: Seller may add Photo to Product #1441

Merged
merged 1 commit into from
May 6, 2023

Conversation

anaulin
Copy link
Member

@anaulin anaulin commented May 5, 2023

This adds very basic support for adding photos to a Marketplace::Product, including:

  • ability to upload a photo to the product
  • the Active Storage blob filename is automatically prepended with the space.id
    • I tried making it into what S3 will consider a "folder", turning the filename into space.id/<filename>, but the default Active Storage behavior is to strip all directories, so that didn't work
  • adds vips image library installation as part of setup

WIP screenshots

image

image

Still todo:

  • display uploaded image in the cart / user-facing marketplace
  • correctly display the existing image in the product form when editing an existing product
  • decide if we want to automatically resize photos to a certain maximum size
  • add tests

return unless photo.attached? && photo.blob.persisted?
return if photo.blob.filename.to_s.start_with?(space.id.to_s)

new_name = "#{space.id}-#{photo.blob.filename}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out that my naive approach to make this space.id/... didn't work, because Active Storage strips out the directories.

@zspencer is pre-pending the filenames with the space id (but having all files be together in the bucket) enough for our needs right now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, I still think bucket-per-space is a better strategy for segmenting data but I can live with prefixing with space-id for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PS. If we end up going with this approach, and liking it, I imagine that this callback method could be extracted into a module to be shared by any model that has attachments.

Copy link
Member

@zspencer zspencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

V exciting! Thank you!

return unless photo.attached? && photo.blob.persisted?
return if photo.blob.filename.to_s.start_with?(space.id.to_s)

new_name = "#{space.id}-#{photo.blob.filename}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, I still think bucket-per-space is a better strategy for segmenting data but I can live with prefixing with space-id for now.

@zspencer zspencer added ✨ feature Reduces Client's Burden or Grants them Benefits 🌸 Polish Improves the UX! labels May 6, 2023
@zspencer zspencer changed the title Marketplace: Add basic support for Product photos 🌸✨ Marketplace: Add basic support for Product photos May 6, 2023
@anaulin
Copy link
Member Author

anaulin commented May 6, 2023

I probably won't be able to move this forward until next Wednesday's ensemble. If anyone else feels like picking up this PR and moving it forward before then, please feel free!

@zspencer
Copy link
Member

zspencer commented May 6, 2023

For now, I'm thinking we take the photos as the maximum size they are; and we add variants on a per-location basis. I'm not sure if this is a long-term good idea; but in the near term it should give us flexibility for figuring out what the sizing should be.

@zspencer zspencer changed the title 🌸✨ Marketplace: Add basic support for Product photos 🌸✨ Marketplace: Seller may add Photo to Product May 6, 2023
@zspencer zspencer marked this pull request as ready for review May 6, 2023 20:20
@zspencer
Copy link
Member

zspencer commented May 6, 2023

I have a set of PRs that are ready to merge into this that fulfill the remaining checkboxes. @anaulin - Do you want to review / merge them before we merge this or can I merge this now?

@anaulin
Copy link
Member Author

anaulin commented May 6, 2023

@zspencer brilliant! feel free to merge ALL the things!

Copy link
Member

@zspencer zspencer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approooooove

@zspencer zspencer merged commit 229034e into main May 6, 2023
@zspencer zspencer deleted the au/product-photos--1428 branch May 6, 2023 22:30
@zspencer zspencer added this to the 1.0 - Andromeda milestone May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature Reduces Client's Burden or Grants them Benefits 🌸 Polish Improves the UX!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants