コード例 #1
0
 /**
  * Validate value
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * if there is no field value, search value is empty or regular expression is not valid
  */
 public function beforeSave()
 {
     $design = clone $this->_design;
     // For value validations
     $exceptions = $this->getValue();
     foreach ($exceptions as $rowKey => $row) {
         if ($rowKey === '__empty') {
             continue;
         }
         // Validate that all values have come
         foreach (['search', 'value'] as $fieldName) {
             if (!isset($row[$fieldName])) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('Exception does not contain field \'%1\'', $fieldName));
             }
         }
         // Empty string (match all) is not supported, because it means setting a default theme. Remove such entries.
         if (!strlen($row['search'])) {
             unset($exceptions[$rowKey]);
             continue;
         }
         // Validate the theme value
         $design->setDesignTheme($row['value'], \Magento\Framework\App\Area::AREA_FRONTEND);
         // Compose regular exception pattern
         $exceptions[$rowKey]['regexp'] = $this->_composeRegexp($row['search']);
     }
     $this->setValue($exceptions);
     return parent::beforeSave();
 }
コード例 #2
0
 /**
  * Validates attribute mapping entries
  * @return $this
  * @throws \Exception
  */
 public function save()
 {
     $mappingValues = (array) $this->getValue();
     //get the value from our config
     $attributeCodes = [];
     if ($this->_config->getValue('carriers/mercadoenvios/active')) {
         foreach ($mappingValues as $value) {
             if (in_array($value['attribute_code'], $attributeCodes)) {
                 throw new \Exception(__('Cannot repeat Magento Product size attributes'));
             }
             $attributeCodes[] = $value['attribute_code'];
         }
     }
     return parent::save();
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function beforeSave()
 {
     $expressions = $this->getValue();
     foreach ($expressions as $rowKey => $row) {
         if ($rowKey === '__empty') {
             continue;
         }
         foreach (['match_expr', 'replace_expr'] as $fieldName) {
             if (!isset($row[$fieldName])) {
                 throw new \Exception(__('Expression does not contain field \'%1\'', $fieldName));
             }
         }
         $expressions[$rowKey]['match_expr'] = $this->composeRegexp($row['match_expr']);
         $expressions[$rowKey]['replace_expr'] = $this->composeRegexp($row['replace_expr']);
     }
     $this->setValue($expressions);
     return parent::beforeSave();
 }
コード例 #4
0
ファイル: Exceptions.php プロジェクト: Doability/magento2dev
 /**
  * @inheritDoc
  */
 public function afterLoad()
 {
     parent::afterLoad();
     $values = $this->getValue();
     foreach ($values as &$value) {
         if (isset($value['record_id'])) {
             unset($value['record_id']);
         }
     }
     $this->setValue($values);
     return $this;
 }