Changed OrderFiles; name is now dropdown of predefined types; Certain
types send emails
This commit is contained in:
@@ -163,6 +163,65 @@ class Order extends mfBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
public function sendFileuploadEmail(OrderFile $file) {
|
||||
$filetype = $file->name;
|
||||
|
||||
$this->log->debug("in sendFileuploadEmail(); filetype: $filetype");
|
||||
|
||||
if(!defined("TT_ORDER_FILE_TYPES") || ! is_array(TT_ORDER_FILE_TYPES )) {
|
||||
return false;
|
||||
}
|
||||
if(!array_key_exists($filetype, TT_ORDER_FILE_TYPES)) {
|
||||
return false;
|
||||
}
|
||||
$tpl = new Layout();
|
||||
$tpl->setTemplate("Emailtemplates/order/fileupload/".$filetype);
|
||||
if(!$tpl->templatePathExists()) {
|
||||
$this->log->debug(__METHOD__.": tpl does not exist, not sending email.");
|
||||
return true;
|
||||
}
|
||||
$tpl->set("order", $this);
|
||||
$tpl->set("file", $file);
|
||||
$body = $tpl->render();
|
||||
|
||||
$values = $tpl->getReturnedValue();
|
||||
|
||||
$subject = $values['subject'];
|
||||
$from = $values['from_email'];
|
||||
$from_name = $values['from_email_name'];
|
||||
$to = $values['to'];
|
||||
|
||||
if(!$subject || !$from || !$from_name || !$to) {
|
||||
$this->log->warn("Order Fileupload Email not sent. (subject: '$subject', from: '$from', from_email: '$from_email', to: '$to')");
|
||||
} else {
|
||||
$filepath = MFUPLOAD_FILE_SAVE_PATH;
|
||||
if($file->file->subfolder) {
|
||||
$filepath .= "/".$file->file->subfolder;
|
||||
}
|
||||
$filepath .= "/".$file->file->store_filename;
|
||||
|
||||
$finfo = new finfo(FILEINFO_MIME_TYPE);
|
||||
$mimetype = $finfo->file($filepath);
|
||||
if(!$mimetype) {
|
||||
$this->log->warning("File (orderfile->id: ".$file->id.") not a valid mimetype: $mimetype");
|
||||
}
|
||||
|
||||
$email = new Emailnotification();
|
||||
$email->setSubject($subject);
|
||||
$email->setBody($body);
|
||||
$email->setFrom($from, $from_name);
|
||||
$email->setTo($to);
|
||||
$email->setHeader("X-Xinon-Oid", $this->id);
|
||||
$email->setHeader("X-Xinon-OFid", $file->id);
|
||||
$email->addAttachment($filepath, null, $file->file->filename, $mimetype);
|
||||
$email->send();
|
||||
$this->log->info(__CLASS__."::save(): Sending Order Fileupload Email to '$to'");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getProperty($name) {
|
||||
if($this->$name == null) {
|
||||
|
||||
@@ -194,6 +253,7 @@ class Order extends mfBaseModel {
|
||||
|
||||
if($name == "products") {
|
||||
$this->products = OrderProductModel::search(["order_id" => $this->id]);
|
||||
//var_dump($this->products);exit;
|
||||
return $this->products;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user