Exemple #1
0
 public function postActivation(ConnectionInterface $con = null)
 {
     $languages = LangQuery::create()->find();
     ConfigQuery::write(self::CONFIG_ENABLED, self::DEFAULT_ENABLED);
     ConfigQuery::write(self::CONFIG_THRESHOLD, self::DEFAULT_THRESHOLD);
     ConfigQuery::write(self::CONFIG_EMAILS, self::DEFAULT_EMAILS);
     // create new message
     if (null === MessageQuery::create()->findOneByName('stockalert_customer')) {
         $message = new Message();
         $message->setName('stockalert_customer')->setHtmlTemplateFileName('alert-customer.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-customer.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Stock Alert - Customer', [], $locale));
             $message->setSubject($this->trans('Product {$product_title} is available again', [], $locale));
         }
         $message->save();
         $message = new Message();
         $message->setName('stockalert_administrator')->setHtmlTemplateFileName('alert-administrator.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-administrator.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Stock Alert - Administrator', [], $locale));
             $message->setSubject($this->trans('Product {$product_title} is (nearly) out of stock', [], $locale));
         }
         $message->save();
     }
     try {
         RestockingAlertQuery::create()->findOne();
     } catch (\Exception $e) {
         $database = new Database($con);
         $database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
     }
 }
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === DpdClassic::getModuleId()) {
         if ($event->getOrder()->getStatusId() === DpdClassic::STATUS_SENT) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_dpdclassic')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_dpdclassic'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->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->getMailer()->send($instance);
             }
         }
     }
 }
Exemple #3
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $Predict = new Predict();
     if ($order->isSent() && $order->getDeliveryModuleId() == $Predict->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_predict')->findOne();
             if (false === $message) {
                 throw new \Exception(Translator::getInstance()->trans("Failed to load message '%mail_tpl_name'.", ["%mail_tpl_name" => "mail_predict"], Predict::MESSAGE_DOMAIN));
             }
             $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('order_id', $order->getId());
             $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);
             Tlog::getInstance()->debug("Predict shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Predict shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
Exemple #4
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $paidStatusId = OrderStatusQuery::create()->filterByCode(OrderStatus::CODE_PAID)->select('Id')->findOne();
     if ($order->hasVirtualProduct() && $event->getStatus() == $paidStatusId) {
         $contact_email = ConfigQuery::read('store_email');
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne();
             if (false === $message) {
                 throw new \Exception("Failed to load message 'mail_virtualproduct'.");
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('customer_id', $customer->getId());
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $this->parser->assign('order_date', $order->getCreatedAt());
             $this->parser->assign('update_date', $order->getUpdatedAt());
             $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);
             Tlog::getInstance()->debug("Virtual product download message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Virtual product download message no contact email customer_id", $customer->getId());
         }
     }
 }
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getDeliveryModuleId() === LocalPickup::getModCode()) {
         if ($event->getOrder()->isSent()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('order_confirmation_localpickup')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'order_confirmation_localpickup'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $store = ConfigQuery::create();
                 $country = CountryQuery::create()->findPk($store->read("store_country"));
                 $country = CountryI18nQuery::create()->filterById($country->getId())->findOneByLocale($order->getLang()->getLocale())->getTitle();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $this->parser->assign('store_name', $store->read("store_name"));
                 $this->parser->assign('store_address1', $store->read("store_address1"));
                 $this->parser->assign('store_address2', $store->read("store_address2"));
                 $this->parser->assign('store_address3', $store->read("store_address3"));
                 $this->parser->assign('store_zipcode', $store->read("store_zipcode"));
                 $this->parser->assign('store_city', $store->read("store_city"));
                 $this->parser->assign('store_country', $country);
                 $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->getMailer()->send($instance);
             }
         }
     }
 }
Exemple #6
0
 /**
  * Delete a messageuration entry
  *
  * @param \Thelia\Core\Event\Message\MessageDeleteEvent $event
  */
 public function delete(MessageDeleteEvent $event)
 {
     if (null !== ($message = MessageQuery::create()->findPk($event->getMessageId()))) {
         $message->setDispatcher($event->getDispatcher())->delete();
         $event->setMessage($message);
     }
 }
