Skip to content

Instantly share code, notes, and snippets.

@chadrien
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadrien/ccb2e253cc86d6c4b85c to your computer and use it in GitHub Desktop.
Save chadrien/ccb2e253cc86d6c4b85c to your computer and use it in GitHub Desktop.
<?php
class Order extends AppModel {
private $__Email = null;
public function afterSave($created, $options = array()) {
if ($created) {
$this->__notifyClient();
$this->__notifyAdmin();
}
return parent::afterSave($created, $options);
}
private function __notifyClient() {
$this->__prepareNotification();
$this->__Email->template('order_complete', 'evolve')
->subject('Evolve Guitars - Order Complete')
->to($this->data['Order']['email'])
->send();
}
private function __notifyAdmin() {
$this->__prepareNotification();
$this->__Email->viewVars(array(
'id_stripped' => $this->data['Order']['id'],
))
->template('order_complete_admin', 'evolve')
->subject('Evolve Guitars - New Order')
->to('admin@website.com')
->send();
}
private function __prepareNotification() {
$this->__cleanUpEmail();
$this->__Email->emailFormat('html')
->from('noreply@website.com')
->viewVars(array(
'items' => $this->getItems($this-id),
'total' => $this->getTotal($this->id),
'invoice_id' => $this->getInvoiceId($this->id),
'name' => $this->data['Order']['first_name'] . ' ' . $this->data['Order']['last_name'],
'date' => date('F dS Y', strtotime($this->data['Order']['created'])),
));
}
private function __cleanUpEmail() {
if (null === $this->__Email) {
$this->__Email = new CakeEmail();
}
$this->__Email->reset();
}
/**
* return the items for the given order id
*/
public getItems($orderId) {}
/**
* return the total for the given order id
*/
public getTotal($orderId) {}
/**
* return the invoice id for the given order id
*/
public getInvoiceId($orderId) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment