local/modules/Colissimo/Listener/SendMail.php line 46

  1. <?php
  2. /*************************************************************************************/
  3. /*      This file is part of the Thelia package.                                     */
  4. /*                                                                                   */
  5. /*      Copyright (c) OpenStudio                                                     */
  6. /*      email : dev@thelia.net                                                       */
  7. /*      web : http://www.thelia.net                                                  */
  8. /*                                                                                   */
  9. /*      For the full copyright and license information, please view the LICENSE.txt  */
  10. /*      file that was distributed with this source code.                             */
  11. /*************************************************************************************/
  12. namespace Colissimo\Listener;
  13. use Colissimo\Colissimo;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. use Thelia\Core\Event\Order\OrderEvent;
  16. use Thelia\Core\Event\TheliaEvents;
  17. use Thelia\Core\Template\ParserInterface;
  18. use Thelia\Log\Tlog;
  19. use Thelia\Mailer\MailerFactory;
  20. use Thelia\Model\ConfigQuery;
  21. use Thelia\Model\MessageQuery;
  22. use Thelia\Model\OrderStatus;
  23. use Thelia\Module\PaymentModuleInterface;
  24. /**
  25.  * Class SendMail
  26.  * @package Colissimo\Listener
  27.  * @author Manuel Raynaud <manu@raynaud.io>
  28.  */
  29. class SendMail implements EventSubscriberInterface
  30. {
  31.     
  32.     protected $parser;
  33.     
  34.     protected $mailer;
  35.     
  36.     public function __construct(ParserInterface $parserMailerFactory $mailer)
  37.     {
  38.         $this->parser $parser;
  39.         $this->mailer $mailer;
  40.     }
  41.     
  42.     public function updateStatus(OrderEvent $event)
  43.     {
  44.         $order $event->getOrder();
  45.         $colissimo = new Colissimo();
  46.         
  47.         if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
  48.             $contact_email ConfigQuery::getStoreEmail();
  49.             
  50.             if ($contact_email) {
  51.                 $order $event->getOrder();
  52.                 $customer $order->getCustomer();
  53.                 
  54.                 $this->mailer->sendEmailToCustomer(
  55.                     'mail_colissimo',
  56.                     $customer,
  57.                     [
  58.                         'customer_id' => $customer->getId(),
  59.                         'order_ref' => $order->getRef(),
  60.                         'order_date' => $order->getCreatedAt(),
  61.                         'update_date' => $order->getUpdatedAt(),
  62.                         'package' => $order->getDeliveryRef()
  63.                     ]
  64.                 );
  65.                 
  66.                 Tlog::getInstance()->debug("Colissimo shipping message sent to customer ".$customer->getEmail());
  67.             } else {
  68.                 $customer $order->getCustomer();
  69.                 Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id"$customer->getId());
  70.             }
  71.         }
  72.     }
  73.     
  74.     /**
  75.      * Returns an array of event names this subscriber wants to listen to.
  76.      *
  77.      * The array keys are event names and the value can be:
  78.      *
  79.      *  * The method name to call (priority defaults to 0)
  80.      *  * An array composed of the method name to call and the priority
  81.      *  * An array of arrays composed of the method names to call and respective
  82.      *    priorities, or 0 if unset
  83.      *
  84.      * For instance:
  85.      *
  86.      *  * array('eventName' => 'methodName')
  87.      *  * array('eventName' => array('methodName', $priority))
  88.      *  * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
  89.      *
  90.      * @return array The event names to listen to
  91.      *
  92.      * @api
  93.      */
  94.     public static function getSubscribedEvents()
  95.     {
  96.         return array(
  97.             TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus"128)
  98.         );
  99.     }
  100. }