Exemple #7
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     $colissimo = new Colissimo();
     if ($order->isSent() && $order->getDeliveryModuleId() == $colissimo->getModuleModel()->getId()) {
         $contact_email = ConfigQuery::getStoreEmail();
         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::getStoreName());
             // Build subject and body
             $message->buildMessage($this->parser, $instance);
             $this->mailer->send($instance);
             Tlog::getInstance()->debug("Colissimo shipping message sent to customer " . $customer->getEmail());
         } else {
             $customer = $order->getCustomer();
             Tlog::getInstance()->debug("Colissimo shipping message no contact email customer_id", $customer->getId());
         }
     }
 }
 /**
  * Checks if we are the payment module for the order, and if the order is paid,
  * then send a confirmation email to the customer.
  *
  * @params OrderEvent $order
  */
 public function update_status(OrderEvent $event)
 {
     $payzen = new Payzen();
     if ($event->getOrder()->isPaid() && $payzen->isPaymentModuleFor($event->getOrder())) {
         $contact_email = ConfigQuery::read('store_email', false);
         Tlog::getInstance()->debug("Sending confirmation email from store contact e-mail {$contact_email}");
         if ($contact_email) {
             $message = MessageQuery::create()->filterByName(Payzen::CONFIRMATION_MESSAGE_NAME)->findOne();
             if (false === $message) {
                 throw new \Exception(sprintf("Failed to load message '%s'.", Payzen::CONFIRMATION_MESSAGE_NAME));
             }
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->parser->assign('order_id', $order->getId());
             $this->parser->assign('order_ref', $order->getRef());
             $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->getMailer()->send($instance);
             Tlog::getInstance()->debug("Confirmation email sent to customer " . $customer->getEmail());
         }
     } else {
         Tlog::getInstance()->debug("No confirmation email sent (order not paid, or not the proper payement module.");
     }
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     // delete existing message
     $message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne($con);
     if (null !== $message) {
         $message->delete($con);
     }
     // create new message
     $message = new Message();
     $message->setName('mail_virtualproduct')->setSecured(0);
     $basePath = __DIR__ . '/Config/message/%s.xml';
     $languages = LangQuery::create()->find();
     foreach ($languages as $language) {
         $locale = $language->getLocale();
         $message->setLocale($locale);
         $path = sprintf($basePath, $language->getLocale());
         if (file_exists($path) && is_readable($path)) {
             $dom = new SimpleXMLElement(file_get_contents($path));
             if ($dom) {
                 $message->setTitle((string) $dom->title);
                 $message->setSubject((string) $dom->subject);
                 $message->setTextMessage((string) $dom->text);
                 $message->setHtmlMessage((string) $dom->html);
             }
         }
     }
     $message->save();
 }
 public function checkDuplicateName($value, ExecutionContextInterface $context)
 {
     $message = MessageQuery::create()->findOneByName($value);
     if ($message) {
         $context->addViolation(Translator::getInstance()->trans('A message with name "%name" already exists.', array('%name' => $value)));
     }
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     // register config variables
     if (null === ConfigQuery::read(self::CONFIG_TRACKING_URL, null)) {
         ConfigQuery::write(self::CONFIG_TRACKING_URL, self::DEFAULT_TRACKING_URL);
     }
     if (null === ConfigQuery::read(self::CONFIG_PICKING_METHOD, null)) {
         ConfigQuery::write(self::CONFIG_PICKING_METHOD, self::DEFAULT_PICKING_METHOD);
     }
     if (null === ConfigQuery::read(self::CONFIG_TAX_RULE_ID, null)) {
         ConfigQuery::write(self::CONFIG_TAX_RULE_ID, self::DEFAULT_TAX_RULE_ID);
     }
     // create new message
     if (null === MessageQuery::create()->findOneByName('mail_custom_delivery')) {
         $message = new Message();
         $message->setName('mail_custom_delivery')->setHtmlTemplateFileName('custom-delivery-shipping.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('custom-delivery-shipping.txt')->setTextLayoutFileName('')->setSecured(0);
         $languages = LangQuery::create()->find();
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Custom delivery shipping message', [], $locale));
             $message->setSubject($this->trans('Your order {$order_ref} has been shipped', [], $locale));
         }
         $message->save();
     }
 }
Exemple #12
0
 /**
  * Load a message from its name, throwing an excemtoipn is none is found.
  *
  * @param  string     $messageName the message name
  * @return Message    the loaded message
  * @throws \Exception if the message could not be loaded
  */
 public static function getFromName($messageName)
 {
     if (false === ($message = MessageQuery::create()->filterByName($messageName)->findOne())) {
         throw new \Exception("Failed to load message {$messageName}.");
     }
     return $message;
 }
