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();
 }
Exemple #2
0
 /**
  * Save the previous URL in session which is based on the referer header or the request, or
  * the _previous_url request attribute, if defined.
  *
  * If the value of _previous_url is "dont-save", the current referrer is not saved.
  *
  * @param FilterResponseEvent $event
  */
 public function registerPreviousUrl(PostResponseEvent $event)
 {
     $request = $event->getRequest();
     $referrer = $request->attributes->get('_previous_url', null);
     if (null !== $referrer) {
         // A previous URL (or the keyword 'dont-save') has been specified.
         if ('dont-save' == $referrer) {
             // We should not save the current URL as the previous URL
             $referrer = null;
         }
     } else {
         // The current URL will become the previous URL
         $referrer = $request->getUri();
     }
     // Set previous URL, if defined
     if (null !== $referrer) {
         $session = $request->getSession();
         if (ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
             $components = parse_url($referrer);
             $lang = LangQuery::create()->filterByUrl(sprintf("%s://%s", $components["scheme"], $components["host"]), ModelCriteria::LIKE)->findOne();
             if (null !== $lang) {
                 $session->setReturnToUrl($referrer);
             }
         } else {
             if (false !== strpos($referrer, $request->getSchemeAndHttpHost())) {
                 $session->setReturnToUrl($referrer);
             }
         }
     }
 }
 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();
     }
 }
 /**
  * Validate a date entered with the default Language date format.
  *
  * @param string                    $value
  * @param ExecutionContextInterface $context
  */
 public function checkLocalizedDate($value, ExecutionContextInterface $context)
 {
     $format = LangQuery::create()->findOneByByDefault(true)->getDateFormat();
     if (false === \DateTime::createFromFormat($format, $value)) {
         $context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => $format, '%date' => $value]));
     }
 }
Exemple #5
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 uploadImage()
 {
     if (null !== ($response = $this->checkAuth(AdminResources::MODULE, ['carousel'], AccessManager::CREATE))) {
         return $response;
     }
     $request = $this->getRequest();
     $form = $this->createForm('carousel.image');
     $error_message = null;
     try {
         $this->validateForm($form);
         /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $fileBeingUploaded */
         $fileBeingUploaded = $request->files->get(sprintf('%s[file]', $form->getName()), null, true);
         $fileModel = new Carousel();
         $fileCreateOrUpdateEvent = new FileCreateOrUpdateEvent(1);
         $fileCreateOrUpdateEvent->setModel($fileModel);
         $fileCreateOrUpdateEvent->setUploadedFile($fileBeingUploaded);
         $this->dispatch(TheliaEvents::IMAGE_SAVE, $fileCreateOrUpdateEvent);
         // Compensate issue #1005
         $langs = LangQuery::create()->find();
         /** @var Lang $lang */
         foreach ($langs as $lang) {
             $fileCreateOrUpdateEvent->getModel()->setLocale($lang->getLocale())->setTitle('')->save();
         }
         $response = $this->redirectToConfigurationPage();
     } catch (FormValidationException $e) {
         $error_message = $this->createStandardFormValidationErrorMessage($e);
     }
     if (null !== $error_message) {
         $this->setupFormErrorContext('carousel upload', $error_message, $form);
         $response = $this->render("module-configure", ['module_code' => 'Carousel']);
     }
     return $response;
 }
Exemple #7
0
 public function setUp()
 {
     $this->locale = LangQuery::create()->findOne()->getLocale();
     $this->dispatcher = $this->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->disableOriginalConstructor()->getMock();
     $this->action = new Hook($stubContainer);
 }
