/** * @return Bronto_Common_Model_System_Config_Backend_Token */ protected function _beforeSave() { $commonHelper = Mage::helper('bronto_common'); $value = $this->getValue(); if (!empty($value)) { if ($commonHelper->validApiToken($value) === false) { // reset the verified status Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '2', $this->getScope(), $this->getScopeId()); Mage::throwException($commonHelper->__('The Bronto API Token you have entered appears to be invalid.')); } // reset the verified status Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '1', $this->getScope(), $this->getScopeId()); // Enable Common Module Mage::getModel('core/config_data')->load(Bronto_Common_Helper_Data::XML_PATH_ENABLED, 'path')->setValue(1)->setPath(Bronto_Common_Helper_Data::XML_PATH_ENABLED)->setScope($this->getScope())->setScopeId($this->getScopeId())->save(); // API key is new and doesn't match existing API key $currentApiKey = $commonHelper->getApiToken(); if (!empty($currentApiKey) && $currentApiKey !== $value) { Mage::getSingleton('adminhtml/session')->addNotice($commonHelper->__('You have changed your Bronto API Token so all Bronto modules have been disabled for this configuration scope.' . '<br />Please proceed to each module and reconfigure all available options to avoid undesired behavior.')); $this->_disableAndUnlink(); } } else { Mage::getSingleton('adminhtml/session')->addNotice($commonHelper->__('You have removed your Bronto API Token so all Bronto modules have been disabled for this configuration scope.')); // reset the verified status Mage::helper('bronto_verify/apitoken')->setStatus(Mage::helper('bronto_verify/apitoken')->getPath('token_status'), '0', $this->getScope(), $this->getScopeId()); $this->_disableAndUnlink(true); } return parent::_beforeSave(); }
/** * Clean the project code of unicode characters. * * @return Mage_Core_Model_Abstract|void */ protected function _beforeSave() { $script = $this->getValue(); $script = preg_replace('/[^(\\x20-\\x7F)]*/', '', $script); $this->setValue($script); return parent::_beforeSave(); }
protected function _beforeSave() { $value = $this->getValue(); Mage::helper('udtiership')->saveV2SimpleCondRates($value); $this->setValue(''); return parent::_beforeSave(); }
/** * Update history expiration date to simplify frontend calculations * * @return Enterprise_Reward_Model_System_Config_Backend_Expiration */ protected function _beforeSave() { parent::_beforeSave(); if (!$this->isValueChanged()) { return $this; } $websiteIds = array(); if ($this->getWebsiteCode()) { $websiteIds = array(Mage::app()->getWebsite($this->getWebsiteCode())->getId()); } else { $collection = Mage::getResourceModel('core/config_data_collection')->addFieldToFilter('path', self::XML_PATH_EXPIRATION_DAYS)->addFieldToFilter('scope', 'websites'); $websiteScopeIds = array(); foreach ($collection as $item) { $websiteScopeIds[] = $item->getScopeId(); } foreach (Mage::app()->getWebsites() as $website) { /* @var $website Mage_Core_Model_Website */ if (!in_array($website->getId(), $websiteScopeIds)) { $websiteIds[] = $website->getId(); } } } if (count($websiteIds) > 0) { Mage::getResourceModel('enterprise_reward/reward_history')->updateExpirationDate($this->getValue(), $websiteIds); } return $this; }
/** * Checks to see if we have a new and valid Site Id Checksum Entered * @return self */ protected function _beforeSave() { $helper = Mage::helper('eems_display'); // We need this helper several times herein $newChecksum = $this->getValue(); list($oldHash, $oldSiteId) = $helper->splitSiteIdChecksumField($this->getOldValue()); if (empty($newChecksum) && empty($oldHash)) { // If both old and new checksums are still empty, prompt with some help info. $this->_dataSaveAllowed = false; Mage::getSingleton(self::SESSION_KEY)->addWarning('Please note that tracking is not enabled. Site Id Checksum is empty. ' . self::CONTACT_INFO); return $this; } $storeId = $helper->getStoreIdForCurrentAdminScope(); $formFields = $this->getFieldsetData(); $newSiteId = $formFields['site_id']; // Not allowed to change the Checksum unless we previously had a hash and we are changing the Site Id if (!empty($oldHash) && $oldSiteId === $newSiteId) { $this->_dataSaveAllowed = false; return $this; } // Check that the value provided in newCheckSum matches what we calculate for ourHash. $url = parse_url($helper->getProductFeedUrl($storeId), PHP_URL_HOST); $ourHash = md5($newSiteId . $url); if ($ourHash === $newChecksum) { // Upon success, we save the hash and the newSiteId. In the frontend at runtime, // we just have make sure that the siteId matches the runtime siteId $this->setValue($newChecksum . self::FIELD_SEP . $newSiteId); parent::_beforeSave(); } else { $this->setValue(self::FIELD_SEP); Mage::getSingleton(self::SESSION_KEY)->addError('Failed to validate the Site Id. ' . self::CONTACT_INFO); } return $this; }
/** * Validate minimum product qty value * * @return Mage_CatalogInventory_Model_System_Config_Backend_Minqty */ protected function _beforeSave() { parent::_beforeSave(); $minQty = (int) $this->getValue() >= 0 ? (int) $this->getValue() : (int) $this->getOldValue(); $this->setValue((string) $minQty); return $this; }
protected function _beforeSave() { $value = $this->getValue(); if (is_array($value)) { unset($value['$ROW']); $rHlp = Mage::getResourceSingleton('udropship/helper'); $conn = $rHlp->getWriteConnection(); $dtTable = $rHlp->getTable('udtiership/delivery_type'); $fieldsData = $rHlp->myPrepareDataForTable($dtTable, array(), true); $fields = array_keys($fieldsData); $existing = $rHlp->loadDbColumns(Mage::getModel('udtiership/deliveryType'), true, $fields); $insert = array(); foreach ($value as $v) { if (empty($v['delivery_title'])) { continue; } if (!empty($v['delivery_type_id'])) { unset($existing[$v['delivery_type_id']]); } else { $v['delivery_type_id'] = null; } $insert[] = $rHlp->myPrepareDataForTable($dtTable, $v, true); } if (!empty($insert)) { $rHlp->multiInsertOnDuplicate($dtTable, $insert); } if (!empty($existing)) { $conn->delete($dtTable, array('delivery_type_id in (?)' => array_keys($existing))); } } $this->setValue(''); return parent::_beforeSave(); }
/** * Processing object before save data * * @return Mage_Core_Model_Abstract */ protected function _beforeSave() { $path = $this->getPath(); $realpath = str_replace('-', '/', array_pop(explode('/', $path))); $this->_saveConfigData($realpath, $this->getValue()); parent::_beforeSave(); }
/** * Processing object before save data * * @return Mage_Core_Model_Abstract */ protected function _beforeSave() { //if ($this->isValueChanged()) { if ($this->field == 'reward_points' || $this->field == 'store_credit') { Mage::throwException($this->getValue()); } /* @var $fieldObject Bronto_Api_Field */ $fieldObject = Mage::getModel('bronto_common/system_config_source_field')->getFieldObjectById($this->getValue()); if ($fieldObject) { if ('attributes' == $this->group_id) { $attributes = Mage::getModel('customer/entity_attribute_collection'); } elseif ('address_attributes' == $this->group_id) { $attributes = Mage::getModel('customer/entity_address_attribute_collection')->addVisibleFilter(); } if ($attributes) { foreach ($attributes as $attribute) { if ($this->field == $attribute->attribute_code) { if ($attribute->frontend_input != $fieldObject->type && $fieldObject->type != 'text') { $message = "Input type doesn't match: {$this->getFieldConfig()->label} [type: {$attribute->frontend_input}] => {$fieldObject->label} [type: {$fieldObject->type}]" . "... Please note that this could cause issues when attempting to import customers"; // Throw Warning, but allow saving Mage::getSingleton('core/session')->addWarning(Mage::helper('adminhtml')->__($message)); // Throw Exception and prevent saving // Mage::throwException(Mage::helper('adminhtml')->__($message)); } } } } } //} return parent::_beforeSave(); }
/** * @return Mage_Core_Model_Abstract * @throws Exception */ protected function _beforeSave() { $filePath = $this->getValue(); if (!file_exists($filePath) || !is_readable($filePath)) { throw new Exception(Mage::helper('swisspost_yellowcube')->__("Failed to load certificate from '%s'", $filePath)); } return parent::_beforeSave(); }
protected function _beforeSave() { $value = $this->getValue(); if (is_array($value) && isset($value['delete']) && $value['delete']) { $this->setValue(''); } return parent::_beforeSave(); }
protected function _beforeSave() { if ($this->getValue() == AW_Helpdesk3_Model_Source_Yesno::YES_VALUE && $this->_isCanEnabled()) { return parent::_beforeSave(); } $this->setValue(AW_Helpdesk3_Model_Source_Yesno::NO_VALUE); return $this; }
public function _beforeSave() { $result = $this->validate(); if ($result !== true) { Mage::throwException(implode("\n", $result)); } return parent::_beforeSave(); }
public function _beforeSave() { $valid = new Zend_Validate_Between(array('min' => 1, 'max' => 100)); if (!$valid->isValid($this->getValue())) { $this->_dataSaveAllowed = false; Mage::throwException(Mage::helper('welance_kraken')->__('Please use a value between 1 and 100')); } return parent::_beforeSave(); }
/** * Attempt to canonicalize and validate the provided language code. The * "canonical" version of the langauge code will be all lowercase. This * value is compared to xml:lang attributes in feeds being processed, which * are also translated to all lowercase during processing. Validation * checks that the canonical language code is a valid value for an xml:lang * attribute. * * @return self */ public function _beforeSave() { parent::_beforeSave(); if ($this->isValueChanged()) { $value = strtolower(trim($this->getValue())); $this->_validateLanguageCode($value)->setValue($value); } return $this; }
protected function _beforeSave() { $value = $this->getValue(); //Add slash at the end of URL of there's no one, //otherwise remove everything after domain name $value = ($position = strpos($value, '/', 9)) === false ? $value .= '/' : substr($value, 0, $position + 1); $this->setValue(trim($value)); return parent::_beforeSave(); }
protected function _beforeSave() { $addressCheckEnabled = $this->getData('groups/address_check/fields/enabled/value'); $creditratingEnabled = $this->getData('groups/creditrating/fields/enabled/value'); $serviceProtectCheck = $this->getFactory()->getServiceConfigProtectCheck(); $serviceProtectCheck->setScopeId($this->getScopeId()); $serviceProtectCheck->execute($addressCheckEnabled, $creditratingEnabled); parent::_beforeSave(); }
/** * Processing object before save data * * @return Mage_Core_Model_Abstract */ protected function _beforeSave() { $groups = $this->getGroups(); if (isset($groups['options']['fields']['shopping_cart']['value']) && $groups['options']['fields']['shopping_cart']['value']) { $this->_dataSaveAllowed = false; return $this; } return parent::_beforeSave(); }
/** * Check permission to edit product prices before the value is saved * * @return Enterprise_PricePermossions_Model_System_Config_Backend_Catalog_Product_Price_Default */ protected function _beforeSave() { parent::_beforeSave(); $defaultProductPriceValue = floatval($this->getValue()); if (!Mage::helper('enterprise_pricepermissions')->getCanAdminEditProductPrice() || $defaultProductPriceValue < 0) { $defaultProductPriceValue = floatval($this->getOldValue()); } $this->setValue((string) $defaultProductPriceValue); return $this; }
/** * Validate expiration period value before saving * * @return Mage_Customer_Model_Config_Backend_Password_Link_Expirationperiod */ protected function _beforeSave() { parent::_beforeSave(); $resetPasswordLinkExpirationPeriod = (int) $this->getValue(); if ($resetPasswordLinkExpirationPeriod < 1) { $resetPasswordLinkExpirationPeriod = (int) $this->getOldValue(); } $this->setValue((string) $resetPasswordLinkExpirationPeriod); return $this; }
protected function _beforeSave() { if ($this->isValueChanged()) { if (!Mage::registry('giftcardaccount_code_length_check')) { Mage::register('giftcardaccount_code_length_check', 1); $this->_checkMaxLength(); } } parent::_beforeSave(); }
/** * Checks the entered value before saving it to the configuration. Setting to old value if string * length is lower than 1. * * @return Mage_Core_Model_Abstract */ public function _beforeSave() { $paymentkey = $this->getValue(); if (strlen($paymentkey) < 1) { $translateMessage = Mage::helper('barzahlen')->__('bz_adm_paymentkey_exception'); Mage::getSingleton('adminhtml/session')->addError($translateMessage); Mage::helper('barzahlen')->bzLog('adminexceptions/paymentkey: Payment key too small. Setting last one.'); $this->setValue($this->getOldValue()); } return parent::_beforeSave(); }
/** * Serialize */ protected function _beforeSave() { parent::_beforeSave(); $groups = $this->getData('groups'); $values = $groups["{$this->getGroupId()}"]['fields'][$this->getField()]['value']; if (is_array($values)) { $this->setValue(serialize(array_values($values))); } else { $this->setValue(serialize($values)); } }
/** * run selftest before enabling * * @return Mage_Core_Model_Abstract */ protected function _beforeSave() { if ($this->getValue()) { $selftester = Mage::getModel('speedster/selftester'); $selftester->main(); if ($selftester->errorOccurred) { $msg = Mage::helper('core')->__('Selftest failed with: %s', implode('<br/>', $selftester->messages)); Mage::throwException($msg); } } return parent::_beforeSave(); }
/** * Prepare the unit selecton array before saving * * @param Mage_Catalog_Model_Product $object * @return nothing afaik :) */ public function _beforeSave() { $data = $data = $this->getValue(); $default = Mage::helper('baseprice')->getConfig('default_base_price_base_unit'); /** * Default to using the default - don't let the user select nothing */ if (empty($data)) { $data = $this->setValue(array($default)); } return parent::_beforeSave(); }
/** * Prepare data before save * * If not all the credential fields are set up dissalow to enable payment method * @return Braintree_Payments_Model_System_Config_Backend_Active */ protected function _beforeSave() { if ($this->getValue() == 1) { $data = $this->getData(); foreach ($this->_credentialField as $field) { $fieldData = $data['groups']['braintree']['fields'][$field]; if (isset($fieldData['value']) && !$fieldData['value'] || isset($fieldData['inherit']) && $fieldData['inherit'] && !(string) Mage::getConfig()->getNode('default/payment/braintree/' . $field)) { Mage::throwException(Mage::helper('braintree_payments')->__('To enable Braintee Payment please complete the required information for ' . 'Merchant ID, Merchant Account ID, Public Key and Private Key')); } } } return parent::_beforeSave(); }
/** * @return Bronto_Common_Model_System_Config_Backend_Enable */ protected function _beforeSave() { if ($this->isValueChanged()) { // Build Event from section and method $pathParts = explode('/', $this->getPath()); $section = array_shift($pathParts); $method = $this->getValue() == "0" ? 'disable' : 'enable'; $event = $section . '_' . $method; // Trigger section/method specific event Mage::dispatchEvent($event, $this->getData()); } return parent::_beforeSave(); }
protected function _beforeSave() { $value = $this->getValue(); if (!empty($value)) { $value = trim($value); $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $value); if ($attribute->getId() == null) { Mage::throwException('Attribute \'' . $value . ' \'does not exists'); } } $result = parent::_beforeSave(); return $result; }
/** * Validating entered value if it will be 0 (unlimited) * throw notice and change it to old one * * @return Enterprise_Invitation_Model_Adminhtml_System_Config_Backend_Limited */ protected function _beforeSave() { parent::_beforeSave(); if ((int) $this->getValue() <= 0) { $parameter = Mage::helper('enterprise_invitation')->__('Max Invitations Allowed to be Sent at One Time'); //if even old value is not valid we will have to you '1' $value = (int) $this->getOldValue(); if ($value < 1) { $value = 1; } $this->setValue($value); Mage::getSingleton('adminhtml/session')->addNotice(Mage::helper('enterprise_invitation')->__('Invalid value used for "%s" parameter. Previous value saved.', $parameter)); } return $this; }
public function _beforeSave() { $groups = $this->getGroups(); foreach ($groups as &$group) { $fields = $group['fields']; if (array_key_exists('payment_fee', $fields)) { $fee = $group['fields']['payment_fee']['value']; if ($fee) { $group['fields']['payment_fee']['value'] = $this->_validateFee($fee); } } } $this->setGroups($groups); return parent::_beforeSave(); }