Exemple #13
0
 /**
  * Delete a messageuration entry
  *
  * @param \Thelia\Core\Event\Message\MessageDeleteEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function delete(MessageDeleteEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     if (null !== ($message = MessageQuery::create()->findPk($event->getMessageId()))) {
         $message->setDispatcher($dispatcher)->delete();
         $event->setMessage($message);
     }
 }
Exemple #14
0
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     // Delete our message
     if (null !== ($message = MessageQuery::create()->findOneByName('order_confirmation_cheque'))) {
         $message->delete($con);
     }
     parent::destroy($con, $deleteModuleData);
 }
Exemple #15
0
 /**
  * @inheritdoc
  */
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     // Delete config table and messages if required
     if ($deleteModuleData) {
         MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete($con);
         MessageQuery::create()->findOneByName(self::NOTIFICATION_MESSAGE_NAME)->delete($con);
     }
 }
 protected function getExistingObject()
 {
     $message = MessageQuery::create()->findOneById($this->getRequest()->get('message_id', 0));
     if (null !== $message) {
         $message->setLocale($this->getCurrentEditionLocale());
     }
     return $message;
 }
Exemple #17
0
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     if ($deleteModuleData) {
         $database = new Database($con);
         $database->execute('drop table `atos_currency`');
         MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete();
     }
 }
Exemple #18
0
 public function destroy(ConnectionInterface $con = null, $deleteModuleData = false)
 {
     // Delete config table and messages if required
     if ($deleteModuleData) {
         $database = new Database($con);
         $database->execute("DROP TABLE ?", PayzenConfigTableMap::TABLE_NAME);
         MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)->delete();
     }
 }
 public function createMailMessage()
 {
     // Create payment confirmation message from templates, if not already defined
     if (null === MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)) {
         $languages = LangQuery::create()->find();
         $message = new Message();
         $message->setName(self::CONFIRMATION_MESSAGE_NAME)->setHtmlTemplateFileName(self::CONFIRMATION_MESSAGE_NAME . '.html')->setTextTemplateFileName(self::CONFIRMATION_MESSAGE_NAME . '.txt');
         foreach ($languages as $language) {
             /** @var Lang $language */
             $locale = $language->getLocale();
             $message->setLocale($locale)->setTitle(Translator::getInstance()->trans("Payment confirmation for Stripe Payment", [], self::MESSAGE_DOMAIN, $locale))->setSubject(Translator::getInstance()->trans('Payment confirmation of your order {$order_ref} on {$store_name}', [], self::MESSAGE_DOMAIN, $locale));
         }
         $message->save();
     }
 }
Exemple #20
0
 protected function initializeMessage()
 {
     // create new message
     if (null === MessageQuery::create()->findOneByName('mail_tnt_france')) {
         $message = new Message();
         $message->setName('mail_tnt_france')->setHtmlTemplateFileName('mail-tnt-france.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('mail-tnt-france.txt')->setTextLayoutFileName('')->setSecured(0);
         $languages = LangQuery::create()->find();
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setSubject($this->trans('Your order {$order_ref} has been shipped.', [], $locale));
             $message->setTitle($this->trans('TNT France shipping message', [], $locale));
         }
         $message->save();
     }
 }
 public function postActivation(ConnectionInterface $con = null)
 {
     // create new message
     if (null === MessageQuery::create()->findOneByName('mail_virtualproduct')) {
         $message = new Message();
         $message->setName('mail_virtualproduct')->setHtmlTemplateFileName('virtual-product-download.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('virtual-product-download.txt')->setTextLayoutFileName('')->setSecured(0);
         $languages = LangQuery::create()->find();
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setSubject($this->trans('Order {$order_ref} validated. Download your files.', [], $locale));
             $message->setTitle($this->trans('Virtual product download message', [], $locale));
         }
         $message->save();
     }
 }
 /**
  * @param ConnectionInterface $con
  */
 public function postActivation(ConnectionInterface $con = null)
 {
     $database = new Database($con->getWrappedConnection());
     $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     $languages = LangQuery::create()->find();
     if (null === MessageQuery::create()->findOneByName(self::MESSAGE_SEND_CONFIRMATION)) {
         $message = new Message();
         $message->setName(self::MESSAGE_SEND_CONFIRMATION)->setHtmlLayoutFileName('')->setHtmlTemplateFileName(self::MESSAGE_SEND_CONFIRMATION . '.html')->setTextLayoutFileName('')->setTextTemplateFileName(self::MESSAGE_SEND_CONFIRMATION . '.txt');
         foreach ($languages as $language) {
             /** @var Lang $language */
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle($this->trans('Order send confirmation', $locale));
             $message->setSubject($this->trans('Order send confirmation', $locale));
         }
         $message->save();
     }
 }
