Exemplo n.º 1
0
 public function testSetEventName()
 {
     $name = 'eventName';
     $this->observer->setEventName($name);
     $result = $this->observer->getData('event_name');
     $this->assertEquals($result, $this->observer->getEventName($name));
 }
Exemplo n.º 2
0
 /**
  * Register an observer
  *
  * If observer has event_name property it will be registered for this specific event.
  * If not it will be registered as global observer
  *
  * @param Observer $observer
  * @return $this
  */
 public function addObserver(Observer $observer)
 {
     $eventName = $observer->getEventName();
     if ($eventName) {
         $this->getEventByName($eventName)->addObserver($observer);
     } else {
         $this->getGlobalObservers()->addObserver($observer);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Update all attribute-dependant index
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return \Magento\CatalogSearch\Model\Fulltext\Observer
  */
 public function eavAttributeChange(\Magento\Framework\Event\Observer $observer)
 {
     $attribute = $observer->getEvent()->getAttribute();
     /* @var $attribute \Magento\Eav\Model\Entity\Attribute */
     $entityType = $this->_eavConfig->getEntityType(\Magento\Catalog\Model\Product::ENTITY);
     /* @var $entityType \Magento\Eav\Model\Entity\Type */
     if ($attribute->getEntityTypeId() != $entityType->getId()) {
         return $this;
     }
     $delete = $observer->getEventName() == 'eav_entity_attribute_delete_after';
     if (!$delete && !$attribute->dataHasChangedFor('is_searchable')) {
         return $this;
     }
     $showNotice = false;
     if ($delete) {
         if ($attribute->getIsSearchable()) {
             $showNotice = true;
         }
     } elseif ($attribute->dataHasChangedFor('is_searchable')) {
         $showNotice = true;
     }
     if ($showNotice) {
         $url = $this->_backendUrl->getUrl('adminhtml/system_cache');
         $this->messageManager->addNotice(__('Attribute setting change related with Search Index. Please run <a href="%1">Rebuild Search Index</a> process.', $url));
     }
     return $this;
 }