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: Cart attach to Shopper #977

Merged
merged 2 commits into from
Dec 8, 2022

Conversation

KellyAH
Copy link
Contributor

@KellyAH KellyAH commented Dec 8, 2022

#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.

KellyAH and others added 2 commits December 7, 2022 18:06
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 %>
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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

@KellyAH KellyAH self-assigned this Dec 8, 2022
Copy link
Member

@anaulin anaulin left a comment

Choose a reason for hiding this comment

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

LGTM 🚢

@KellyAH KellyAH merged commit 07cd651 into main Dec 8, 2022
@KellyAH KellyAH deleted the attach-marketplace-to-person-not-cart branch December 8, 2022 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants