Skip to content

Commit

Permalink
Gift sticker packs to guests of non-changelog pods
Browse files Browse the repository at this point in the history
  • Loading branch information
jerodsanto committed Apr 22, 2024
1 parent c2ac81b commit 102771c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 27 deletions.
16 changes: 8 additions & 8 deletions lib/changelog/schema/episode/episode_guest.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Changelog.EpisodeGuest do
use Changelog.Schema

alias Changelog.{Episode, Merch, Person}
alias Changelog.{Episode, Merch, Person, Podcast}

schema "episode_guests" do
field :position, :integer
Expand Down Expand Up @@ -47,13 +47,9 @@ defmodule Changelog.EpisodeGuest do
podcast = episode_guest.episode.podcast

code =
if Changelog.Podcast.gives_free_shirt(podcast) do
case Merch.create_discount(thanks_code(episode_guest), "-30.0") do
{:ok, dc} -> dc.code
{:error, _} -> ""
end
else
""
case Merch.create_discount(thanks_code(episode_guest), discount(podcast)) do
{:ok, dc} -> dc.code
{:error, _} -> ""
end

episode_guest
Expand All @@ -67,6 +63,10 @@ defmodule Changelog.EpisodeGuest do
|> Repo.update()
end

defp discount(podcast) do
if Podcast.is_a_changelog_pod(podcast), do: "-30.0", else: "-10.0"
end

defp thanks_code(episode_guest) do
episode_guest = Repo.preload(episode_guest, :person)
handle = episode_guest.person.handle
Expand Down
2 changes: 0 additions & 2 deletions lib/changelog/schema/podcast/podcast.ex
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ defmodule Changelog.Podcast do
Enum.member?(~w(news podcast friends), podcast.slug)
end

def gives_free_shirt(podcast), do: is_a_changelog_pod(podcast)

def is_interviews(podcast), do: podcast.slug == "podcast" && !podcast.is_meta

def is_news(podcast), do: podcast.slug == "news"
Expand Down
6 changes: 4 additions & 2 deletions lib/changelog_web/templates/email/guest_thanks.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

<p>Are you aware of <a href="https://changelog.com/news">Changelog News</a>? It's our podcast + newsletter combo featuring all developer news worth your attention. Submit <a href="https://changelog.com/submit">right here</a> when you have future news/announcements. We'd be happy to help you spread the word.</p>

<%= if Changelog.Podcast.gives_free_shirt(@podcast) do %>
<h3>4. You get free merch 🎁</h3>

<%= if Changelog.StringKit.blank?(@discount_code) do %>
Expand All @@ -29,12 +28,15 @@
<p>This is our gift to you as a thanks for your time and all you do for the community.</p>

<ol>
<%= if Podcast.is_a_changelog_pod(@podcast) do %>
<li>Visit our <a href="https://merch.changelog.com" title="Changelog Merch Store">Merch Store</a></li>
<li>Pick a shirt you want (or anything really)</li>
<% else %>
<li>Grab some free stickers from our <a href="https://merch.changelog.com/products/changelog-sticker-pack" title="Changelog Merch Store">Merch Store</a></li>
<% end %>
<li>Use coupon code <mark><strong><%= @discount_code %></strong></mark> at checkout</li>
<li>Keep your order at $0 for free shipping!</li>
</ol>
<% end %>
<% end %>

<hr/>
Expand Down
7 changes: 5 additions & 2 deletions lib/changelog_web/templates/email/guest_thanks.text.eex
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,22 @@ Are you aware of Changelog News? It's our podcast + newsletter combo featuring a

Oh, and get it in your inbox weekly right here (https://changelog.com/news).

<%= if Podcast.gives_free_shirt(@podcast) do %>

#### 4. You get free merch ####
<%= if Changelog.StringKit.blank?(@discount_code) do %>
Dratz! Something's wrong with our Shopify integration! Hit reply and let us know</mark> so we can generate a coupon code for you.
<% else %>
This is our gift to you as a thanks for your time and all you do for the community.

<%= if Podcast.is_a_changelog_pod(@podcast) do %>
- Visit our Merch Store (https://merch.changelog.com)
- Pick a shirt you want (or anything really)
<% else %>
- Grab a sticker pack (https://merch.changelog.com/products/changelog-sticker-pack)
<% end %>
- Use coupon code <%= @discount_code %> at checkout
- Keep your order at $0 for free shipping!
<% end %>
<% end %>
---

That's all we have. You’re part of Changelog's family now. If there is any way that we can help you in the future, don’t hesitate to contact us.
Expand Down
4 changes: 3 additions & 1 deletion lib/changelog_web/templates/page/guest.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@
<ul>
<li>Receive an email when the show is published 📥</li>
<li>Help share and promote the episode 🗣</li>
<%= if Podcast.gives_free_shirt(@podcast) do %>
<%= if Podcast.is_a_changelog_pod(@podcast) do %>
<li>Get an awesome <a href="https://merch.changelog.com" title="Changelog Merch">t-shirt</a> as a thanks from us ✊</li>
<% else %>
<li>Get an awesome <a href="https://merch.changelog.com/products/changelog-sticker-pack" title="Changelog Sticker Pack">sticker pack</a> as a thanks from us ✊</li>
<% end %>
</ul>

Expand Down
12 changes: 0 additions & 12 deletions test/changelog/schema/episode/episode_guest_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,6 @@ defmodule Changelog.EpisodeGuestTest do
end
end

test "doesn't generate a coupon code when podcast doesn't give a free shirt" do
with_mock(Merch, create_discount: fn _, _ -> {:ok, %{code: "hai"}} end) do
podcast = insert(:podcast, slug: "gotime")
episode = insert(:episode, podcast: podcast)
eg = insert(:episode_guest, episode: episode)
{:ok, eg} = EpisodeGuest.thanks(eg)
assert eg.thanks
assert eg.discount_code == ""
refute called(Changelog.Merch.create_discount(:_, :_))
end
end

test "doesn't generate a duplicate discount code when already present" do
with_mock(Merch, create_discount: fn _, _ -> {:ok, %{code: "hai"}} end) do
eg = insert(:episode_guest, discount_code: "yup")
Expand Down

0 comments on commit 102771c

Please sign in to comment.