示例#1
0
 public function testCreate()
 {
     $feature = $this->getRandomFeature();
     $event = new FeatureAvCreateEvent();
     $event->setFeatureId($feature->getId())->setLocale('en_US')->setTitle('test')->setDispatcher($this->dispatcher);
     $action = new FeatureAv();
     $action->create($event);
     $createdFeatureAv = $event->getFeatureAv();
     $this->assertInstanceOf('Thelia\\Model\\FeatureAv', $createdFeatureAv);
     $this->assertFalse($createdFeatureAv->isNew());
     $this->assertEquals('en_US', $createdFeatureAv->getLocale());
     $this->assertEquals('test', $createdFeatureAv->getTitle());
     $this->assertEquals($feature->getId(), $createdFeatureAv->getFeatureId());
     return $createdFeatureAv;
 }
示例#2
0
 /**
  * Create a new feature entry
  *
  * @param FeatureAvCreateEvent $event
  * @param $eventName
  * @param EventDispatcherInterface $dispatcher
  */
 public function create(FeatureAvCreateEvent $event, $eventName, EventDispatcherInterface $dispatcher)
 {
     $feature = new FeatureAvModel();
     $feature->setDispatcher($dispatcher)->setFeatureId($event->getFeatureId())->setLocale($event->getLocale())->setTitle($event->getTitle())->save();
     $event->setFeatureAv($feature);
 }
 protected function getCreationEvent($formData)
 {
     $createEvent = new FeatureAvCreateEvent();
     $createEvent->setFeatureId($formData['feature_id'])->setTitle($formData['title'])->setLocale($formData["locale"]);
     return $createEvent;
 }
示例#4
0
 /**
  * Create a new feature entry
  *
  * @param FeatureAvCreateEvent $event
  */
 public function create(FeatureAvCreateEvent $event)
 {
     $feature = new FeatureAvModel();
     $feature->setDispatcher($event->getDispatcher())->setFeatureId($event->getFeatureId())->setLocale($event->getLocale())->setTitle($event->getTitle())->save();
     $event->setFeatureAv($feature);
 }
