diff --git a/core/lib/Thelia/Module/PaymentModuleInterface.php b/core/lib/Thelia/Module/PaymentModuleInterface.php index fd3283e3f..1b8b2894a 100644 --- a/core/lib/Thelia/Module/PaymentModuleInterface.php +++ b/core/lib/Thelia/Module/PaymentModuleInterface.php @@ -27,6 +27,12 @@ use Thelia\Model\Order; interface PaymentModuleInterface extends BaseModuleInterface { + const NOT_PAID = 1; + const PAID = 2; + const PROCESSING = 3; + const SENT = 4; + const CANCELED = 5; + /** * @return mixed */ diff --git a/local/modules/Colissimo/Config/config.xml b/local/modules/Colissimo/Config/config.xml index f158e6526..1ea694eff 100644 --- a/local/modules/Colissimo/Config/config.xml +++ b/local/modules/Colissimo/Config/config.xml @@ -26,9 +26,11 @@ --> - diff --git a/local/modules/Colissimo/Listener/SendMail.php b/local/modules/Colissimo/Listener/SendMail.php index 409e1421a..ff8c47d10 100644 --- a/local/modules/Colissimo/Listener/SendMail.php +++ b/local/modules/Colissimo/Listener/SendMail.php @@ -23,11 +23,15 @@ namespace Colissimo\Listener; +use Colissimo\Colissimo; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Core\Event\Order\OrderEvent; use Thelia\Core\Event\TheliaEvents; use Thelia\Core\Template\ParserInterface; use Thelia\Mailer\MailerFactory; +use Thelia\Model\ConfigQuery; +use Thelia\Model\MessageQuery; +use Thelia\Module\PaymentModuleInterface; /** @@ -50,7 +54,47 @@ class SendMail implements EventSubscriberInterface public function updateStatus(OrderEvent $event) { + $order = $event->getOrder(); + $colissimo = new Colissimo(); + if ($order->getStatusId() == PaymentModuleInterface::SENT && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) { + $contact_email = ConfigQuery::read('store_email'); + + if ($contact_email) { + + $message = MessageQuery::create() + ->filterByName('mail_colissimo') + ->findOne(); + + if (false === $message) { + throw new \Exception("Failed to load message 'order_confirmation'."); + } + + $order = $event->getOrder(); + $customer = $order->getCustomer(); + + $this->parser->assign('customer_id', $customer->getId()); + $this->parser->assign('order_ref', $order->getRef()); + $this->parser->assign('order_date', $order->getCreatedAt()); + $this->parser->assign('update_date', $order->getUpdatedAt()); + $this->parser->assign('package', $order->getDeliveryRef()); + + + $message + ->setLocale($order->getLang()->getLocale()); + + $instance = \Swift_Message::newInstance() + ->addTo($customer->getEmail(), $customer->getFirstname()." ".$customer->getLastname()) + ->addFrom($contact_email, ConfigQuery::read('store_name')) + ; + + // Build subject and body + + $message->buildMessage($this->parser, $instance); + + $this->mailer->send($instance); + } + } } /**