Exemple #23
0
 public function update_status(OrderEvent $event)
 {
     if ($event->getOrder()->getPaymentModuleId() === Paypal::getModCode()) {
         if ($event->getOrder()->isPaid()) {
             $contact_email = ConfigQuery::read('store_email');
             if ($contact_email) {
                 $message = MessageQuery::create()->filterByName('payment_confirmation_paypal')->findOne();
                 if (false === $message) {
                     throw new \Exception("Failed to load message 'payment_confirmation_paypal'.");
                 }
                 $order = $event->getOrder();
                 $customer = $order->getCustomer();
                 $this->parser->assign('order_id', $order->getId());
                 $this->parser->assign('order_ref', $order->getRef());
                 $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->getMailer()->send($instance);
             }
         }
     }
 }
Exemple #24
0
 public function buildModelCriteria()
 {
     $id = $this->getId();
     $name = $this->getVariable();
     $secured = $this->getSecured();
     $exclude = $this->getExclude();
     $search = MessageQuery::create();
     $this->configureI18nProcessing($search, array('TITLE', 'SUBJECT', 'TEXT_MESSAGE', 'HTML_MESSAGE'));
     if (!is_null($id)) {
         $search->filterById($id);
     }
     if (!is_null($name)) {
         $search->filterByName($name);
     }
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     if (!is_null($secured) && $secured != BooleanOrBothType::ANY) {
         $search->filterBySecured($secured ? 1 : 0);
     }
     $search->orderByName(Criteria::ASC);
     return $search;
 }
Exemple #25
0
 public function postActivation(ConnectionInterface $con = null)
 {
     // Config
     if (null === ConfigQuery::read('comment_activated')) {
         ConfigQuery::write('comment_activated', Comment::CONFIG_ACTIVATED);
     }
     if (null === ConfigQuery::read('comment_moderate')) {
         ConfigQuery::write('comment_moderate', Comment::CONFIG_MODERATE);
     }
     if (null === ConfigQuery::read('comment_ref_allowed')) {
         ConfigQuery::write('comment_ref_allowed', Comment::CONFIG_REF_ALLOWED);
     }
     if (null === ConfigQuery::read('comment_only_customer')) {
         ConfigQuery::write('comment_only_customer', Comment::CONFIG_ONLY_CUSTOMER);
     }
     if (null === ConfigQuery::read('comment_only_verified')) {
         ConfigQuery::write('comment_only_verified', Comment::CONFIG_ONLY_VERIFIED);
     }
     if (null === ConfigQuery::read('comment_request_customer_ttl')) {
         ConfigQuery::write('comment_request_customer_ttl', Comment::CONFIG_REQUEST_CUSTOMMER_TTL);
     }
     if (null === ConfigQuery::read('comment_notify_admin_new_comment')) {
         ConfigQuery::write('comment_notify_admin_new_comment', Comment::CONFIG_NOTIFY_ADMIN_NEW_COMMENT);
     }
     // Schema
     try {
         CommentQuery::create()->findOne();
     } catch (\Exception $ex) {
         $database = new Database($con->getWrappedConnection());
         $database->insertSql(null, [__DIR__ . DS . 'Config' . DS . 'thelia.sql']);
     }
     // Messages
     // load the email localization files (the module was just loaded so they are not loaded yet)
     $languages = LangQuery::create()->find();
     /** @var Lang $language */
     foreach ($languages as $language) {
         Translator::getInstance()->addResource("php", __DIR__ . "/I18n/email/default/" . $language->getLocale() . ".php", $language->getLocale(), self::MESSAGE_DOMAIN_EMAIL);
     }
     // Request comment from customer
     if (null === MessageQuery::create()->findOneByName('comment_request_customer')) {
         $message = new Message();
         $message->setName('comment_request_customer')->setHtmlTemplateFileName('request-customer-comment.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('request-customer-comment.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle(Translator::getInstance()->trans('Request customer comment', [], self::MESSAGE_DOMAIN));
             $message->setSubject(Translator::getInstance()->trans('', [], self::MESSAGE_DOMAIN));
         }
         $message->save();
     }
     // Notify admin of new comment
     if (null === MessageQuery::create()->findOneByName('new_comment_notification_admin')) {
         $message = new Message();
         $message->setName('new_comment_notification_admin')->setHtmlTemplateFileName('new-comment-notification-admin.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('new-comment-notification-admin.txt')->setTextLayoutFileName('')->setSecured(0);
         foreach ($languages as $language) {
             $locale = $language->getLocale();
             $message->setLocale($locale);
             $message->setTitle(Translator::getInstance()->trans('Notify store admin of new comment', [], self::MESSAGE_DOMAIN_EMAIL, $locale));
             $subject = Translator::getInstance()->trans('New comment on %ref_type_title "%ref_title"', [], self::MESSAGE_DOMAIN_EMAIL, $locale);
             $subject = str_replace('%ref_type_title', '{$ref_type_title|lower}', $subject);
             $subject = str_replace('%ref_title', '{$ref_title}', $subject);
             $message->setSubject($subject);
         }
         $message->save();
     }
 }
Exemple #26
0
 public function previewAction($messageId, $html = true)
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MESSAGE, [], AccessManager::VIEW))) {
         return $response;
     }
     if (null === ($message = MessageQuery::create()->findPk($messageId))) {
         $this->pageNotFound();
     }
     $parser = $this->getParser($this->getTemplateHelper()->getActiveMailTemplate());
     foreach ($this->getRequest()->query->all() as $key => $value) {
         $parser->assign($key, $value);
     }
     if ($html) {
         $content = $message->setLocale($this->getCurrentEditionLocale())->getHtmlMessageBody($parser);
     } else {
         $content = $message->setLocale($this->getCurrentEditionLocale())->getTextMessageBody($parser);
     }
     return new Response($content);
 }