Exemple #8
0
 protected function retrieveLocale($viewLocale)
 {
     if (strlen($viewLocale) == 2) {
         if (null !== ($lang = LangQuery::create()->findOneByCode($viewLocale))) {
             $viewLocale = $lang->getLocale();
         }
     }
     return $viewLocale;
 }
 protected function applyUserLocale(Admin $user)
 {
     // Set the current language according to Admin locale preference
     $locale = $user->getLocale();
     if (null === ($lang = LangQuery::create()->findOneByLocale($locale))) {
         $lang = Lang::getDefaultLanguage();
     }
     $this->getSession()->setLang($lang);
 }
 protected function getLocaleList()
 {
     $locales = array();
     $list = LangQuery::create()->find();
     foreach ($list as $item) {
         $locales[$item->getLocale()] = $item->getLocale();
     }
     return $locales;
 }
 public function updateAction($lang_id)
 {
     if (null !== ($response = $this->checkAuth(AdminResources::LANGUAGE, array(), AccessManager::UPDATE))) {
         return $response;
     }
     $this->checkXmlHttpRequest();
     $lang = LangQuery::create()->findPk($lang_id);
     $langForm = $this->createForm(AdminForm::LANG_UPDATE, 'form', array('id' => $lang->getId(), 'title' => $lang->getTitle(), 'code' => $lang->getCode(), 'locale' => $lang->getLocale(), 'date_time_format' => $lang->getDateTimeFormat(), 'date_format' => $lang->getDateFormat(), 'time_format' => $lang->getTimeFormat(), 'decimal_separator' => $lang->getDecimalSeparator(), 'thousands_separator' => $lang->getThousandsSeparator(), 'decimals' => $lang->getDecimals()));
     $this->getParserContext()->addForm($langForm);
     return $this->render('ajax/language-update-modal', array('lang_id' => $lang_id));
 }
Exemple #12
0
 /**
  * @param  integer  $id
  * @return Response
  *
  * This method is called when the route /admin/export/{id}
  * is called with a POST request.
  */
 public function export($id)
 {
     if (null === ($export = $this->getExport($id))) {
         return $this->pageNotFound();
     }
     /**
      * Get needed services
      */
     $archiveBuilderManager = $this->getArchiveBuilderManager($this->container);
     $formatterManager = $this->getFormatterManager($this->container);
     /**
      * Get the archive builders
      */
     $archiveBuilders = [];
     foreach ($archiveBuilderManager->getNames() as $archiveBuilder) {
         $archiveBuilders[$archiveBuilder] = $archiveBuilder;
     }
     /**
      * Define and validate the form
      */
     $form = new ExportForm($this->getRequest());
     $errorMessage = null;
     try {
         $boundForm = $this->validateForm($form);
         $lang = LangQuery::create()->findPk($boundForm->get("language")->getData());
         $archiveBuilder = null;
         /**
          * Get the formatter and the archive builder if we have to compress the file(s)
          */
         /** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
         $formatter = $formatterManager->get($boundForm->get("formatter")->getData());
         if ($boundForm->get("do_compress")->getData()) {
             /** @var \Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface $archiveBuilder */
             $archiveBuilder = $archiveBuilderManager->get($boundForm->get("archive_builder")->getData());
         }
         /**
          * Return the generated Response
          */
         return $this->processExport($formatter, $export->getHandleClassInstance($this->container), $archiveBuilder, $lang, $boundForm->get("images")->getData(), $boundForm->get("documents")->getData());
     } catch (FormValidationException $e) {
         $errorMessage = $this->createStandardFormValidationErrorMessage($e);
     } catch (\Exception $e) {
         $errorMessage = $e->getMessage();
     }
     /**
      * If has an error, display it
      */
     if (null !== $errorMessage) {
         $form->setErrorMessage($errorMessage);
         $this->getParserContext()->addForm($form)->setGeneralError($errorMessage);
     }
     return $this->exportView($id);
 }
Exemple #13
0
 public function buildModelCriteria()
 {
     $search = LangQuery::create();
     if (null !== ($id = $this->getId())) {
         $search->filterById($id, Criteria::IN);
     }
     if (null !== ($code = $this->getCode())) {
         $search->filterByCode($code, Criteria::IN);
     }
     if (null !== ($locale = $this->getLocale())) {
         $search->filterByLocale($locale, Criteria::IN);
     }
     if (!$this->getBackendContext() && Type\BooleanOrBothType::ANY !== ($visible = $this->getVisible())) {
         $search->filterByVisible($visible);
     }
     if (Type\BooleanOrBothType::ANY !== ($active = $this->getActive())) {
         $search->filterByActive($active);
     }
     if ($this->getDefaultOnly()) {
         $search->filterByByDefault(true);
     }
     if ($this->getExcludeDefault()) {
         $search->filterByByDefault(false);
     }
     if (null !== ($exclude = $this->getExclude())) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "id":
                 $search->orderById(Criteria::ASC);
                 break;
             case "id_reverse":
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->orderByTitle(Criteria::ASC);
                 break;
             case "alpha_reverse":
                 $search->orderByTitle(Criteria::DESC);
                 break;
             case "position":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "position_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
Exemple #14
0
 /**
  * populate a list of field for each locale for an object
  *
  * @param mixed $object     the object to populate
  * @param array $fields     list of field to populate
  * @param array $localeList list of locale to use populate the object
  */
 protected function setI18n(&$object, $fields = array("Title"), $localeList = null)
 {
     if (null === $localeList) {
         if (null === self::$localeList) {
             self::$localeList = LangQuery::create()->select("Locale")->find()->toArray();
         }
         $localeList = self::$localeList;
     }
     foreach ($localeList as $locale) {
         foreach ($fields as $name) {
             $object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name);
         }
     }
 }
 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();
     }
 }
 public function getTaxonomy($langId = null)
 {
     $lang = LangQuery::create()->findOneById($langId);
     if ($lang === null) {
         $lang = Lang::getDefaultLanguage();
     }
     $file = file_get_contents("http://www.google.com/basepages/producttype/taxonomy." . str_replace("_", "-", $lang->getLocale()) . ".txt");
     $rows = explode("\n", $file);
     $cats = [];
     foreach ($rows as $row) {
         $splittedCat = explode('>', $row);
         $name = end($splittedCat);
         $cats[$name] = htmlspecialchars($row);
     }
     return new JsonResponse(['cats' => $cats]);
 }
 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();
     }
 }
