Skip to content

Commit

Permalink
Merge pull request #1 from spree-edge/4-6-stable
Browse files Browse the repository at this point in the history
Spree Dynamic email compatible with spree 4.6
  • Loading branch information
rahul-bash authored Dec 4, 2024
2 parents 150bc51 + 0279576 commit d722d07
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/jobs/email_send_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def recepients(template, id)
emails = @campaign.send(rule) if rule.present?
emails = @campaign&.to&.split(',') unless emails.present?
emails&.each do |to|
response = template.mailer_class.constantize.send(template.template_name, template.record, id: template.id,
email_to: to).deliver_now
response = template.mailer_class.constantize.send(template.template_name, template.record, false, template.id,
to).deliver_now
create_log(response)
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/spree/custom_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class CustomMailer < ::Spree::BaseMailer
def custom_email(resend = false, test: false, id: nil, email_to: nil)
def custom_email(record=nil, test=false, id=nil, email_to=nil)
@test_mail = test
find_template(id)
email = email_to
Expand Down
6 changes: 3 additions & 3 deletions app/mailers/spree/order_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class OrderMailer < ::Spree::BaseMailer
def confirm_email(order, resend = false, test: false, id: nil, email_to: nil)
def confirm_email(order, test=false, id=nil, email_to=nil)
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order)
@test_mail = test
current_store = @order.store
Expand All @@ -11,7 +11,7 @@ def confirm_email(order, resend = false, test: false, id: nil, email_to: nil)
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url)
end

def store_owner_notification_email(order, test: false, id: nil, email_to: nil)
def store_owner_notification_email(order, test=false, id=nil, email_to=nil)
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order)
@test_mail = test
current_store = @order.store
Expand All @@ -20,7 +20,7 @@ def store_owner_notification_email(order, test: false, id: nil, email_to: nil)
mail(to: email, from: from_address, subject: @subject, store_url: current_store.url)
end

def cancel_email(order, resend = false, test: false, id: nil, email_to: nil)
def cancel_email(order, test=false, id=nil, email_to=nil)
@order = order.respond_to?(:id) ? order : ::Spree::Order.find(order)
@test_mail = test
current_store = @order.store
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/spree/reimbursement_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class ReimbursementMailer < BaseMailer
def reimbursement_email(reimbursement, resend = false, test: false, id: nil, email_to: nil)
def reimbursement_email(reimbursement, test=false, id=nil, email_to=nil)
@reimbursement = reimbursement.respond_to?(:id) ? reimbursement : Spree::Reimbursement.find(reimbursement)
@test_mail = test
@order = @reimbursement.order
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/spree/return_authorization_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class ReturnAuthorizationMailer < BaseMailer
def return_authorization_email(return_authorization, test = false, id: nil, email_to: nil)
def return_authorization_email(return_authorization, test= false, id= nil, email_to=nil)
@return_authorization = return_authorization.respond_to?(:id) ? return_authorization : Spree::ReturnAuthorization.find(return_authorization)
@test_mail = test
@order = @return_authorization.order
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/spree/shipment_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
class ShipmentMailer < BaseMailer
def shipped_email(shipment, resend = false, test: false, id: nil, email_to: nil)
def shipped_email(shipment, test=false, id=nil, email_to=nil)
@shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment)
@test_mail = test
@order = @shipment.order
Expand Down
2 changes: 1 addition & 1 deletion app/models/spree/email_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def render_body(resource, options)
end

def send_mail
mailer_class.constantize.send(template_name, record, test: true, id: id).deliver_now
mailer_class.constantize.send(template_name, record, true, id, nil).deliver_now
end

def record
Expand Down
12 changes: 0 additions & 12 deletions app/overrides/spree/admin/add_mail_tab_to_main_menu.rb

This file was deleted.

99 changes: 99 additions & 0 deletions app/views/spree/admin/shared/_main_menu.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<nav class="pb-3 pt-lg-3 px-1">
<div class="text-right d-lg-none pl-3 py-2 border-bottom d-flex align-items-center">
<div class="d-flex flex-grow-1 text-primary"></div>
<button
id="sidebar-close"
class="btn btn-link d-flex"
type="button"
aria-expanded="false"
aria-label="Toggle navigation">
<%= svg_icon name: "cancel.svg", width: '20', height: '20', classes: 'p-0 m-0' %>
</button>
</div>

<ul class="nav nav-sidebar" id="sidebarDashboard">
<%= tab Spree.t('admin.home'), url: spree.admin_dashboard_path, match_path: '/dashboard', icon: 'house-door-fill.svg' %>
</ul>

<% if can? :admin, Spree::Order %>
<ul class="nav nav-sidebar" id="sidebarOrder">
<%= main_menu_tree Spree.t(:orders), icon: "inbox-fill.svg", sub_menu: "orders", url: "#sidebar-orders" %>
</ul>
<% end %>