Exemple #27
0
 /**
  * Create a SwiftMessage instance from a given message code.
  *
  * @param  string $messageCode
  * @param  array  $from              From addresses. An array of (name => email-address)
  * @param  array  $to                To addresses. An array of (name => email-address)
  * @param  array  $messageParameters an array of (name => value) parameters that will be available in the message.
  * @param string  $locale. If null, the default store locale is used.
  *
  * @return \Swift_Message the generated and built message.
  */
 public function createEmailMessage($messageCode, $from, $to, $messageParameters = [], $locale = null)
 {
     if (null !== ($message = MessageQuery::getFromName($messageCode))) {
         if ($locale == null) {
             $locale = Lang::getDefaultLanguage()->getLocale();
         }
         $message->setLocale($locale);
         // Assign parameters
         foreach ($messageParameters as $name => $value) {
             $this->parser->assign($name, $value);
         }
         $this->parser->assign('locale', $locale);
         $instance = \Swift_Message::newInstance();
         // Add from addresses
         foreach ($from as $address => $name) {
             $instance->addFrom($address, $name);
         }
         // Add to addresses
         foreach ($to as $address => $name) {
             $instance->addTo($address, $name);
         }
         $message->buildMessage($this->parser, $instance);
         return $instance;
     }
     throw new \RuntimeException(Translator::getInstance()->trans("Failed to load message with code '%code%', propably because it does'nt exists.", ['%code%' => $messageCode]));
 }
 public function sendEmailForAdmin($emails, $productIds)
 {
     $contactEmail = ConfigQuery::read('store_email');
     if ($contactEmail) {
         $message = MessageQuery::create()->filterByName('stockalert_administrator')->findOne();
         if (null === $message) {
             throw new \Exception("Failed to load message 'stockalert_administrator'.");
         }
         $locale = Lang::getDefaultLanguage()->getLocale();
         $this->parser->assign('locale', $locale);
         $this->parser->assign('products_id', $productIds);
         $message->setLocale($locale);
         $instance = \Swift_Message::newInstance();
         $instance->addFrom($contactEmail, ConfigQuery::read('store_name'));
         foreach ($emails as $email) {
             $instance->addTo($email);
         }
         // Build subject and body
         $message->buildMessage($this->parser, $instance);
         $this->mailer->send($instance);
         Tlog::getInstance()->debug("Stock Alert sent to administrator " . implode(', ', $emails));
     } else {
         Tlog::getInstance()->debug("Stock Alert sent to administrator " . implode(', ', $emails));
     }
 }
Exemple #29
0
 /**
  * Get the associated ChildMessage object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildMessage The associated ChildMessage object.
  * @throws PropelException
  */
 public function getMessage(ConnectionInterface $con = null)
 {
     if ($this->aMessage === null && $this->id !== null) {
         $this->aMessage = ChildMessageQuery::create()->findPk($this->id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aMessage->addMessageVersions($this);
            */
     }
     return $this->aMessage;
 }
Exemple #30
0
 /**
  * Returns a new ChildMessageQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param     Criteria $criteria Optional Criteria to build the query from
  *
  * @return ChildMessageQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof \Thelia\Model\MessageQuery) {
         return $criteria;
     }
     $query = new \Thelia\Model\MessageQuery();
     if (null !== $modelAlias) {
         $query->setModelAlias($modelAlias);
     }
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }