Example #1
0
 protected function display404(GetResponseForExceptionEvent $event)
 {
     // Define the template thant shoud be used
     $this->parser->setTemplateDefinition($this->parser->getTemplateHelper()->getActiveFrontTemplate());
     $response = new Response($this->parser->render(ConfigQuery::getPageNotFoundView()), 404);
     $event->setResponse($response);
 }
Example #2
0
 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);
             }
         }
     }
 }
 /**
  * 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.");
     }
 }
Example #4
0
 /**
  * Return an asset source file path.
  *
  * A system of fallback enables file overriding. It will look for the template :
  *      - in the current template in directory /modules/{module code}/
  *      - in the module in the current template if it exists
  *      - in the module in the default template
  *
  * @param  string $source a module code, or or SmartyParser::TEMPLATE_ASSETS_KEY
  * @param  string $templateName a template name, or false to use the current template
  * @param  string $fileName the filename
  * @param  ParserInterface $parserInterface the current template parser
  *
  * @return mixed the path to directory containing the file, or null if the file doesn't exists.
  */
 public function resolveAssetSourcePath($source, $templateName, $fileName, ParserInterface $parserInterface)
 {
     $filePath = null;
     $templateDefinition = $parserInterface->getTemplateDefinition(false);
     // Get all possible directories to search
     $paths = $this->getPossibleAssetSources($parserInterface->getTemplateDirectories($templateDefinition->getType()), $templateName ?: $templateDefinition->getName(), $source);
     // Normalize path separator if required (e.g., / becomes \ on windows)
     $fileName = $this->fixPathSeparator($fileName);
     /* Absolute paths are not allowed. This may be a mistake, such as '/assets/...' instead of 'assets/...'. Forgive it.  */
     $fileName = ltrim($fileName, DS);
     /* Navigating in the server's directory tree is not allowed :) */
     if (preg_match('!\\.\\.\\' . DS . '!', $fileName)) {
         // This time, we will not forgive.
         throw new \InvalidArgumentException("Relative paths are not allowed in assets names.");
     }
     // Find the first occurrence of the file in the directories lists
     foreach ($paths as $path) {
         if ($this->filesExist($path, $fileName)) {
             // Got it !
             $filePath = $path;
             break;
         }
     }
     return $filePath;
 }
 /**
  * @param  \SplFileInfo[]   $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processModule($templates, $resourcesPath, $modulePath, $moduleCode)
 {
     foreach ($templates as $template) {
         $fileName = str_replace("__MODULE__", $moduleCode, $template->getFilename());
         $fileName = str_replace("FIX", "", $fileName);
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = $modulePath . $relativePath . DS . $fileName;
         $isFix = false !== strpos($template->getFilename(), "FIX");
         // Expect special rule for Module\Module
         $isModuleClass = $modulePath . $relativePath . DS . $moduleCode . ".php" === $completeFilePath;
         if ($isFix && !file_exists($completeFilePath) || !$isFix) {
             if ($isModuleClass && is_file($completeFilePath)) {
                 $caught = false;
                 try {
                     $reflection = new \ReflectionClass("{$moduleCode}\\{$moduleCode}");
                 } catch (\ReflectionException $e) {
                     $caught = true;
                     // The class is not valid
                 }
                 if (!$caught && $reflection->hasConstant("MESSAGE_DOMAIN")) {
                     continue;
                     // If the class already have the constant, don't override it
                 }
             }
             $fetchedTemplate = $this->parser->fetch($template->getRealPath());
             $this->writeFile($completeFilePath, $fetchedTemplate, true, true);
         }
     }
 }
Example #6
0
 public function defaultErrorFallback(GetResponseForExceptionEvent $event)
 {
     $this->parser->assign("status_code", 500);
     $this->parser->assign("exception_message", $event->getException()->getMessage());
     $this->parser->setTemplateDefinition($this->securityContext->hasAdminUser() ? TemplateHelper::getInstance()->getActiveAdminTemplate() : TemplateHelper::getInstance()->getActiveFrontTemplate());
     $response = new Response($this->parser->render(ConfigQuery::getErrorMessagePageName()), 500);
     $event->setResponse($response);
 }
Example #7
0
 public function generate(ModuleGenerateEvent $event)
 {
     $templates = $this->findInPath($event->getResourcesPath(), "/__TABLE__.*\\.php\$/");
     $this->parser->assign("moduleCode", $event->getModuleCode());
     $this->parser->assign("tables", $event->getEntities());
     foreach ($event->getEntities() as $entity) {
         $this->processPhp($entity, $templates, $event->getResourcesPath(), $event->getModuleCode(), $event->getModulePath());
     }
 }
Example #8
0
 /**
  * helper function allowing you to render a template using a template engine
  *
  * @param string $templateName the template path of the template
  * @param array  $parameters   an array of parameters to assign to a template engine
  *
  * @return string the content generated by a template engine
  */
 public function render($templateName, array $parameters = array())
 {
     $templateDir = $this->assetsResolver->resolveAssetSourcePath($this->module->getCode(), false, $templateName, $this->parser);
     if (null !== $templateDir) {
         // retrieve the template
         $content = $this->parser->render($templateDir . DS . $templateName, $parameters);
     } else {
         $content = sprintf("ERR: Unknown template %s for module %s", $templateName, $this->module->getCode());
     }
     return $content;
 }
 /**
  * @param  \TheliaStudio\Parser\Entity\Table $table
  * @param  \SplFileInfo[]                    $templates
  * @param $resourcesPath
  * @param $moduleCode
  * @throws \Exception
  * @throws \SmartyException
  */
 protected function processTemplate(Table $table, $templates, $resourcesPath, $moduleCode)
 {
     $this->parser->assign("table", $table);
     foreach ($templates as $template) {
         $fetchedTemplate = $this->parser->fetch($template->getRealPath());
         $fileName = str_replace("__TABLE__", str_replace("_", "-", $table->getRawTableName()), $template->getFilename());
         $relativePath = str_replace($resourcesPath, "", $template->getPath() . DS);
         $completeFilePath = THELIA_MODULE_DIR . $moduleCode . DS . $relativePath . DS . $fileName;
         $this->writeFile($completeFilePath, $fetchedTemplate, false, true);
     }
 }
 protected function generateTemplates($resourcesPath, $modulePath, $moduleCode)
 {
     $templates = $this->findInPath($resourcesPath, "/__CONFIG_FORM__.*\\.html/");
     $previousLeft = $this->parser->left_delimiter;
     $previousRight = $this->parser->right_delimiter;
     $this->parser->left_delimiter = '[{';
     $this->parser->right_delimiter = '}]';
     /** @var \SplFileInfo $template */
     foreach ($templates as $template) {
         $fetchedTemplate = $this->parser->fetch($template->getRealPath());
         $relativePath = str_replace($resourcesPath, '', $template->getRealPath());
         $relativePath = str_replace("__CONFIG_FORM__", strtolower($moduleCode), $relativePath);
         $fullPath = $modulePath . $relativePath;
         $this->writeFile($fullPath, $fetchedTemplate, false, true);
     }
     $this->parser->left_delimiter = $previousLeft;
     $this->parser->right_delimiter = $previousRight;
 }
