/**
  * 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]);
     }
 }