public function addItem()
 {
     $request = $this->getRequest();
     $cartAdd = $this->getAddCartForm($request);
     $message = null;
     try {
         $form = $this->validateForm($cartAdd);
         $cartEvent = $this->getCartEvent();
         $cartEvent->bindForm($form);
         $this->getDispatcher()->dispatch(TheliaEvents::CART_ADDITEM, $cartEvent);
         $this->afterModifyCart();
         if ($this->getRequest()->isXmlHttpRequest()) {
             $this->changeViewForAjax();
         } else {
             if (null !== ($response = $this->generateSuccessRedirect($cartAdd))) {
                 return $response;
             }
         }
     } catch (PropelException $e) {
         Tlog::getInstance()->error(sprintf("Failed to add item to cart with message : %s", $e->getMessage()));
         $message = $this->getTranslator()->trans("Failed to add this article to your cart, please try again", [], Front::MESSAGE_DOMAIN);
     } catch (FormValidationException $e) {
         $message = $e->getMessage();
     }
     if ($message) {
         $cartAdd->setErrorMessage($message);
         $this->getParserContext()->addForm($cartAdd);
     }
 }
Пример #2
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 updateOrCreateLinkAction($id)
 {
     // Check current user authorization
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, DealerTeam::getModuleCode(), AccessManager::CREATE))) {
         return $response;
     }
     $retour = [];
     $code = 200;
     $con = Propel::getConnection();
     $con->beginTransaction();
     try {
         $data = ['id' => $id];
         $tempOption = $this->getRequest()->request->get("option_id");
         $dafyDealer = [];
         foreach ($tempOption as $option) {
             $data["dealer_option_id"] = $option;
             $temp = $this->getService()->createFromArray($data);
             if ($temp) {
                 $dafyDealer[] = $temp->toArray();
             }
         }
         $con->commit();
         $retour["data"] = $dafyDealer;
     } catch (\Exception $e) {
         $con->rollBack();
         // Any other error
         Tlog::getInstance()->addError($e->getMessage());
         $code = $e->getCode();
         if ($code == 0) {
             $code = 500;
         }
         $retour["message"] = $e->getMessage();
     }
     return JsonResponse::create($retour, $code);
 }
Пример #4
0
 public function process()
 {
     $logger = Tlog::getInstance();
     $logger->setLevel(Tlog::DEBUG);
     $updatedVersions = array();
     $currentVersion = ConfigQuery::read('thelia_version');
     $logger->debug("start update process");
     if (true === $this->isLatestVersion($currentVersion)) {
         $logger->debug("You already have the latest version. No update available");
         throw new UpToDateException('You already have the latest version. No update available');
     }
     $index = array_search($currentVersion, self::$version);
     $con = Propel::getServiceContainer()->getWriteConnection(ProductTableMap::DATABASE_NAME);
     $con->beginTransaction();
     $logger->debug("begin transaction");
     $database = new Database($con->getWrappedConnection());
     try {
         $size = count(self::$version);
         for ($i = ++$index; $i < $size; $i++) {
             $this->updateToVersion(self::$version[$i], $database, $logger);
             $updatedVersions[] = self::$version[$i];
         }
         $con->commit();
         $logger->debug('update successfully');
     } catch (PropelException $e) {
         $con->rollBack();
         $logger->error(sprintf('error during update process with message : %s', $e->getMessage()));
         throw $e;
     }
     $logger->debug('end of update processing');
     return $updatedVersions;
 }