Example #11
0
 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);
             }
         }
     }
 }
Example #12
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);
             }
         }
     }
 }
Example #13
0
 /**
  * Calculate the message body, given the HTML entered in the back-office, the message layout, and the message template
  * @param  ParserInterface $parser
  * @param $message
  * @param $layout
  * @param $template
  * @return bool
  */
 protected function getMessageBody($parser, $message, $layout, $template, $compressOutput = true)
 {
     $body = false;
     // Try to get the body from template file, if a file is defined
     if (!empty($template)) {
         try {
             $body = $parser->render($template, [], $compressOutput);
         } catch (ResourceNotFoundException $ex) {
             // Ignore this.
         }
     }
     // We did not get it ? Use the message entered in the back-office
     if ($body === false) {
         $body = $parser->renderString($message, [], $compressOutput);
     }
     // Do we have a layout ?
     if (!empty($layout)) {
         // Populate the message body variable
         $parser->assign('message_body', $body);
         // Render the layout file
         $body = $parser->render($layout, [], $compressOutput);
     }
     return $body;
 }
Example #14
0
 /**
  * @param  array                     $params
  * @param  string                    $content
  * @param  \Smarty_Internal_Template $template
  * @param  string                    $templateTypeName
  * @return string
  */
 protected function automaticFormFieldRendering($params, $content, $template, $templateFile)
 {
     $data = '';
     $templateStyle = $this->getParam($params, 'template', 'standard');
     $snippet_path = sprintf('%s' . DS . 'forms' . DS . '%s' . DS . '%s.html', $this->parser->getTemplateDefinition()->getAbsolutePath(), $templateStyle, $templateFile);
     if (false !== ($snippet_content = file_get_contents($snippet_path))) {
         $this->processFormField($params, $template);
         $form = $this->getParam($params, 'form', false);
         $field_name = $this->getParam($params, 'field', false);
         $field_extra_class = $this->getParam($params, 'extra_class', '');
         $field_value = $this->getParam($params, 'value', '');
         $show_label = $this->getParam($params, 'show_label', true);
         $value_key = $this->getParam($params, 'value_key', false);
         $template->assign(['content' => trim($content), 'form' => $form, 'field_name' => $field_name, 'field_extra_class' => $field_extra_class, 'field_value' => $field_value, 'field_template' => $templateStyle, 'value_key' => $value_key, 'show_label' => $show_label]);
         $data = $template->fetch(sprintf('string:%s', $snippet_content));
     }
     return $data;
 }