示例#5
0
 /**
  * Update the value of a product feature.
  *
  * @param FeatureProductUpdateEvent $event
  */
 public function updateFeatureProductValue(FeatureProductUpdateEvent $event)
 {
     // Prepare the FeatureAv's ID
     $featureAvId = $event->getFeatureValue();
     // Search for existing FeatureProduct
     $featureProductQuery = FeatureProductQuery::create()->filterByProductId($event->getProductId())->filterByFeatureId($event->getFeatureId());
     // If it's not a free text value, we can filter by the event's featureValue (which is an ID)
     if ($event->getFeatureValue() !== null && $event->getIsTextValue() === false) {
         $featureProductQuery->filterByFeatureAvId($featureAvId);
     }
     $featureProduct = $featureProductQuery->findOne();
     // If the FeatureProduct does not exist, create it
     if ($featureProduct === null) {
         $featureProduct = new FeatureProduct();
         $featureProduct->setDispatcher($event->getDispatcher())->setProductId($event->getProductId())->setFeatureId($event->getFeatureId());
         // If it's a free text value, create a FeatureAv to handle i18n
         if ($event->getIsTextValue() === true) {
             $featureProduct->setFreeTextValue(true);
             $createFeatureAvEvent = new FeatureAvCreateEvent();
             $createFeatureAvEvent->setFeatureId($event->getFeatureId())->setLocale($event->getLocale())->setTitle($event->getFeatureValue());
             $event->getDispatcher()->dispatch(TheliaEvents::FEATURE_AV_CREATE, $createFeatureAvEvent);
             $featureAvId = $createFeatureAvEvent->getFeatureAv()->getId();
         }
     } elseif ($featureProduct !== null && $event->getIsTextValue() === true) {
         // Get the FeatureAv
         $freeTextFeatureAv = FeatureAvQuery::create()->filterByFeatureProduct($featureProduct)->findOneByFeatureId($event->getFeatureId());
         // Get the FeatureAvI18n by locale
         $freeTextFeatureAvI18n = FeatureAvI18nQuery::create()->filterById($freeTextFeatureAv->getId())->findOneByLocale($event->getLocale());
         // Nothing found for this lang and the new value is not empty : create FeatureAvI18n
         if ($freeTextFeatureAvI18n === null && !empty($featureAvId)) {
             $featureAvI18n = new FeatureAvI18n();
             $featureAvI18n->setId($freeTextFeatureAv->getId())->setLocale($event->getLocale())->setTitle($event->getFeatureValue())->save();
             $featureAvId = $featureAvI18n->getId();
         } elseif ($freeTextFeatureAvI18n !== null && empty($featureAvId)) {
             $freeTextFeatureAvI18n->delete();
             // Check if there are still some FeatureAvI18n for this FeatureAv
             $freeTextFeatureAvI18ns = FeatureAvI18nQuery::create()->findById($freeTextFeatureAv->getId());
             // If there are no more FeatureAvI18ns for this FeatureAv, remove the corresponding FeatureProduct & FeatureAv
             if (count($freeTextFeatureAvI18ns) == 0) {
                 $deleteFeatureProductEvent = new FeatureProductDeleteEvent($event->getProductId(), $event->getFeatureId());
                 $event->getDispatcher()->dispatch(TheliaEvents::PRODUCT_FEATURE_DELETE_VALUE, $deleteFeatureProductEvent);
                 $deleteFeatureAvEvent = new FeatureAvDeleteEvent($freeTextFeatureAv->getId());
                 $event->getDispatcher()->dispatch(TheliaEvents::FEATURE_AV_DELETE, $deleteFeatureAvEvent);
                 return;
             }
         } elseif ($freeTextFeatureAvI18n !== null && !empty($featureAvId)) {
             $freeTextFeatureAvI18n->setTitle($featureAvId);
             $freeTextFeatureAvI18n->save();
             $featureAvId = $freeTextFeatureAvI18n->getId();
         }
     } else {
         $featureAvId = $event->getFeatureValue();
     }
     $featureProduct->setFeatureAvId($featureAvId);
     $featureProduct->save();
     $event->setFeatureProduct($featureProduct);
 }
示例#6
0
 public function importFeaturesAv()
 {
     $count = $errors = 0;
     $hdl = $this->t1db->query("select * from caracdisp");
     while ($hdl && ($caracdisp = $this->t1db->fetch_object($hdl))) {
         $descs = $this->t1db->query_list("select * from caracdispdesc where caracdisp = ? order by lang asc", array($caracdisp->id));
         $idx = 0;
         $event = new FeatureAvCreateEvent();
         foreach ($descs as $desc) {
             try {
                 $lang = $this->getT2Lang($desc->lang);
                 $feature_id = $this->feat_corresp->getT2($caracdisp->caracteristique);
                 if ($idx == 0) {
                     $event->setFeatureId($feature_id)->setLocale($lang->getLocale())->setTitle($desc->titre);
                     $this->dispatcher->dispatch(TheliaEvents::FEATURE_AV_CREATE, $event);
                     // Updater position
                     $update_position_event = new UpdatePositionEvent($event->getFeatureAv()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $desc->classement);
                     $this->dispatcher->dispatch(TheliaEvents::FEATURE_AV_UPDATE_POSITION, $update_position_event);
                     $this->feat_av_corresp->addEntry($caracdisp->id, $event->getFeatureAv()->getId());
                 }
                 $update_event = new FeatureAvUpdateEvent($event->getFeatureAv()->getId());
                 $update_event->setFeatureId($feature_id)->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo('')->setDescription('')->setPostscriptum('');
                 $this->dispatcher->dispatch(TheliaEvents::FEATURE_AV_UPDATE, $update_event);
                 $idx++;
             } catch (\Exception $ex) {
                 Tlog::getInstance()->addError("Failed to import Feature Av: ", $ex->getMessage());
                 $errors++;
             }
             $count++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }