/**
  * Add fields for attribute values selection in our own way (since the product on has its default PSE, it has
  * no attributes as far as Thelia is concerned, but we want it to have all of its template's attributes).
  *
  * @param TheliaFormEvent $event
  */
 public function cartFormAfterBuild(TheliaFormEvent $event)
 {
     $sessionLocale = null;
     $session = $this->request->getSession();
     if ($session !== null) {
         $sessionLang = $session->getLang();
         if ($sessionLang !== null) {
             $sessionLocale = $sessionLang->getLocale();
         }
     }
     $product = ProductQuery::create()->findPk($this->request->getProductId());
     if ($product === null || $product->getTemplate() === null) {
         return;
     }
     $productAttributes = AttributeQuery::create()->filterByTemplate($product->getTemplate())->find();
     /** @var Attribute $productAttribute */
     foreach ($productAttributes as $productAttribute) {
         $attributeValues = AttributeAvQuery::create()->findByAttributeId($productAttribute->getId());
         $choices = [];
         /** @var AttributeAv $attributeValue */
         foreach ($attributeValues as $attributeValue) {
             if ($sessionLocale !== null) {
                 $attributeValue->setLocale($sessionLocale);
             }
             $choices[$attributeValue->getId()] = $attributeValue->getTitle();
         }
         $event->getForm()->getFormBuilder()->add(static::LEGACY_PRODUCT_ATTRIBUTE_FIELD_PREFIX . $productAttribute->getId(), 'choice', ['choices' => $choices, 'required' => true]);
     }
 }
 /**
  * Add birth date input in forms
  * @param TheliaFormEvent $event
  */
 public function birthDateInput(TheliaFormEvent $event)
 {
     if ($this->request->fromApi() === false) {
         $data = $event->getForm()->getFormBuilder()->getData();
         $customerBirthDate = null;
         if (!empty($data['id'])) {
             $customerBirthDate = CustomerBirthDateQuery::create()->findOneById($data['id']);
         }
         $event->getForm()->getFormBuilder()->add('birth_date', 'birthday', ['label' => 'Birth date', 'required' => true, 'widget' => 'choice', 'format' => 'yyyy-MM-dd', 'years' => range(date('Y') - 90, date('Y')), 'input' => 'string', 'data' => $customerBirthDate !== null ? $customerBirthDate->getBirthDate('Y-m-d') : '']);
     }
 }
 public function forcePhoneInput(TheliaFormEvent $event)
 {
     if ($this->request->fromApi() === false) {
         if (ForcePhone::getConfigValue('force_one', false)) {
             $constraints = [new AtLeastOnePhone()];
         } else {
             $constraints = [];
         }
         $forcePhone = ForcePhone::getConfigValue('force_phone', false);
         if (!empty($constraints) || $forcePhone) {
             $event->getForm()->getFormBuilder()->remove('phone')->add("phone", "text", ["constraints" => $forcePhone ? [new NotBlank()] : $constraints, "label" => Translator::getInstance()->trans("Phone"), "label_attr" => ["for" => "phone"], "required" => $forcePhone]);
         }
         $forceCellPhone = ForcePhone::getConfigValue('force_cellphone', false);
         if (!empty($constraints) || $forceCellPhone) {
             $event->getForm()->getFormBuilder()->remove('cellphone')->add("cellphone", "text", ["constraints" => $forceCellPhone ? [new NotBlank()] : $constraints, "label" => Translator::getInstance()->trans("Cellphone"), "label_attr" => ["for" => "cellphone"], "required" => $forceCellPhone]);
         }
     }
 }
 /**
  * Add stripe_token & stripe_amount inputs to invoice form
  * @param TheliaFormEvent $event
  */
 public function addStripeInput(TheliaFormEvent $event)
 {
     $event->getForm()->getFormBuilder()->add('stripe_token', 'text', ["required" => true])->add('stripe_amount', 'integer', ["required" => true]);
 }
 /**
  * Callback used to add some fields to the Thelia's CustomerCreateForm.
  * It add two fields : one for the SIRET number and one for VAT.
  * @param TheliaFormEvent $event
  */
 public function addCustomerFamilyFieldsForUpdate(TheliaFormEvent $event)
 {
     // Adding new fields
     $customer = $this->request->getSession()->getCustomerUser();
     if (is_null($customer)) {
         // No customer => no account update => stop here
         return;
     }
     $customerCustomerFamily = CustomerCustomerFamilyQuery::create()->findOneByCustomerId($customer->getId());
     $cfData = array(self::CUSTOMER_FAMILY_CODE_FIELD_NAME => (is_null($customerCustomerFamily) or is_null($customerCustomerFamily->getCustomerFamily())) ? '' : $customerCustomerFamily->getCustomerFamily()->getCode(), self::CUSTOMER_FAMILY_SIRET_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getSiret(), self::CUSTOMER_FAMILY_VAT_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getVat());
     // Retrieving CustomerFamily choices
     $customerFamilyChoices = array();
     /** @var \CustomerFamily\Model\CustomerFamily $customerFamilyChoice */
     foreach (CustomerFamilyQuery::create()->find() as $customerFamilyChoice) {
         $customerFamilyChoices[$customerFamilyChoice->getCode()] = self::trans($customerFamilyChoice->getTitle());
     }
     // Building additional fields
     $event->getForm()->getFormBuilder()->add(self::CUSTOMER_FAMILY_CODE_FIELD_NAME, 'choice', array('constraints' => array(new Constraints\Callback(array('methods' => array(array($this, 'checkCustomerFamily')))), new Constraints\NotBlank()), 'choices' => $customerFamilyChoices, 'empty_data' => false, 'required' => false, 'label' => self::trans('Customer family'), 'label_attr' => array('for' => 'customer_family_id'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_CODE_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_SIRET_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Siret number'), 'label_attr' => array('for' => 'siret'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_SIRET_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_VAT_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Vat'), 'label_attr' => array('for' => 'vat'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_VAT_FIELD_NAME]));
 }