send mail for colissimo module
This commit is contained in:
@@ -27,6 +27,12 @@ use Thelia\Model\Order;
|
|||||||
|
|
||||||
interface PaymentModuleInterface extends BaseModuleInterface
|
interface PaymentModuleInterface extends BaseModuleInterface
|
||||||
{
|
{
|
||||||
|
const NOT_PAID = 1;
|
||||||
|
const PAID = 2;
|
||||||
|
const PROCESSING = 3;
|
||||||
|
const SENT = 4;
|
||||||
|
const CANCELED = 5;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -26,9 +26,11 @@
|
|||||||
-->
|
-->
|
||||||
</templateDirectives>
|
</templateDirectives>
|
||||||
|
|
||||||
<!--
|
|
||||||
<services>
|
<services>
|
||||||
|
<service id="send.colissimo.mail" class="Colissimo\Listener\SendMail" scope="request">
|
||||||
|
<argument type="service" id="thelia.parser" />
|
||||||
|
<argument type="service" id="mailer"/>
|
||||||
|
<tag name="kernel.event_subscriber"/>
|
||||||
|
</service>
|
||||||
</services>
|
</services>
|
||||||
-->
|
|
||||||
</config>
|
</config>
|
||||||
|
|||||||
@@ -23,11 +23,15 @@
|
|||||||
|
|
||||||
namespace Colissimo\Listener;
|
namespace Colissimo\Listener;
|
||||||
|
|
||||||
|
use Colissimo\Colissimo;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Thelia\Core\Event\Order\OrderEvent;
|
use Thelia\Core\Event\Order\OrderEvent;
|
||||||
use Thelia\Core\Event\TheliaEvents;
|
use Thelia\Core\Event\TheliaEvents;
|
||||||
use Thelia\Core\Template\ParserInterface;
|
use Thelia\Core\Template\ParserInterface;
|
||||||
use Thelia\Mailer\MailerFactory;
|
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)
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user