Example #15
0
 /**
  * Add a module template directory to the parser environment
  *
  * @param ParserInterface $parser             the parser
  * @param Module          $module             the Module.
  * @param string          $templateType       the template type (one of the TemplateDefinition type constants)
  * @param string          $templateSubdirName the template subdirectory name (one of the TemplateDefinition::XXX_SUBDIR constants)
  */
 protected function addModuleTemplateToParserEnvironment($parser, $module, $templateType, $templateSubdirName)
 {
     // Get template path
     $templateDirectory = $module->getAbsoluteTemplateDirectoryPath($templateSubdirName);
     try {
         $templateDirBrowser = new \DirectoryIterator($templateDirectory);
         $code = ucfirst($module->getCode());
         /* browse the directory */
         foreach ($templateDirBrowser as $templateDirContent) {
             /* is it a directory which is not . or .. ? */
             if ($templateDirContent->isDir() && !$templateDirContent->isDot()) {
                 $parser->addMethodCall('addTemplateDirectory', array($templateType, $templateDirContent->getFilename(), $templateDirContent->getPathName(), $code));
             }
         }
     } catch (\UnexpectedValueException $ex) {
         // The directory does not exists, ignore it.
     }
 }
Example #16
0
 /**
  * Add a subject and a body (TEXT, HTML or both, depending on the message
  * configuration.
  *
  * @param  ParserInterface $parser
  * @param  \Swift_Message  $messageInstance
  * @param  bool            $useFallbackTemplate When we send mail from a module and don't use the `default` email
  *                                              template, if the file (html/txt) is not found in the template then
  *                                              the template file located in the module under
  *                                              `templates/email/default/' directory is used if
  *                                              `$useFallbackTemplate` is set to `true`.
  */
 public function buildMessage(ParserInterface $parser, \Swift_Message $messageInstance, $useFallbackTemplate = true)
 {
     $parser->setTemplateDefinition($parser->getTemplateHelper()->getActiveMailTemplate(), $useFallbackTemplate);
     $subject = $parser->fetch(sprintf("string:%s", $this->getSubject()));
     $htmlMessage = $this->getHtmlMessageBody($parser);
     $textMessage = $this->getTextMessageBody($parser);
     $messageInstance->setSubject($subject);
     // If we do not have an HTML message
     if (empty($htmlMessage)) {
         // Message body is the text message
         $messageInstance->setBody($textMessage, 'text/plain');
     } else {
         // The main body is the HTML messahe
         $messageInstance->setBody($htmlMessage, 'text/html');
         // Use the text as a message part, if we have one.
         if (!empty($textMessage)) {
             $messageInstance->addPart($textMessage, 'text/plain');
         }
     }
     return $messageInstance;
 }