/**
  * after save.
  */
 public function afterSave()
 {
     if ($storeViewId = $this->getStoreViewId()) {
         $storeAttributes = $this->getStoreAttributes();
         foreach ($storeAttributes as $attribute) {
             $attributeValue = $this->_valueFactory->create()->loadAttributeValue($this->getId(), $storeViewId, $attribute);
             if ($this->getData($attribute . '_in_store')) {
                 try {
                     if ($attribute == 'image' && $this->getData('delete_image')) {
                         $attributeValue->delete();
                     } else {
                         $attributeValue->setValue($this->getData($attribute . '_value'))->save();
                     }
                 } catch (\Exception $e) {
                     $this->_monolog->addError($e->getMessage());
                 }
             } elseif ($attributeValue && $attributeValue->getId()) {
                 try {
                     $attributeValue->delete();
                 } catch (\Exception $e) {
                     $this->_monolog->addError($e->getMessage());
                 }
             }
         }
     }
     return parent::afterSave();
 }
Example #2
0
 /**
  * @{inheritDoc}
  *
  * @param  integer $level   The logging level
  * @param  string  $message The log message
  * @param  array   $context The log context
  * @return Boolean Whether the record has been processed
  */
 public function addRecord($level, $message, array $context = [])
 {
     if ($level <= $this->minimumErrorLevel) {
         $this->messages[] = ['level' => $this->getLevelName($level), 'message' => $message];
     }
     return parent::addRecord($level, $message, $context);
 }