Exemple #18
0
 public function toggleDefault()
 {
     if ($this->getId() === null) {
         throw new \RuntimeException("impossible to just uncheck default language, choose a new one");
     }
     $con = Propel::getWriteConnection(LangTableMap::DATABASE_NAME);
     $con->beginTransaction();
     try {
         LangQuery::create()->filterByByDefault(1)->update(array('ByDefault' => 0), $con);
         $this->setByDefault(1)->save($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
Exemple #19
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 buildModelCriteria()
 {
     $query = GoogleshoppingProductSynchronisationQuery::create()->filterByProductId($this->getProductId());
     if ($this->getCountry()) {
         $targetCountry = $this->getCountry();
     } else {
         $targetCountry = Country::getDefaultCountry()->getIsoalpha2();
     }
     if ($this->getLocale()) {
         $lang = LangQuery::create()->findOneByLocale($this->getLocale())->getCode();
     } else {
         $lang = Lang::getDefaultLanguage()->getCode();
     }
     $query->filterByTargetCountry($targetCountry)->filterByLang($lang);
     return $query;
 }
 /**
  * @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();
     }
 }
 public function testUpdate()
 {
     $admin = AdminQuery::create()->findOne();
     $login = '******' . uniqid();
     $locale = LangQuery::create()->findOne()->getLocale();
     $adminEvent = new AdministratorEvent();
     $adminEvent->setId($admin->getId())->setFirstname('thelia_update')->setLastname('thelia_update')->setLogin($login)->setPassword('azertyuiop')->setLocale($locale)->setEmail(uniqid() . '@example.com')->setDispatcher($this->getMockEventDispatcher());
     $actionAdmin = new Administrator($this->mailerFactory, $this->tokenProvider);
     $actionAdmin->update($adminEvent, null, $this->getMockEventDispatcher());
     $updatedAdmin = $adminEvent->getAdministrator();
     $this->assertInstanceOf("Thelia\\Model\\Admin", $updatedAdmin);
     $this->assertFalse($updatedAdmin->isNew());
     $this->assertEquals($adminEvent->getFirstname(), $updatedAdmin->getFirstname());
     $this->assertEquals($adminEvent->getLastname(), $updatedAdmin->getLastname());
     $this->assertEquals($adminEvent->getLogin(), $updatedAdmin->getLogin());
     $this->assertEquals($adminEvent->getLocale(), $updatedAdmin->getLocale());
     $this->assertEquals($adminEvent->getProfile(), $updatedAdmin->getProfileId());
     $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
 }
 public function testUpdate()
 {
     $admin = AdminQuery::create()->findOne();
     $login = '******' . uniqid();
     $locale = LangQuery::create()->findOne()->getLocale();
     $adminEvent = new AdministratorEvent();
     $adminEvent->setId($admin->getId())->setFirstname('thelia_update')->setLastname('thelia_update')->setLogin($login)->setPassword('azertyuiop')->setLocale($locale)->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $actionAdmin = new Administrator();
     $actionAdmin->update($adminEvent);
     $updatedAdmin = $adminEvent->getAdministrator();
     $this->assertInstanceOf("Thelia\\Model\\Admin", $updatedAdmin);
     $this->assertFalse($updatedAdmin->isNew());
     $this->assertEquals($adminEvent->getFirstname(), $updatedAdmin->getFirstname());
     $this->assertEquals($adminEvent->getLastname(), $updatedAdmin->getLastname());
     $this->assertEquals($adminEvent->getLogin(), $updatedAdmin->getLogin());
     $this->assertEquals($adminEvent->getLocale(), $updatedAdmin->getLocale());
     $this->assertEquals($adminEvent->getProfile(), $updatedAdmin->getProfileId());
     $this->assertTrue(password_verify($adminEvent->getPassword(), $updatedAdmin->getPassword()));
 }
Exemple #24
0
 /**
  * Create and save the id of the pop-in images folder if necessary.
  *
  * @throws \Exception
  * @throws PropelException
  */
 protected function createPopInImageFolder()
 {
     $imageFolderIdConfig = ConfigQuery::create()->findOneByName(static::CONF_KEY_IMAGE_FOLDER_ID);
     if (null !== $imageFolderIdConfig && null !== FolderQuery::create()->findPk($imageFolderIdConfig->getValue())) {
         // we already have and know our images folder
         return;
     }
     Propel::getConnection()->beginTransaction();
     try {
         // create the folder
         $folder = new Folder();
         $folder->setVisible(true);
         /** @var Lang $lang */
         foreach (LangQuery::create()->find() as $lang) {
             $localizedTitle = Translator::getInstance()->trans("Pop-in images", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
             if ($localizedTitle == "") {
                 continue;
             }
             $folder->setLocale($lang->getLocale())->setTitle($localizedTitle);
         }
         $folder->save();
         // save the folder id in configuration
         if ($folder->getId() !== null) {
             $config = new Config();
             $config->setName(static::CONF_KEY_IMAGE_FOLDER_ID)->setValue($folder->getId())->setHidden(false);
             /** @var Lang $lang */
             foreach (LangQuery::create()->find() as $lang) {
                 $localizedTitle = Translator::getInstance()->trans("Pop-in images folder id", [], static::MESSAGE_DOMAIN_BO, $lang->getLocale(), false);
                 if ($localizedTitle == "") {
                     continue;
                 }
                 $config->setLocale($lang->getLocale())->setTitle($localizedTitle);
             }
             $config->save();
         }
     } catch (\Exception $e) {
         Propel::getConnection()->rollBack();
         throw $e;
     }
     Propel::getConnection()->commit();
 }
Exemple #25
0
 public function buildModelCriteria()
 {
     $id = $this->getId();
     $exclude = $this->getExclude();
     $default_only = $this->getDefaultOnly();
     $search = LangQuery::create();
     if (!is_null($id)) {
         $search->filterById($id);
     }
     if ($default_only) {
         $search->filterByByDefault(true);
     }
     if (!is_null($exclude)) {
         $search->filterById($exclude, Criteria::NOT_IN);
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case "id":
                 $search->orderById(Criteria::ASC);
                 break;
             case "id_reverse":
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->orderByTitle(Criteria::ASC);
                 break;
             case "alpha_reverse":
                 $search->orderByTitle(Criteria::DESC);
                 break;
             case "position":
                 $search->orderByPosition(Criteria::ASC);
                 break;
             case "position_reverse":
                 $search->orderByPosition(Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
 /**
  *
  * in this function you add all the fields you need for your Form.
  * Form this you have to call add method on $this->formBuilder attribute :
  *
  * $this->formBuilder->add("name", "text")
  *   ->add("email", "email", array(
  *           "attr" => array(
  *               "class" => "field"
  *           ),
  *           "label" => "email",
  *           "constraints" => array(
  *               new \Symfony\Component\Validator\Constraints\NotBlank()
  *           )
  *       )
  *   )
  *   ->add('age', 'integer');
  *
  * @return null
  */
 protected function buildForm()
 {
     /**
      * Get information
      */
     if (ShoppingFluxConfigQuery::getDefaultLang() !== null) {
         $langId = ShoppingFluxConfigQuery::getDefaultLang()->getId();
     } else {
         $langId = Lang::getDefaultLanguage()->getId();
     }
     $langsId = LangQuery::create()->select("Id")->find()->toArray();
     $langsId = array_flip($langsId);
     $deliveryModulesId = ModuleQuery::create()->filterByType(AbstractDeliveryModule::DELIVERY_MODULE_TYPE)->filterByActivate(1)->select("Id")->find()->toArray();
     $deliveryModulesId = array_flip($deliveryModulesId);
     $taxesId = TaxQuery::create()->filterByType("Thelia\\TaxEngine\\TaxType\\FixAmountTaxType")->select("Id")->find()->toArray();
     $taxesId = array_flip($taxesId);
     $translator = Translator::getInstance();
     /**
      * Then build the form
      */
     $this->formBuilder->add("token", "text", array("label" => $translator->trans("ShoppingFlux Token", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_token"], "constraints" => [], "required" => true, "data" => ShoppingFluxConfigQuery::getToken()))->add("prod", "checkbox", array("label" => $translator->trans("In production", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_prod"], "required" => false, "data" => ShoppingFluxConfigQuery::getProd()))->add("delivery_module_id", "choice", array("label" => $translator->trans("Delivery module", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_delivery_module_id"], "required" => true, "multiple" => false, "choices" => $deliveryModulesId, "data" => ShoppingFluxConfigQuery::getDeliveryModuleId()))->add("lang_id", "choice", array("label" => $translator->trans("Language", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_lang"], "required" => true, "multiple" => false, "choices" => $langsId, "data" => $langId))->add("ecotax_id", "choice", array("label" => $translator->trans("Ecotax rule", [], ShoppingFlux::MESSAGE_DOMAIN), "label_attr" => ["for" => "shopping_flux_ecotax"], "required" => true, "choices" => $taxesId, "multiple" => false, "data" => ShoppingFluxConfigQuery::getEcotaxRuleId()))->add("action_type", "choice", array("required" => true, "choices" => ["save" => 0, "export" => 1], "multiple" => false));
 }
Exemple #27
0
 /**
  * Get the associated ChildLang object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildLang The associated ChildLang object.
  * @throws PropelException
  */
 public function getLang(ConnectionInterface $con = null)
 {
     if ($this->aLang === null && $this->lang_id !== null) {
         $this->aLang = ChildLangQuery::create()->findPk($this->lang_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->aLang->addOrders($this);
            */
     }
     return $this->aLang;
 }
 /**
  * @param Lang|null $lang
  * @return string
  * @since 2.3
  */
 protected function getBaseUrl(Lang $lang = null)
 {
     $baseUrl = '';
     if ((int) ConfigQuery::read('one_domain_foreach_lang') === 1) {
         if ($lang === null) {
             $lang = LangQuery::create()->findOneByByDefault(true);
         }
         $baseUrl = $lang->getUrl();
     }
     $baseUrl = trim($baseUrl);
     if (empty($baseUrl)) {
         $baseUrl = ConfigQuery::read('url_site');
     }
     if (empty($baseUrl)) {
         $baseUrl = 'http://localhost';
     }
     return $baseUrl;
 }
 public function toggleProductSync($id)
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('GoogleShopping'), AccessManager::UPDATE))) {
         return $response;
     }
     if ($this->getRequest()->query->get('target_country')) {
         $targetCountry = CountryQuery::create()->findOneByIsoalpha2($this->getRequest()->get('target_country'));
     } else {
         $targetCountry = Country::getDefaultCountry();
     }
     if ($this->getRequest()->query->get('locale')) {
         $lang = LangQuery::create()->findOneByLocale($this->getRequest()->query->get('locale'));
     } else {
         $lang = Lang::getDefaultLanguage();
     }
     $product = ProductQuery::create()->findPk($id);
     $googleProductEvent = new GoogleProductEvent($product);
     $googleProductEvent->setTargetCountry($targetCountry)->setLang($lang);
     $this->getDispatcher()->dispatch(GoogleShoppingEvents::GOOGLE_PRODUCT_TOGGLE_SYNC, $googleProductEvent);
 }
Exemple #30
0
 /**
  *
  * in this function you add all the fields you need for your Form.
  * Form this you have to call add method on $this->formBuilder attribute :
  *
  * $this->formBuilder->add("name", "text")
  *   ->add("email", "email", array(
  *           "attr" => array(
  *               "class" => "field"
  *           ),
  *           "label" => "email",
  *           "constraints" => array(
  *               new \Symfony\Component\Validator\Constraints\NotBlank()
  *           )
  *       )
  *   )
  *   ->add('age', 'integer');
  *
  * @return null
  */
 protected function buildForm()
 {
     foreach (LangQuery::create()->find() as $lang) {
         $this->formBuilder->add(self::LANG_PREFIX . $lang->getId(), 'text', array('constraints' => array(new NotBlank()), "attr" => array("tag" => "url", "url_id" => $lang->getId(), "url_title" => $lang->getTitle())));
     }
 }