Пример #5
0
 public function delete(ModuleDeleteEvent $event)
 {
     if (null !== ($module = ModuleQuery::create()->findPk($event->getModuleId()))) {
         $con = Propel::getWriteConnection(ModuleTableMap::DATABASE_NAME);
         $con->beginTransaction();
         try {
             if (null === $module->getFullNamespace()) {
                 throw new \LogicException(Translator::getInstance()->trans('Cannot instanciante module "%name%": the namespace is null. Maybe the model is not loaded ?', array('%name%' => $module->getCode())));
             }
             try {
                 $instance = $module->createInstance();
                 $instance->setContainer($this->container);
                 $path = $module->getAbsoluteBaseDir();
                 $instance->destroy($con, $event->getDeleteData());
                 $fs = new Filesystem();
                 $fs->remove($path);
             } catch (\ReflectionException $ex) {
                 // Happens probably because the module directory has been deleted.
                 // Log a warning, and delete the database entry.
                 Tlog::getInstance()->addWarning(Translator::getInstance()->trans('Failed to create instance of module "%name%" when trying to delete module. Module directory has probably been deleted', array('%name%' => $module->getCode())));
             }
             $module->delete($con);
             $con->commit();
             $event->setModule($module);
             $this->cacheClear($event->getDispatcher());
         } catch (\Exception $e) {
             $con->rollBack();
             throw $e;
         }
     }
 }
Пример #6
0
 public static function setUpBeforeClass()
 {
     self::$logger = Tlog::getInstance();
     self::$logger->setDestinations("Thelia\\Log\\Destination\\TlogDestinationText");
     self::$logger->setLevel(Tlog::DEBUG);
     self::$logger->setFiles("*");
 }
 public function createRuleAction()
 {
     if (null !== ($response = $this->checkAuth(array(), array('FreeShipping'), AccessManager::CREATE))) {
         return $response;
     }
     $ruleCreationForm = new FreeShippingRuleCreationForm($this->getRequest());
     $message = false;
     try {
         $form = $this->validateForm($ruleCreationForm);
         $event = $this->createEventInstance($form->getData());
         $this->areaId = $form->get('area')->getData();
         if (null === $this->getExistingObject()) {
             $this->dispatch(FreeShippingEvents::FREE_SHIPPING_RULE_CREATE, $event);
             return $this->generateSuccessRedirect($ruleCreationForm);
         } else {
             throw new \Exception("A rule with this area already exist");
         }
     } catch (FormValidationException $e) {
         $message = sprintf("Please check your input: %s", $e->getMessage());
     } catch (PropelException $e) {
         $message = $e->getMessage();
     } catch (\Exception $e) {
         $message = sprintf("Sorry, an error occured: %s", $e->getMessage() . " " . $e->getFile());
     }
     if ($message !== false) {
         \Thelia\Log\Tlog::getInstance()->error(sprintf("Error during free shipping rule creation process : %s.", $message));
         $ruleCreationForm->setErrorMessage($message);
         $this->getParserContext()->addForm($ruleCreationForm)->setGeneralError($message);
     }
     // Redirect
     return $this->generateRedirectFromRoute('admin.module.configure', array(), array('module_code' => 'FreeShipping'));
 }
Пример #8
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());
         }
     }
 }
Пример #9
0
 protected function logAlertMessage($message, $failSafe = false)
 {
     Tlog::getInstance()->addAlert($message);
     if (!$failSafe && $this->debugEnabled) {
         throw new \InvalidArgumentException($message);
     }
 }
Пример #10
0
 public function subscribeAction()
 {
     $errorMessage = false;
     $newsletterForm = new NewsletterForm($this->getRequest());
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname());
             $event->setLastname($customer->getLastname());
         } else {
             $event->setFirstname($form->get('firstname')->getData());
             $event->setLastname($form->get('lastname')->getData());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
     }
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         $response = new JsonResponse();
         if ($errorMessage) {
             $response = $response->setContent(array("success" => false, "message" => $errorMessage));
         } else {
             $response = $response->setContent(array("success" => true, "message" => $this->getTranslator()->trans("Thanks for signing up! We'll keep you posted whenever we have any new updates.")));
         }
         return $response;
     } else {
         $newsletterForm->setErrorMessage($errorMessage);
         $this->getParserContext()->addForm($newsletterForm)->setGeneralError($errorMessage);
     }
 }
