Skip to content

Commit

Permalink
Fixed mail issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kk-ketan committed Dec 2, 2024
1 parent b5b9bc2 commit 1b2cc91
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
6 changes: 3 additions & 3 deletions app/jobs/spree_gift_card/send_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class SendEmailJob < ApplicationJob
queue_as :gift_card

def perform(gift_card_id)
gift_card = Spree::GiftCard.find_by(id: gift_card_id)
gift_card = ::Spree::GiftCard.find_by(id: gift_card_id)

if gift_card.present?
order_id = gift_card.line_item.order.id

Spree::OrderMailer.gift_card_receiver(gift_card.id, order_id).deliver_later
Spree::OrderMailer.gift_card_sender(gift_card.id, order_id).deliver_later
::Spree::OrderMailer.gift_card_receiver(gift_card.id, order_id).deliver_later
::Spree::OrderMailer.gift_card_sender(gift_card.id, order_id).deliver_later
end
end
end
Expand Down
33 changes: 0 additions & 33 deletions app/mailers/spree/order_mailer_decorator.rb

This file was deleted.

35 changes: 35 additions & 0 deletions app/mailers/spree_gift_card/spree/order_mailer_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module SpreeGiftCard
module Spree
module OrderMailerDecorator
def gift_card_receiver(card_id, order_id)
@gift_card = ::Spree::GiftCard.find_by(id: card_id)
@order = ::Spree::Order.find_by(id: order_id)
subject = "#{::Spree::Store.current.name} #{::Spree.t('gift_card_email.subject')}"
@gift_card.update_columns(sent_at: Time.now, gift_card_notified: true)

mail(
to: @gift_card.email,
from: from_address,
subject: subject
)
end

def gift_card_sender(card_id, order_id)
@gift_card = ::Spree::GiftCard.find_by(id: card_id)
return unless @gift_card.sender_email

@order = ::Spree::Order.find_by(id: order_id)
subject = "#{::Spree::Store.current.name} Notification! Gift Card delivered!"
mail(
to: @gift_card.sender_email,
from: from_address,
subject: subject
)
end
end
end
end

::Spree::OrderMailer.prepend SpreeGiftCard::Spree::OrderMailerDecorator
2 changes: 1 addition & 1 deletion app/models/spree_gift_card/order_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def gift_card_notification

if gift_cards.present? && !gift_card_notified
gift_cards.each do |gift_card|
SpreeGiftCard::SendEmailJob.set(wait_until: gift_card&.delivery_on).perform_later(gift_card.id)
::SpreeGiftCard::SendEmailJob.set(wait_until: gift_card&.delivery_on).perform_later(gift_card.id)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/spree_gift_card.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace :gift_cards do
desc 'Sends outstanding gift card emails'
task send: :environment do
SpreeGiftCard::SendEmailJob.perform_now
::SpreeGiftCard::SendEmailJob.perform_now
end
end

0 comments on commit 1b2cc91

Please sign in to comment.