mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 02:44:35 -04:00
Fixes for mailable
This commit is contained in:
parent
a4f2d40d75
commit
453042f7e8
@ -23,6 +23,7 @@ use App\Models\Invoice;
|
|||||||
use App\Models\PurchaseOrder;
|
use App\Models\PurchaseOrder;
|
||||||
use App\Models\Quote;
|
use App\Models\Quote;
|
||||||
use App\Models\RecurringInvoice;
|
use App\Models\RecurringInvoice;
|
||||||
|
use App\Services\Email\MailEntity;
|
||||||
use App\Services\Email\MailObject;
|
use App\Services\Email\MailObject;
|
||||||
use App\Transformers\CreditTransformer;
|
use App\Transformers\CreditTransformer;
|
||||||
use App\Transformers\InvoiceTransformer;
|
use App\Transformers\InvoiceTransformer;
|
||||||
@ -129,6 +130,10 @@ class EmailController extends BaseController
|
|||||||
];
|
];
|
||||||
|
|
||||||
$mo = new MailObject;
|
$mo = new MailObject;
|
||||||
|
$mo->subject = empty($subject) ? null : $subject;
|
||||||
|
$mo->body = empty($body) ? null : $body;
|
||||||
|
$mo->entity_string = $entity;
|
||||||
|
$mo->email_template = $template;
|
||||||
|
|
||||||
if(Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified)
|
if(Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified)
|
||||||
return response(['message' => 'Please verify your account to send emails.'], 400);
|
return response(['message' => 'Please verify your account to send emails.'], 400);
|
||||||
@ -137,12 +142,14 @@ class EmailController extends BaseController
|
|||||||
return $this->sendPurchaseOrder($entity_obj, $data, $template);
|
return $this->sendPurchaseOrder($entity_obj, $data, $template);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity_obj->invitations->each(function ($invitation) use ($data, $entity_string, $entity_obj, $template) {
|
$entity_obj->invitations->each(function ($invitation) use ($data, $entity_string, $entity_obj, $template, $mo) {
|
||||||
|
|
||||||
if (! $invitation->contact->trashed() && $invitation->contact->email) {
|
if (! $invitation->contact->trashed() && $invitation->contact->email) {
|
||||||
$entity_obj->service()->markSent()->save();
|
$entity_obj->service()->markSent()->save();
|
||||||
|
|
||||||
EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data);
|
// EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data);
|
||||||
|
|
||||||
|
MailEntity::dispatch($invitation, $invitation->company->db, $mo);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -286,8 +286,8 @@ class MailBuild
|
|||||||
|
|
||||||
if ($this->mail_entity->mail_object->subject) //where the user updates the subject from the UI
|
if ($this->mail_entity->mail_object->subject) //where the user updates the subject from the UI
|
||||||
return $this;
|
return $this;
|
||||||
elseif(is_string($this->mail_entity->mail_object->email_template_subject) && strlen($this->settings->{$this->mail_entity->mail_object->email_template_subject}) > 3)
|
elseif(is_string($this->mail_entity->mail_object->email_template) && strlen($this->settings->{$this->resolveBaseEntityTemplate()}) > 3)
|
||||||
$this->mail_entity->mail_object->subject = $this->settings->{$this->mail_entity->mail_object->email_template_subject};
|
$this->mail_entity->mail_object->subject = $this->settings->{$this->resolveBaseEntityTemplate()};
|
||||||
else
|
else
|
||||||
$this->mail_entity->mail_object->subject = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate(), $this->locale);
|
$this->mail_entity->mail_object->subject = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate(), $this->locale);
|
||||||
|
|
||||||
@ -306,8 +306,8 @@ class MailBuild
|
|||||||
if($this->mail_entity->mail_object->body){
|
if($this->mail_entity->mail_object->body){
|
||||||
$this->mail_entity->mail_object->body = $this->mail_entity->mail_object->body;
|
$this->mail_entity->mail_object->body = $this->mail_entity->mail_object->body;
|
||||||
}
|
}
|
||||||
elseif(is_string($this->mail_entity->mail_object->email_template_body) && strlen($this->settings->{$this->mail_entity->mail_object->email_template_body}) > 3){
|
elseif(is_string($this->mail_entity->mail_object->email_template) && strlen($this->settings->{$this->resolveBaseEntityTemplate('body')}) > 3){
|
||||||
$this->mail_entity->mail_object->body = $this->settings->{$this->mail_entity->mail_object->email_template_body};
|
$this->mail_entity->mail_object->body = $this->settings->{$this->resolveBaseEntityTemplate('body')};
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$this->mail_entity->mail_object->body = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate('body'), $this->locale);
|
$this->mail_entity->mail_object->body = EmailTemplateDefaults::getDefaultTemplate($this->resolveBaseEntityTemplate('body'), $this->locale);
|
||||||
@ -330,6 +330,17 @@ class MailBuild
|
|||||||
*/
|
*/
|
||||||
private function resolveBaseEntityTemplate(string $type = 'subject'): string
|
private function resolveBaseEntityTemplate(string $type = 'subject'): string
|
||||||
{
|
{
|
||||||
|
if($this->mail_entity->mail_object->email_template){
|
||||||
|
|
||||||
|
match($type){
|
||||||
|
'subject' => $template = "email_subject_{$this->mail_entity->mail_object->email_template}",
|
||||||
|
'body' => $template = "email_template_{$this->mail_entity->mail_object->email_template}",
|
||||||
|
default => $template = "email_template_invoice",
|
||||||
|
};
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
//handle statements being emailed
|
//handle statements being emailed
|
||||||
//handle custom templates these types won't have a resolvable entity_string
|
//handle custom templates these types won't have a resolvable entity_string
|
||||||
if(!$this->mail_entity->mail_object->entity_string)
|
if(!$this->mail_entity->mail_object->entity_string)
|
||||||
|
@ -57,7 +57,7 @@ class MailMailable extends Mailable
|
|||||||
view: $this->mail_object->html_template,
|
view: $this->mail_object->html_template,
|
||||||
text: $this->mail_object->text_template,
|
text: $this->mail_object->text_template,
|
||||||
with: [
|
with: [
|
||||||
'text_body' => strip_tags($this->mail_object->body), //@todo this is a bit hacky here.
|
'text_body' => str_replace("<br>","\n", strip_tags($this->mail_object->body,"<br>")), //@todo this is a bit hacky here.
|
||||||
'body' => $this->mail_object->body,
|
'body' => $this->mail_object->body,
|
||||||
'settings' => $this->mail_object->settings,
|
'settings' => $this->mail_object->settings,
|
||||||
'whitelabel' => $this->mail_object->whitelabel,
|
'whitelabel' => $this->mail_object->whitelabel,
|
||||||
|
@ -62,9 +62,7 @@ class MailObject
|
|||||||
|
|
||||||
public ?int $vendor_contact_id = null;
|
public ?int $vendor_contact_id = null;
|
||||||
|
|
||||||
public ?string $email_template_body = null;
|
public ?string $email_template = null; //this defines the template in short notation WITH the email_template prefix
|
||||||
|
|
||||||
public ?string $email_template_subject = null;
|
|
||||||
|
|
||||||
public ?string $html_template = null;
|
public ?string $html_template = null;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user