/** * Order files by group to make reading easier * * @return $this */ protected function _beforeSave() { $values = $this->getValue(); if ($values && is_array($values) && count($values) > 0) { $sorted = array(); foreach ($values as $id => $value) { if (!is_array($value)) { continue; } foreach ($value as $k => $v) { $value[$k] = trim($v); } if (empty($value['group']) || empty($value['file']) || empty($value['type'])) { continue; } $group = $value['group']; if (!isset($sorted[$group])) { $sorted[$group] = array(); } $sorted[$group][$id] = $value; } } ksort($sorted); $final = array(); foreach ($sorted as $group => $files) { $final += $files; } $this->setValue($final); return parent::_beforeSave(); }
/** * Validate value * * @throws Mage_Core_Exception if there is no field value, search value is empty or regular expression is not valid */ protected function _beforeSave() { $design = clone Mage::getDesign(); // For value validations $exceptions = $this->getValue(); foreach ($exceptions as $rowKey => $row) { if ($rowKey === '__empty') { continue; } // Validate that all values have come foreach (array('search', 'value') as $fieldName) { if (!isset($row[$fieldName])) { Mage::throwException(Mage::helper('Mage_Core_Helper_Data')->__("Exception does not contain field '{$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'], Mage_Core_Model_App_Area::AREA_FRONTEND); // Compose regular exception pattern $exceptions[$rowKey]['regexp'] = $this->_composeRegexp($row['search']); } $this->setValue($exceptions); return parent::_beforeSave(); }
protected function _afterLoad() { parent::_afterLoad(); if ($this->getValue() === false) { $this->setDefaultMapProductColumns(); } }
/** * Prepare data before save */ protected function _beforeSave() { $value = $this->getValue(); if (is_array($value)) { unset($value['__empty']); $foundGroups = array(); $hasGroupAllOnly = false; $groupAllQty = null; foreach ($value as $k => $v) { if (in_array($v['customer_group_id'], $foundGroups)) { unset($value[$k]); continue; } $foundGroups[] = $v['customer_group_id']; if ($v['customer_group_id'] == Mage_Customer_Model_Group::CUST_GROUP_ALL) { $hasGroupAllOnly = true; $groupAllQty = $v['min_sale_qty']; } else { $hasGroupAllOnly = false; } } if ($hasGroupAllOnly) { $this->setValue($groupAllQty); } else { parent::_beforeSave(); } } }
protected function _beforeSave() { parent::_beforeSave(); if (is_array($this->getValue())) { $this->setValue(serialize($this->getValue())); } }
/** * additional validation for unique brands * * @override * @throws Mage_Core_Exception if the brands are not unique -> validation failed * @return Netresearch_Ops_Model_System_Config_Backend_Intersolve_Brands */ public function save() { $brands = $this->getValue(); if (is_array($brands) && sizeof($brands) > 1) { $alreadyProcessedBrands = array(); foreach ($brands as $brand) { if (is_array($brand) && array_key_exists('brand', $brand)) { if (in_array($brand['brand'], $alreadyProcessedBrands)) { Mage::throwException("Brands must be unique"); } $alreadyProcessedBrands[] = $brand['brand']; } } } return parent::save(); }
protected function _beforeSave() { $value = $this->getValue(); if (is_array($value)) { unset($value['__empty']); if (count($value)) { $value = DeliveryDateOrderBy($value, 'sort'); $keys = array(); for ($i = 0; $i < count($value); $i++) { $keys[] = 'nonworking_' . uniqid(); } $value = array_combine($keys, array_values($value)); } } $this->setValue($value); parent::_beforeSave(); }
protected function _beforeSave() { // Remove empty value if (is_array($value = $this->getValue())) { unset($value['__empty']); } else { $value = array(); } // Prepare resulting value $result = array(); foreach ($value as $key => $variable) { // Only save if all values are set if (isset($variable['code']) && trim($variable['code']) !== '' && !isset($result[$variable['code']]) && isset($variable['value']) && trim($variable['value']) !== '') { $result[$variable['code']] = $variable; } } $this->setValue($result); return parent::_beforeSave(); }
protected function _beforeSave() { $value = $this->getValue(); $allowedIsoCodes = Mage::getModel('dhlonlineretoure/config')->getAllowedCountryCodes(); $configuredIsoCodes = array(); if (is_array($value)) { foreach ($value as $key => $data) { if ($key === '__empty') { continue; } if (!in_array($data['iso'], $allowedIsoCodes)) { Mage::throwException(Mage::helper('dhlonlineretoure/data')->__('Selected country "%s" is not applicable for online return.', $data['iso'])); } if (in_array($data['iso'], $configuredIsoCodes)) { Mage::throwException(Mage::helper('dhlonlineretoure/data')->__('Country in area Online Return must not be defined twice.')); } $configuredIsoCodes[] = $data['iso']; } } parent::_beforeSave(); }