<% if can?(:admin, Spree::ReturnAuthorization) || can?(:admin, Spree::CustomerReturn) %>
<ul class="nav nav-sidebar" id="sidebarReturn">
<%= main_menu_tree Spree.t(:returns), icon: "reply-fill.svg", sub_menu: "returns", url: "#sidebar-returns" %>
</ul>
<% end %>

<% if can? :admin, Spree::Product %>
<ul class="nav nav-sidebar" id="sidebarProduct">
<%= main_menu_tree Spree.t(:products), icon: "tags-fill.svg", sub_menu: "product", url: "#sidebar-product" %>
</ul>
<% end %>

<% if can?(:admin, Spree::StockLocation) || can?(:admin, Spree::StockTransfer) %>
<ul class="nav nav-sidebar" id="sidebarStock">
<%= main_menu_tree Spree.t(:stock), icon: "box-seam.svg", sub_menu: "stock", url: "#sidebar-stock" %>
</ul>
<% end %>

<% if can? :admin, Spree::Admin::ReportsController %>
<ul class="nav nav-sidebar" id="sidebarReport">
<%= tab *Spree::Backend::Configuration::REPORT_TABS, icon: 'pie-chart-fill.svg' %>
</ul>
<% end %>

<% if can? :admin, Spree::Promotion %>
<ul class="nav nav-sidebar" id="sidebarPromotion">
<%= main_menu_tree Spree.t(:promotions), icon: "percent.svg", sub_menu: "promotion", url: "#sidebar-promotions" %>
</ul>
<% end %>

<% if defined?(Spree::Vendor) && can?(:manage, Spree::Vendor) && can?(:index, Spree::Vendor) %>
<ul class="nav nav-sidebar" id="sidebarOrganizations">
<%= main_menu_tree Spree.t(:organizations), icon: "building.svg", sub_menu: "organizations", url: "#sidebar-organizations" %>
</ul>
<% end %>

<% if Spree.user_class && can?(:admin, Spree.user_class) %>
<ul class="nav nav-sidebar" id="sidebarUser">
<%= tab *Spree::Backend::Configuration::USER_TABS, url: spree.admin_users_path, icon: 'people-fill.svg' %>
</ul>
<% end %>

<% if can? :admin, Spree::Menu %>
<ul class="nav nav-sidebar" id="sidebarMenu">
<%= main_menu_tree Spree.t('admin.tab.content'), icon: "card-heading.svg", sub_menu: "content", url: "#sidebar-content" %>
</ul>
<% end %>

<% if can?(:admin, Spree::Webhooks::Subscriber) || can?(:admin, Spree::PaymentMethod) %>
<ul class="nav nav-sidebar" id="sidebarIntegrations">
<%= main_menu_tree Spree.t('admin.tab.integrations'), icon: "stack.svg", sub_menu: "integrations", url: "#sidebar-integrations" %>
</ul>
<% end %>

<% if can? :admin, Spree::OauthApplication %>
<ul class="nav nav-sidebar" id="sidebarApps">
<%= main_menu_tree Spree.t('admin.tab.apps'), icon: "terminal-fill.svg", sub_menu: "apps", url: "#sidebar-apps" %>
</ul>
<% end %>

<% if can? :admin, current_store %>
<ul class="nav nav-sidebar" id="sidebarEmail">
<%= main_menu_tree Spree.t(:email), icon: "envelope.svg", sub_menu: "template", url: "#sidebar-email" %>
</ul>
<% end %>

<% if can? :admin, current_store %>
<ul class="nav nav-sidebar" id="sidebarConfiguration">
<%= main_menu_tree Spree.t('admin.settings'), icon: "gear-fill.svg", sub_menu: "configuration", url: "#sidebar-configuration" %>
</ul>
<% elsif defined?(current_spree_vendor) && current_spree_vendor.present? %>
<ul class="nav nav-sidebar" id="sidebarConfiguration">
<%= main_menu_tree Spree.t('admin.settings'), icon: "gear-fill.svg", sub_menu: "vendor_configuration", url: "#sidebar-configuration" %>
</ul>
<% end %>
</nav>
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/sub_menu/_template.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ul id="sidebar-email" class="border-top bg-white collapse nav nav-pills nav-stacked" data-hook="email_settings">
<ul id="sidebar-email" class="bg-white collapse nav nav-pills nav-stacked" data-hook="email_settings">
<%= tab :email_templates, match_path: '/email_templates' %>
<%= tab :campaigns, match_path: '/campaigns' %>
</ul>
2 changes: 1 addition & 1 deletion lib/mailer_previews/custom_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

class CustomMailerPreview < ActionMailer::Preview
def custom_email
::Spree::CustomMailer.custom_email(id: params[:template_id])
::Spree::CustomMailer.custom_email(nil, false, params[:template_id], nil)
end
end
2 changes: 1 addition & 1 deletion spree_dynamic_emails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.requirements << 'none'

s.add_dependency 'spree', '>= 4.4.0'
s.add_dependency 'spree', '>= 4.6.0'
s.add_dependency 'spree_extension'

s.add_development_dependency 'spree_dev_tools'
Expand Down

0 comments on commit d722d07

Please sign in to comment.