Пример #11
0
 public function subscribeAction()
 {
     $errorMessage = false;
     $newsletterForm = $this->createForm(FrontForm::NEWSLETTER);
     try {
         $form = $this->validateForm($newsletterForm);
         $event = new NewsletterEvent($form->get('email')->getData(), $this->getRequest()->getSession()->getLang()->getLocale());
         /** @var Customer $customer */
         if (null !== ($customer = $this->getSecurityContext()->getCustomerUser())) {
             $event->setFirstname($customer->getFirstname())->setLastname($customer->getLastname());
         } else {
             $event->setFirstname($form->get('firstname')->getData())->setLastname($form->get('lastname')->getData());
         }
         $this->dispatch(TheliaEvents::NEWSLETTER_SUBSCRIBE, $event);
         // If a success URL is defined in the form, redirect to it, otherwise use the defaut view
         if ($newsletterForm->hasSuccessUrl() && !$this->getRequest()->isXmlHttpRequest()) {
             return $this->generateSuccessRedirect($newsletterForm);
         }
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
         Tlog::getInstance()->error(sprintf('Error during newsletter subscription : %s', $errorMessage));
         $newsletterForm->setErrorMessage($errorMessage);
     }
     // If Ajax Request
     if ($this->getRequest()->isXmlHttpRequest()) {
         return new JsonResponse(["success" => $errorMessage ? false : true, "message" => $errorMessage ? $errorMessage : $this->getTranslator()->trans("Thanks for signing up! We'll keep you posted whenever we have any new updates.", [], Front::MESSAGE_DOMAIN)], $errorMessage ? 500 : 200);
     }
     $this->getParserContext()->setGeneralError($errorMessage)->addForm($newsletterForm);
     // If an error URL is defined in the form, redirect to it, otherwise use the defaut view
     if ($errorMessage && $newsletterForm->hasErrorUrl()) {
         return $this->generateErrorRedirect($newsletterForm);
     }
 }
Пример #12
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());
         }
     }
 }
Пример #13
0
 /**
  * @return Tlog
  */
 protected function setTLogPaypal()
 {
     /*
      * Write Log
      */
     $this->log = Tlog::getInstance();
     $this->log->setDestinations(self::LOGCLASS);
     $this->log->setConfig(self::LOGCLASS, 0, THELIA_ROOT . "log" . DS . "log-paypal.txt");
 }
Пример #14
0
 protected function renderTemplate()
 {
     $destinations = array();
     $destination_directories = Tlog::getInstance()->getDestinationsDirectories();
     foreach ($destination_directories as $dir) {
         $this->loadDefinedDestinations($dir, $destinations);
     }
     $active_destinations = explode(";", ConfigQuery::read(Tlog::VAR_DESTINATIONS, Tlog::DEFAUT_DESTINATIONS));
     return $this->render('system-logs', array('ip_address' => $this->getRequest()->getClientIp(), 'destinations' => $destinations, 'active_destinations' => $active_destinations));
 }
Пример #15
0
 /**
  * A simple helper to insert an entry in the admin log
  *
  * @param $resource
  * @param $action
  * @param $message
  * @param Request       $request
  * @param UserInterface $adminUser
  * @param bool          $withRequestContent
  */
 public static function append($resource, $action, $message, Request $request, UserInterface $adminUser = null, $withRequestContent = true)
 {
     $log = new AdminLog();
     $log->setAdminLogin($adminUser !== null ? $adminUser->getUsername() : '<no login>')->setAdminFirstname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getFirstname() : '<no first name>')->setAdminLastname($adminUser !== null && $adminUser instanceof Admin ? $adminUser->getLastname() : '<no last name>')->setResource($resource)->setAction($action)->setMessage($message)->setRequest($request->toString($withRequestContent));
     try {
         $log->save();
     } catch (\Exception $ex) {
         Tlog::getInstance()->err("Failed to insert new entry in AdminLog: {ex}", array('ex' => $ex));
     }
 }
Пример #16
0
 public function parseResults(LoopResult $results)
 {
     $results = parent::parseResults($results);
     foreach ($results as $loopResultRow) {
         $accessoryProductId = $loopResultRow->get('ID');
         \Thelia\Log\Tlog::getInstance()->notice($this->accessoryId);
         $loopResultRow->set("ID", $this->accessoryId[$accessoryProductId])->set("POSITION", $this->accessoryPosition[$accessoryProductId])->set("ACCESSORY_ID", $accessoryProductId);
     }
     return $results;
 }
Пример #17
0
 /**
  * @throws \Exception
  */
 public function receiveResponse()
 {
     $request = $this->getRequest();
     $order_id = $request->get('reference');
     if (is_numeric($order_id)) {
         $order_id = (int) $order_id;
     }
     /*
      * Configure log output
      */
     $log = Tlog::getInstance();
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationFile");
     $log->setConfig("\\Thelia\\Log\\Destination\\TlogDestinationFile", 0, THELIA_ROOT . "log" . DS . "log-cmcic.txt");
     $log->info("accessed");
     $order = OrderQuery::create()->findPk($order_id);
     /*
      * Retrieve HMac for CGI2
      */
     $config = Config::read(CmCIC::JSON_CONFIG_PATH);
     $hashable = sprintf(CmCIC::CMCIC_CGI2_FIELDS, $config['CMCIC_TPE'], $request->get('date'), $request->get('montant'), $request->get('reference'), $request->get('texte-libre'), $config['CMCIC_VERSION'], $request->get('code-retour'), $request->get('cvx'), $request->get('vld'), $request->get('brand'), $request->get('status3ds'), $request->get('numauto'), $request->get('motifrefus'), $request->get('originecb'), $request->get('bincb'), $request->get('hpancb'), $request->get('ipclient'), $request->get('originetr'), $request->get('veres'), $request->get('pares'));
     $mac = CmCIC::computeHmac($hashable, CmCIC::getUsableKey($config["CMCIC_KEY"]));
     $response = CmCIC::CMCIC_CGI2_MACNOTOK . $hashable;
     if ($mac === strtolower($request->get('MAC'))) {
         $code = $request->get("code-retour");
         $msg = null;
         $status = OrderStatusQuery::create()->findOneByCode(OrderStatus::CODE_PAID);
         $event = new OrderEvent($order);
         $event->setStatus($status->getId());
         switch ($code) {
             case "payetest":
                 $msg = "The test payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "paiement":
                 $msg = "The payment of the order " . $order->getRef() . " has been successfully released. ";
                 $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event);
                 break;
             case "Annulation":
                 $msg = "Error during the paiement: " . $this->getRequest()->get("motifrefus");
                 break;
             default:
                 $log->error("Error while receiving response from CMCIC: code-retour not valid");
                 throw new \Exception(Translator::getInstance()->trans("An error occured, no valid code-retour"));
         }
         if (!empty($msg)) {
             $log->info($msg);
         }
         $response = CmCIC::CMCIC_CGI2_MACOK;
     }
     /*
      * Get log back to previous state
      */
     $log->setDestinations("\\Thelia\\Log\\Destination\\TlogDestinationRotatingFile");
     return Response::create(sprintf(CmCIC::CMCIC_CGI2_RECEIPT, $response), 200, array("Content-type" => "text/plain", "Pragma" => "nocache"));
 }
Пример #18
0
 /**
  * Send email to notify customer that files for virtual products are available
  *
  * @param OrderEvent $event
  * @throws \Exception
  */
 public function sendEmail(OrderEvent $event)
 {
     $order = $event->getOrder();
     // Be sure that we have a document to download
     $virtualProductCount = OrderProductQuery::create()->filterByOrderId($order->getId())->filterByVirtual(true)->filterByVirtualDocument(null, Criteria::NOT_EQUAL)->count();
     if ($virtualProductCount > 0) {
         $customer = $order->getCustomer();
         $this->mailer->sendEmailToCustomer('mail_virtualproduct', $customer, ['customer_id' => $customer->getId(), 'order_id' => $order->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt()]);
     } else {
         Tlog::getInstance()->warning("Virtual product download message not sent to customer: there's nothing to downnload");
     }
 }
Пример #19
0
 public function initDebugBar()
 {
     $alternativelogger = null;
     if ($this->debugMode) {
         $alternativelogger = \Thelia\Log\Tlog::getInstance();
     }
     $this->debugBar->addCollector(new PhpInfoCollector());
     //$this->debugBar->addCollector(new MessagesCollector());
     //$this->debugBar->addCollector(new RequestDataCollector());
     $this->debugBar->addCollector(new TimeDataCollector());
     $this->debugBar->addCollector(new MemoryCollector());
     $this->debugBar->addCollector(new PropelCollector($alternativelogger));
 }
Пример #20
0
 public static function exec($url, $status = 302, $cookies = array())
 {
     trigger_error('deprecated since version 2.1 and will be removed in 2.3. A response can not be send before the end of the script. Please use RedirectResponse directly', E_USER_DEPRECATED);
     if (false == Tlog::getInstance()->showRedirect($url)) {
         $response = new RedirectResponse($url, $status);
         foreach ($cookies as $cookie) {
             if (!$cookie instanceof Cookie) {
                 throw new \InvalidArgumentException(sprintf('Third parameter is not a valid Cookie object.'));
             }
             $response->headers->setCookie($cookie);
         }
         $response->send();
     }
 }
