-
-
Notifications
You must be signed in to change notification settings - Fork 20
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: Cart attach to Shopper #977
Conversation
Co-authored-by: Zee Spencer <[email protected]> Co-authored-by: Ana <[email protected]>
Co-authored-by: Zee Spencer <[email protected]> Co-authored-by: Ana <[email protected]>
Marketplace::Shopper.find_or_create_by(id: session[:current_cart] ||= SecureRandom.uuid) | ||
else | ||
Marketplace::Shopper.find_or_create_by(person: current_person) | ||
end %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine for now, but it feels like this might want to eventually live in a controller helper method, instead of the template (and maybe also the cart?). It just seems like a fair amount of non-trivial logic to have in a view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried moving this to a helper in app/furniture/marketplace/marketplaces_controller.rb
but it forced me to repeat the partial _marketplace.html.erb
which is used in at least 3 controllers. This would lead to a lot of duplicate code.
@anaulin @zspencer Should I just move it to application helper like below or leave the code as in _marketplace.html.erb
.
module ApplicationHelper
def shopper
params = if current_person.is_a?(Guest)
{id: session[:current_cart] ||= SecureRandom.uuid}
else
{person: current_person}
end
Marketplace::Shopper.find_or_create_by(params)
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting it in the ApplicationHelper
would take over the name shopper
in all execution contexts; which seems less than ideal.
WHAT IF!
We generated a MarketplaceComponent
that takes an instance of a Marketplace::Marketplace
and exposes a shopper
method? It could access current_person
and session
through the Helpers Proxy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚢
#831
When there were multi Marketplaces in a neighborhood, the page would crash. Now the Cart is attached to a Shopper which prevents the conflict of trying to find the Cart by the same Id across Marketplaces.