Пример #1
0
 protected function getUpdateEvent($formData)
 {
     $changeEvent = new AttributeUpdateEvent($formData['id']);
     // Create and dispatch the change event
     $changeEvent->setLocale($formData["locale"])->setTitle($formData['title'])->setChapo($formData['chapo'])->setDescription($formData['description'])->setPostscriptum($formData['postscriptum']);
     return $changeEvent;
 }
Пример #2
0
 /**
  * Change a product attribute
  *
  * @param AttributeUpdateEvent $event
  */
 public function update(AttributeUpdateEvent $event)
 {
     if (null !== ($attribute = AttributeQuery::create()->findPk($event->getAttributeId()))) {
         $attribute->setDispatcher($event->getDispatcher())->setLocale($event->getLocale())->setTitle($event->getTitle())->setDescription($event->getDescription())->setChapo($event->getChapo())->setPostscriptum($event->getPostscriptum())->save();
         $event->setAttribute($attribute);
     }
 }
Пример #3
0
 /**
  * @param AttributeModel $attribute
  * @depends testCreateSimple
  */
 public function testUpdate(AttributeModel $attribute)
 {
     $event = new AttributeUpdateEvent($attribute->getId());
     $event->setLocale($attribute->getLocale())->setTitle('bar')->setDescription('bar description')->setChapo('bar chapo')->setPostscriptum('bar postscriptum')->setDispatcher($this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"));
     $action = new Attribute();
     $action->update($event);
     $updatedAttribute = $event->getAttribute();
     $this->assertInstanceOf('Thelia\\Model\\Attribute', $updatedAttribute);
     $this->assertEquals('en_US', $updatedAttribute->getLocale());
     $this->assertEquals('bar', $updatedAttribute->getTitle());
     $this->assertEquals('bar description', $updatedAttribute->getDescription());
     $this->assertEquals('bar chapo', $updatedAttribute->getChapo());
     $this->assertEquals('bar postscriptum', $updatedAttribute->getPostscriptum());
     return $updatedAttribute;
 }
Пример #4
0
 public function importAttributes()
 {
     $count = $errors = 0;
     $hdl = $this->t1db->query("select * from declinaison order by classement");
     while ($hdl && ($declinaison = $this->t1db->fetch_object($hdl))) {
         $descs = $this->t1db->query_list("select * from declinaisondesc where declinaison = ? order by lang asc", array($declinaison->id));
         $idx = 0;
         $event = new AttributeCreateEvent();
         foreach ($descs as $desc) {
             try {
                 $lang = $this->getT2Lang($desc->lang);
                 if ($idx == 0) {
                     $event->setLocale($lang->getLocale())->setTitle($desc->titre);
                     $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_CREATE, $event);
                     // Updater position
                     $update_position_event = new UpdatePositionEvent($event->getAttribute()->getId(), UpdatePositionEvent::POSITION_ABSOLUTE, $declinaison->classement);
                     $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_UPDATE_POSITION, $update_position_event);
                     Tlog::getInstance()->info("Created attribute " . $event->getAttribute()->getId() . " from {$desc->titre} ({$declinaison->id})");
                     $this->attr_corresp->addEntry($declinaison->id, $event->getAttribute()->getId());
                 }
                 $update_event = new AttributeUpdateEvent($event->getAttribute()->getId());
                 $update_event->setLocale($lang->getLocale())->setTitle($desc->titre)->setChapo($desc->chapo)->setDescription($desc->description)->setPostscriptum('');
                 $this->dispatcher->dispatch(TheliaEvents::ATTRIBUTE_UPDATE, $update_event);
                 $idx++;
             } catch (\Exception $ex) {
                 Tlog::getInstance()->addError("Failed to create Attribute from {$desc->titre} ({$declinaison->id}): ", $ex->getMessage());
                 $errors++;
             }
             $count++;
         }
     }
     return new ImportChunkResult($count, $errors);
 }