Пример #21
0
 public function updateStatus(OrderEvent $event)
 {
     $order = $event->getOrder();
     if ($order->isPaid() && $order->getPaymentModuleId() == Atos::getModuleId()) {
         if (Atos::getConfigValue('send_payment_confirmation_message')) {
             $this->mailer->sendEmailToCustomer(Atos::CONFIRMATION_MESSAGE_NAME, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
         }
         // Send confirmation email if required.
         if (Atos::getConfigValue('send_confirmation_message_only_if_paid')) {
             $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
         }
         Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
     }
 }
Пример #22
0
 public function redimlive($type, $id, $offset, $width, $height, $resizeMode = 'none')
 {
     $object = ucfirst($type);
     $queryClass = sprintf("Thelia\\Model\\%sImageQuery", $object);
     $filterMethod = sprintf("filterBy%sId", $object);
     // xxxImageQuery::create()
     $method = new \ReflectionMethod($queryClass, 'create');
     /** @var ModelCriteria $search */
     $search = $method->invoke(null);
     // Static !
     // $query->filterByXXX(id)
     $method = new \ReflectionMethod($queryClass, $filterMethod);
     $method->invoke($search, $id);
     $search->orderByPosition(Criteria::ASC)->offset(max(0, $offset - 1))->limit(1);
     if (null !== ($image = $search->findOne())) {
         switch ($resizeMode) {
             case 'crop':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
                 break;
             case 'borders':
                 $resizeMode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
                 break;
             case 'none':
             default:
                 $resizeMode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
         }
         $baseSourceFilePath = ConfigQuery::read('images_library_path');
         if ($baseSourceFilePath === null) {
             $baseSourceFilePath = THELIA_LOCAL_DIR . 'media' . DS . 'images';
         } else {
             $baseSourceFilePath = THELIA_ROOT . $baseSourceFilePath;
         }
         // Put source image file path
         $sourceFilePath = sprintf('%s/%s/%s', $baseSourceFilePath, $object, $image->getFile());
         // Create image processing event
         $event = new ImageEvent($this->getRequest());
         $event->setSourceFilepath($sourceFilePath)->setCacheSubdirectory($object)->setWidth($width)->setHeight($height)->setResizeMode($resizeMode);
         try {
             // Dispatch image processing event
             $this->getDispatcher()->dispatch(TheliaEvents::IMAGE_PROCESS, $event);
             return Response::create(file_get_contents($event->getCacheFilepath()), 200, array('Content-type' => image_type_to_mime_type(exif_imagetype($event->getCacheFilepath()))));
         } catch (\Exception $ex) {
             Tlog::getInstance()->addError(sprintf("Failed to process image: %s", $ex->getMessage()));
             return new Response("", 500);
         }
     } else {
         $this->pageNotFound();
     }
 }
Пример #23
0
 public function addWatermark(ImageEvent $event)
 {
     $image = $event->getImageObject();
     $size = $image->getSize();
     Tlog::getInstance()->debug("Category: " . $event->getCacheSubdirectory());
     if ($event->getCacheSubdirectory() == 'product' && $size->getHeight() > 200) {
         $imagine = $this->createImagineInstance();
         $watermark = $imagine->open(__DIR__ . DS . '..' . DS . '/Config/watermark.png');
         $watermark->resize($watermark->getSize()->heighten(round(0.1 * $size->getHeight())));
         $wSize = $watermark->getSize();
         $delta = round(0.02 * $size->getHeight());
         $bottomRight = new Point($size->getWidth() - $wSize->getWidth() - $delta, $size->getHeight() - $wSize->getHeight() - $delta);
         $image->paste($watermark, $bottomRight);
     }
 }
Пример #24
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) {
             $order = $event->getOrder();
             $customer = $order->getCustomer();
             $this->mailer->sendEmailToCustomer('mail_colissimo', $customer, ['customer_id' => $customer->getId(), 'order_ref' => $order->getRef(), 'order_date' => $order->getCreatedAt(), 'update_date' => $order->getUpdatedAt(), 'package' => $order->getDeliveryRef()]);
             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());
         }
     }
 }
 public function flushImagesAndDocumentsAction()
 {
     if (null !== ($result = $this->checkAuth(AdminResources::ADVANCED_CONFIGURATION, [], AccessManager::UPDATE))) {
         return $result;
     }
     $form = $this->createForm(AdminForm::IMAGES_AND_DOCUMENTS_CACHE_FLUSH);
     try {
         $this->validateForm($form);
         $event = new CacheEvent(THELIA_WEB_DIR . ConfigQuery::read('image_cache_dir_from_web_root', 'cache' . DS . 'images'));
         $this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
         $event = new CacheEvent(THELIA_WEB_DIR . ConfigQuery::read('document_cache_dir_from_web_root', 'cache' . DS . 'documents'));
         $this->dispatch(TheliaEvents::CACHE_CLEAR, $event);
     } catch (\Exception $e) {
         Tlog::getInstance()->addError(sprintf("Flush images and document error: %s", $e->getMessage()));
     }
     return $this->generateRedirectFromRoute('admin.configuration.advanced');
 }
Пример #26
0
 public function parseTemplate($templateType, $template)
 {
     $templateDefinition = new TemplateDefinition($template, $templateType);
     $hooks = array();
     $this->walkDir($templateDefinition->getAbsolutePath(), $hooks);
     // load language message
     $locale = Lang::getDefaultLanguage()->getLocale();
     $this->loadTrans($templateType, $locale);
     $ret = array();
     foreach ($hooks as $hook) {
         try {
             $ret[] = $this->prepareHook($hook);
         } catch (\UnexpectedValueException $ex) {
             Tlog::getInstance()->warning($ex->getMessage());
         }
     }
     return $ret;
 }
Пример #27
0
 /**
  * send contact message
  */
 public function sendAction()
 {
     $contactForm = new ContactForm($this->getRequest());
     try {
         $form = $this->validateForm($contactForm);
         $message = \Swift_Message::newInstance($form->get('subject')->getData())->addFrom(ConfigQuery::getStoreEmail(), $form->get('name')->getData())->addReplyTo($form->get('email')->getData(), $form->get('name')->getData())->addTo(ConfigQuery::getStoreEmail(), ConfigQuery::getStoreName())->setBody($form->get('message')->getData());
         $this->getMailer()->send($message);
         if (null !== ($successUrl = $this->retrieveSuccessUrl($contactForm))) {
             return $this->generateRedirect($successUrl);
         }
         return $this->generateRedirectFromRoute('contact.success');
     } catch (FormValidationException $e) {
         $error_message = $e->getMessage();
     }
     Tlog::getInstance()->error(sprintf('Error during sending contact mail : %s', $error_message));
     $contactForm->setErrorMessage($error_message);
     $this->getParserContext()->addForm($contactForm)->setGeneralError($error_message);
 }
Пример #28
0
 public function useAddressAction()
 {
     if (null !== ($response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))) {
         return $response;
     }
     $address_id = $this->getRequest()->request->get('address_id');
     try {
         $address = AddressQuery::create()->findPk($address_id);
         if (null === $address) {
             throw new \InvalidArgumentException(sprintf('%d address does not exists', $address_id));
         }
         $addressEvent = new AddressEvent($address);
         $this->dispatch(TheliaEvents::ADDRESS_DEFAULT, $addressEvent);
         $this->adminLogAppend($this->resourceCode, AccessManager::UPDATE, sprintf("address %d for customer %d set as default address", $address_id, $address->getCustomerId()), $address_id);
     } catch (\Exception $e) {
         \Thelia\Log\Tlog::getInstance()->error(sprintf("error during address setting as default with message %s", $e->getMessage()));
     }
     return $this->redirectToEditionTemplate();
 }
Пример #29
0
 /**
  * Checks if we are the payment module for the order, and if the order is paid,
  * then send a confirmation email to the customer.
  *
  * @param OrderEvent $event
  * @throws \Exception
  */
 public function updateOrderStatus(OrderEvent $event)
 {
     $paybox = new Paybox();
     if ($event->getOrder()->isPaid() && $paybox->isPaymentModuleFor($event->getOrder())) {
         $contact_email = ConfigQuery::read('store_email', false);
         Tlog::getInstance()->debug("Order " . $event->getOrder()->getRef() . ": sending confirmation email from store contact e-mail {$contact_email}");
         if ($contact_email) {
             $order = $event->getOrder();
             $this->getMailer()->sendEmailToCustomer(Paybox::CONFIRMATION_MESSAGE_NAME, $order->getCustomer(), ['order_id' => $order->getId(), 'order_ref' => $order->getRef()]);
             Tlog::getInstance()->debug("Order " . $order->getRef() . ": confirmation email sent to customer.");
             if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
                 // Send now the order confirmation email to the customer
                 $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
             }
         }
     } else {
         Tlog::getInstance()->debug("Order " . $event->getOrder()->getRef() . ": no confirmation email sent (order not paid, or not the proper payment module).");
     }
 }
 public function createAction($source_id)
 {
     $form = new ViewForm($this->getRequest());
     try {
         $viewForm = $this->validateForm($form);
         $data = $viewForm->getData();
         $event = new ViewEvent($data['view'], $data['source'], $data['source_id']);
         if ($data['has_subtree'] != 0) {
             $event->setChildrenView($data['children_view'])->setSubtreeView($data['subtree_view']);
         }
         $this->dispatch('view.create', $event);
         return $this->generateSuccessRedirect($form);
     } catch (\Exception $ex) {
         $error_message = $ex->getMessage();
         Tlog::getInstance()->error("Failed to validate View form: {$error_message}");
     }
     $this->setupFormErrorContext('Failed to process View form data', $error_message, $form);
     $sourceType = $this->getRequest()->get('source_type');
     return $this->render($sourceType . '-edit', [$sourceType . '_id' => $source_id, 'current_tab' => 'modules']);
 }