<?php
class EmailPedidoDonoListaPresente extends EmailPedidoListaPresente {

  public function __construct($registry)
  {
    parent::__construct($registry);
    parent::getConfigMail();
  }

  public function sendTask($typeemail, $order_id, $attribute_value)
  {

    try {
      if (!$this->config->get('listapresente_status')) {
        throw new exception('O modulo lista de presente esta desabilitado. E-mail referente ao pedido: ' . $order_id . ' não enviado!');
      }

      parent::getInfosTemplateOrder($order_id);
      parent::getInfosListaPresente($order_id);
      $this->getInfosOwnerListaPresente();

      $this->mail->setTo($this->to);//$order_info['email']
      $this->mail->setSender($this->sender);//$order_info['store_name']
      $this->mail->setSubject(html_entity_decode($this->subject, ENT_QUOTES, 'UTF-8'));
      $this->mail->setHtml(parent::getTemplate($typeemail));
      $this->mail->setText(html_entity_decode($this->text, ENT_QUOTES, 'UTF-8'));
      $this->mail->send(true);
    } catch(Exception $e){
      throw $e;
    }

  }

  public function getInfosOwnerListaPresente()
  {

    if($this->lista && $this->order_info){
      $this->load->dmodel('account/customer');
      $cliente = $this->dmodel_account_customer->getCustomer($this->lista['cliente_id']);
      $this->to = $cliente['email'];

      $this->template->data['customer_name']  = $this->order_info['firstname'] . ' ' . $this->order_info['lastname'];
      $this->template->data['customer_email'] = $this->order_info['email'];
      $this->template->data['customer_fone']  = $this->order_info['telephone'];

      $this->subject = $this->order_info['firstname'] . ' ' . $this->order_info['lastname'] . ' comprou um presente para você';

    }

  }


}