protected function buildForm() { parent::buildForm(true); $this->formBuilder->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))->add("by_module", "checkbox", array("label" => Translator::getInstance()->trans("By Module"), "required" => false, "label_attr" => array("for" => "by_module", "help" => Translator::getInstance()->trans("This hook is specific to a module (delivery/payment modules)."))))->add("block", "checkbox", array("label" => Translator::getInstance()->trans("Hook block"), "required" => false, "label_attr" => array("for" => "block", "help" => Translator::getInstance()->trans("If checked, this hook will be used by a hook block. If not, by hook function.")))); // Add standard description fields, excluding title and locale, which a re defined in parent class $this->addStandardDescFields(array('title', 'postscriptum', 'locale')); }
public function verifyProfileId($value, ExecutionContextInterface $context) { $profile = ProfileQuery::create()->findPk($value); if (null === $profile) { $context->addViolation(Translator::getInstance()->trans("Profile ID not found")); } }
public function checkDuplicateCode($value, ExecutionContextInterface $context) { $currency = CurrencyQuery::create()->findOneByCode($value); if ($currency) { $context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value])); } }
/** * 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])); } }
public function verifyExistingEmail($value, ExecutionContextInterface $context) { $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value); if ($customer) { $context->addViolation(Translator::getInstance()->trans("You are already registered!")); } }
public function verifyExistingEmail($value, ExecutionContextInterface $context) { $customer = CustomerQuery::create()->findOneByEmail($value); if (null === $customer) { $context->addViolation(Translator::getInstance()->trans("This email does not exists")); } }
protected function buildForm() { parent::buildForm(true); $this->formBuilder->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))->add("by_module", "checkbox", array("label" => Translator::getInstance()->trans("By Module"), "label_attr" => array("for" => "by_module")))->add("block", "checkbox", array("label" => Translator::getInstance()->trans("Hook block"), "label_attr" => array("for" => "block"))); // Add standard description fields, excluding title and locale, which a re defined in parent class $this->addStandardDescFields(array('title', 'postscriptum', 'locale')); }
protected function buildForm() { $this->doBuilForm(Translator::getInstance()->trans('The brand name or title')); $this->formBuilder->add('id', 'hidden', ['constraints' => [new GreaterThan(['value' => 0])], 'required' => true])->add("logo_image_id", "integer", ['constraints' => [], 'required' => false, 'label' => Translator::getInstance()->trans('Select the brand logo'), 'label_attr' => ['for' => 'logo_image_id', 'help' => Translator::getInstance()->trans("Select the brand logo amongst the brand images")]]); // Add standard description fields, excluding title and locale, which are already defined $this->addStandardDescFields(array('title', 'locale')); }
/** * @param int $titleId customer title id (from customer_title table) * @param string $firstname customer first name * @param string $lastname customer last name * @param string $address1 customer address * @param string $address2 customer adress complement 1 * @param string $address3 customer adress complement 2 * @param string $phone customer phone number * @param string $cellphone customer cellphone number * @param string $zipcode customer zipcode * @param string $city * @param int $countryId customer country id (from Country table) * @param string $email customer email, must be unique * @param string $plainPassword customer plain password, hash is made calling setPassword method. Not mandatory parameter but an exception is thrown if customer is new without password * @param string $lang * @param int $reseller * @param null $sponsor * @param int $discount * @param null $company * @param null $ref * @param bool $forceEmailUpdate true if the email address could be updated. * @param int $stateId customer state id (from State table) * @throws \Exception * @throws \Propel\Runtime\Exception\PropelException */ public function createOrUpdate($titleId, $firstname, $lastname, $address1, $address2, $address3, $phone, $cellphone, $zipcode, $city, $countryId, $email = null, $plainPassword = null, $lang = null, $reseller = 0, $sponsor = null, $discount = 0, $company = null, $ref = null, $forceEmailUpdate = false, $stateId = null) { $this->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setEmail($email, $forceEmailUpdate)->setPassword($plainPassword)->setReseller($reseller)->setSponsor($sponsor)->setDiscount($discount)->setRef($ref); if (!is_null($lang)) { $this->setLangId($lang); } $con = Propel::getWriteConnection(CustomerTableMap::DATABASE_NAME); $con->beginTransaction(); try { if ($this->isNew()) { $address = new Address(); $address->setLabel(Translator::getInstance()->trans("Main address"))->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->setIsDefault(1); $this->addAddress($address); if (ConfigQuery::isCustomerEmailConfirmationEnable()) { $this->setConfirmationToken(bin2hex(random_bytes(32))); } } else { $address = $this->getDefaultAddress(); $address->setCompany($company)->setTitleId($titleId)->setFirstname($firstname)->setLastname($lastname)->setAddress1($address1)->setAddress2($address2)->setAddress3($address3)->setPhone($phone)->setCellphone($cellphone)->setZipcode($zipcode)->setCity($city)->setCountryId($countryId)->setStateId($stateId)->save($con); } $this->save($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } }
protected function transQuick($id, $locale, $parameters = []) { if ($this->translator === null) { $this->translator = Translator::getInstance(); } return $this->trans($id, $parameters, DealerTeam::DOMAIN_NAME, $locale); }
public function verifyEmailField($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if (isset($data["email_confirm"]) && $data["email"] != $data["email_confirm"]) { $context->addViolation(Translator::getInstance()->trans("email confirmation is not the same as email field")); } }
public function getPostage(Country $country) { if (!$this->isValidDelivery($country)) { throw new DeliveryException(Translator::getInstance()->trans("This module cannot be used on the current cart.")); } return 0.0; }
/** * Checks if at least one phone number is provided * * @param mixed $value The value that should be validated * @param Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { $data = $this->context->getRoot()->getData(); if (empty($data["phone"]) && empty($data["cellphone"])) { $this->context->addViolationAt("phone", Translator::getInstance()->trans("Please enter at least one phone number.", [], ForcePhone::DOMAIN_NAME)); } }
protected function trans($id, $parameters = [], $locale = null) { if (null === $this->translator) { $this->translator = Translator::getInstance(); } return $this->translator->trans($id, $parameters, self::MESSAGE_DOMAIN, $locale); }
public function verifyTaxList($value, ExecutionContextInterface $context) { $jsonType = new JsonType(); if (!$jsonType->isValid($value)) { $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON")); } $taxList = json_decode($value, true); /* check we have 2 level max */ foreach ($taxList as $taxLevel1) { if (is_array($taxLevel1)) { foreach ($taxLevel1 as $taxLevel2) { if (is_array($taxLevel2)) { $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON")); } else { $taxModel = TaxQuery::create()->findPk($taxLevel2); if (null === $taxModel) { $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON")); } } } } else { $taxModel = TaxQuery::create()->findPk($taxLevel1); if (null === $taxModel) { $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON")); } } } }
/** * @param $areaId * @param $weight * * @return mixed * @throws \Thelia\Exception\OrderException */ public static function getPostageAmount($areaId, $weight) { $freeshipping = ColissimoFreeshippingQuery::create()->getLast(); $postage = 0; if (!$freeshipping) { $prices = self::getPrices(); /* check if Colissimo delivers the asked area */ if (!isset($prices[$areaId]) || !isset($prices[$areaId]["slices"])) { throw new DeliveryException(Translator::getInstance()->trans("Colissimo delivery unavailable for the delivery country", [], self::MESSAGE_DOMAIN)); } $areaPrices = $prices[$areaId]["slices"]; ksort($areaPrices); /* Check cart weight is below the maximum weight */ end($areaPrices); $maxWeight = key($areaPrices); if ($weight > $maxWeight) { throw new DeliveryException(Translator::getInstance()->trans("Colissimo delivery unavailable for this cart weight (%weight kg)", array("%weight" => $weight), self::MESSAGE_DOMAIN)); } $postage = current($areaPrices); while (prev($areaPrices)) { if ($weight > key($areaPrices)) { break; } $postage = current($areaPrices); } } return $postage; }
/** * @inheritdoc */ protected function buildForm() { $translator = Translator::getInstance(); $this->formBuilder->add('file', 'file', ['required' => false, 'constraints' => [new Image([])], 'label' => $translator->trans('Replace current image by this file'), 'label_attr' => ['for' => 'file']])->add('visible', 'checkbox', ['constraints' => [], 'required' => false, 'label' => $translator->trans('This image is online'), 'label_attr' => ['for' => 'visible_create']]); // Add standard description fields $this->addStandardDescFields(); }
public function verifyExistingCode($value, ExecutionContextInterface $context) { $coupon = CouponQuery::create()->findOneByCode($value); if (null === $coupon) { $context->addViolation(Translator::getInstance()->trans("This coupon does not exists")); } }
public function __construct(Request $request, $type = "form", $data = array(), $options = array()) { $this->request = $request; $validator = Validation::createValidatorBuilder(); if (!isset($options["attr"]["name"])) { $options["attr"]["thelia_name"] = $this->getName(); } $builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension()); if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) { $builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))))); } $translator = Translator::getInstance(); $validator->setTranslationDomain('validators')->setTranslator($translator); $this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options)); $this->buildForm(); // If not already set, define the success_url field // This field is not included in the standard form hidden fields // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('success_url')) { $this->formBuilder->add("success_url", "hidden"); } // The "error_message" field defines the error message displayed if // the form could not be validated. If it is empty, a standard error message is displayed instead. // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('error_message')) { $this->formBuilder->add("error_message", "hidden"); } $this->form = $this->formBuilder->getForm(); }
public function checkDuplicateRef($value, ExecutionContextInterface $context) { $count = ProductQuery::create()->filterByRef($value)->count(); if ($count > 0) { $context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value))); } }
public function verifyCountry($value, ExecutionContextInterface $context) { $address = CountryQuery::create()->findPk($value); if (null === $address) { $context->addViolation(Translator::getInstance()->trans("Country ID not found")); } }
public function verifyPasswordField($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if ($data["password"] != $data["password_confirm"]) { $context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field")); } }
/** * Process url generator function * * @param array $params * @param \Smarty $smarty * @return string no text is returned. */ public function generateUrlFunction($params, &$smarty) { // the path to process $current = $this->getParam($params, 'current', false); $path = $this->getParam($params, 'path', null); $file = $this->getParam($params, 'file', null); // Do not invoke index.php in URL (get a static file in web space if ($current) { $path = $this->request->getPathInfo(); unset($params["current"]); // Delete the current param, so it isn't included in the url // Then build the query variables $params = array_merge($this->request->query->all(), $params); } if ($file !== null) { $path = $file; $mode = URL::PATH_TO_FILE; } elseif ($path !== null) { $mode = URL::WITH_INDEX_PAGE; } else { throw new \InvalidArgumentException(Translator::getInstance()->trans("Please specify either 'path' or 'file' parameter in {url} function.")); } $excludeParams = $this->resolvePath($params, $path, $smarty); $url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array_merge(['noamp', 'path', 'file', 'target'], $excludeParams)), $mode); $this->applyNoAmpAndTarget($params, $url); return $url; }
public function checkAtLeastOnePhoneNumberIsDefined($value, ExecutionContextInterface $context) { $data = $context->getRoot()->getData(); if (empty($data["phone"]) && empty($data["cellphone"])) { $context->addViolationAt("phone", Translator::getInstance()->trans("Please enter a home or mobile phone number")); } }
public function verifyExistingEmail($value, ExecutionContextInterface $context) { $customer = CustomerQuery::getCustomerByEmail($value); if ($customer) { $context->addViolation(Translator::getInstance()->trans("This email already exists.")); } }
public function checkCityName($value, ExecutionContextInterface $context) { $isValid = InseeGeoMunicipalityQuery::create()->findOneById($value); if (!isset($isValid)) { $context->addViolation(Translator::getInstance()->trans('city.error', [], INSEEGeo::DOMAIN_NAME)); } }
protected function trans($id, $parameters = []) { if (null === $this->translator) { $this->translator = Translator::getInstance(); } return $this->translator->trans($id, $parameters); }
/** * @inherited */ protected function buildForm() { $translator = Translator::getInstance(); BaseProductCreationForm::buildForm(); $this->formBuilder->add("brand_id", "integer", ['required' => true, 'label' => $translator->trans('Brand / Supplier'), 'label_attr' => ['for' => 'mode', 'help' => $translator->trans("Select the product brand, or supplier.")]]); $this->addStandardDescFields(array('title', 'locale')); }
public function checkDuplicateName($value, ExecutionContextInterface $context) { $config = ConfigQuery::create()->findOneByName($value); if ($config) { $context->addViolation(Translator::getInstance()->trans('A variable with name "%name" already exists.', array('%name' => $value))); } }
public function importData(array $data) { $pse = ProductSaleElementsQuery::create()->findPk($data['id']); if ($pse === null) { return Translator::getInstance()->trans('The product sale element id %id doesn\'t exist', ['%id' => $data['id']]); } else { $currency = null; if (isset($data['currency'])) { $currency = CurrencyQuery::create()->findOneByCode($data['currency']); } if ($currency === null) { $currency = Currency::getDefaultCurrency(); } $price = ProductPriceQuery::create()->filterByProductSaleElementsId($pse->getId())->findOneByCurrencyId($currency->getId()); if ($price === null) { $price = new ProductPrice(); $price->setProductSaleElements($pse)->setCurrency($currency); } $price->setPrice($data['price']); if (isset($data['promo_price'])) { $price->setPromoPrice($data['promo_price']); } if (isset($data['promo'])) { $price->getProductSaleElements()->setPromo((int) $data['promo'])->save(); } $price->save(); $this->importedRows++; } return null; }