/** * @param Mage_Core_Model_Config_Data $object * @return Mage_Core_Model_Config_Data */ protected function checkConfigUnique(Mage_Core_Model_Config_Data $object) { /** @var $collection Mage_Core_Model_Mysql4_Config_Data_Collection | Mage_Core_Model_Resource_Config_Data_Collection */ $collection = $this->getFactory()->getModelCoreConfigData()->getCollection(); $collection->addFieldToFilter('scope', $object->getScope()); $collection->addFieldToFilter('scope_id', $object->getScopeId()); $collection->addFieldToFilter('path', $object->getPath()); $collection->load(); if ($collection->count() > 0) { /** @var $config Mage_Core_Model_Config_Data */ $config = $collection->getFirstItem(); $object->setId($config->getId()); } return $object; }
public function save() { $enabled = $this->getValue(); //get the value from our config $resource = Mage::getSingleton('core/resource'); $readConnection = $resource->getConnection('core_read'); $writeConnection = $resource->getConnection('core_write'); //die($enabled); $query = 'SELECT attribute_id FROM eav_attribute WHERE `attribute_code` = \'telephone\''; $attribute_id = $readConnection->fetchOne($query); $query = 'UPDATE eav_attribute SET `is_required` = \'' . $enabled . '\' WHERE `attribute_code` = \'telephone\''; $writeConnection->query($query); if ($enabled == 1) { $validationRules = 'a:2:{s:15:"max_text_length";i:255;s:15:"min_text_length";i:1;}'; $query = 'UPDATE customer_eav_attribute SET `validate_rules` = \'' . $validationRules . '\' WHERE `attribute_id` = \'' . $attribute_id . '\''; $writeConnection->query($query); } else { $query = 'UPDATE customer_eav_attribute SET `validate_rules` = NULL WHERE `attribute_id` = \'' . $attribute_id . '\''; $writeConnection->query($query); } //die($attribute_id); return parent::save(); //call original save method so whatever happened //before still happens (the value saves) }
/** * Check request for errors found by Helper and Observer. It will print error messages if errors found and * in that case set value to 0. * * @return FACTFinder_Core_Model_System_Config_Backend_Enabled */ public function save() { parent::save(); Mage::app()->cleanCache(); $this->_checkConfiguration(); 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(); }
protected function _afterload() { if (!is_array($this->getValue())) { $this->setValue(explode(",", $this->getValue())); } return parent::_afterload(); }
/** * Cleanup blocks HTML cache if value has been changed * * @return Enterprise_WebsiteRestriction_Model_System_Config_Backend_Active */ protected function _afterSave() { if ($this->isValueChanged()) { Mage::dispatchEvent('clean_cache_by_tags', array('tags' => array(Mage_Core_Model_Store::CACHE_TAG, Mage_Cms_Model_Block::CACHE_TAG))); } return parent::_afterSave(); }
/** * 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(); }
/** * 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; }
/** * 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(); }
/** * Perform API call to Amazon to validate Client ID/Secret * */ public function save() { $data = $this->getFieldsetData(); $isEnabled = $this->getValue(); if ($data['client_id'] && $data['client_secret']) { $_api = Mage::getModel('amazon_login/api'); // REST API params $params = array('grant_type' => 'authorization_code', 'code' => 'SplxlOBeZQQYbYS6WxSbIA', 'client_id' => trim($data['client_id']), 'client_secret' => trim($data['client_secret'])); $response = $_api->request('auth/o2/token', $params); if (!$response) { Mage::getSingleton('core/session')->addError('Error: Unable to perform HTTP request to Amazon API.'); } else { if ($response && isset($response['error'])) { if ($response['error'] == 'invalid_client') { Mage::getSingleton('core/session')->addError('Client authentication failed. Please verify your Client ID and Client Secret.'); $this->setValue(0); // Set "Enabled" to "No" } else { Mage::getSingleton('core/session')->addSuccess('Successfully connected to Amazon API with Client ID and Client Secret.'); } } } } return parent::save(); }
/** * 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 _afterSave() { if ($this->isValueChanged()) { Mage::getModel('enterprise_giftcardaccount/pool')->cleanupFree(); } parent::_afterSave(); }
/** * if we dont' have a value yet retrieve a starting value from * the default config xml configuration * * @return Fooman_PdfCustomiser_Model_Backend_Pdftotal */ protected function _afterLoad() { if ($this->getValue() == '') { $this->setValue((string) Mage::getConfig()->getNode($this->_getGlobalConfigPath())); } return parent::_afterLoad(); }
public function save() { $fdata = array(); foreach ($this->groups['account']['fields'] as $name => $field) { $fdata[$name] = $field['value']; } if ($fdata['embed']) { $obj = json_decode($fdata['embed']); $fdata['embed'] = $obj->embed; $fdata['guid'] = $obj->guid; } include_once dirname(__FILE__) . '/JustunoAccess.php'; $params = array('apiKey' => JUSTUNO_KEY, 'email' => $fdata['email'], 'domain' => $fdata['domain'], 'guid' => $fdata['guid']); if ($fdata['password']) { $params['password'] = $fdata['password']; } $jAccess = new JustunoAccess($params); try { $justuno = $jAccess->getWidgetConfig(); $jusdata = array(); $jusdata['dashboard'] = (string) $jAccess->getDashboardLink(); $jusdata['guid'] = (string) $justuno['guid']; $jusdata['embed'] = (string) $justuno['embed']; $this->setValue((string) json_encode($jusdata)); } catch (JustunoAccessException $e) { Mage::throwException($e->getMessage()); } return parent::save(); }
/** * @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(); }
/** * 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(); }
protected function _beforeSave() { $value = $this->getValue(); Mage::helper('udtiership')->saveV2SimpleCondRates($value); $this->setValue(''); return parent::_beforeSave(); }
public function save() { if (!Mage::getModel($this->getValue())) { Mage::throwException(sprintf('Invalid Access Class: Could not instantiate a [%s]', $this->getValue())); } else { parent::save(); } }
public function save() { // Validate number. Should be a whole number greater than 0. if (!ctype_digit((string) $this->getValue()) || (int) $this->getValue() <= 0) { Mage::throwException("Invalid entry for attempts. Must be a positive whole number, such as 20"); } return parent::save(); }
public function save() { $v = $this->getValue(); if ($v == 'rgba(0, 0, 0, 0)') { $this->setValue('transparent'); } return parent::save(); }
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; }
/** * After save call * Invalidate catalog search index if engine was changed * * @return Enterprise_Search_Model_Adminhtml_System_Config_Backend_Engine */ protected function _afterSave() { parent::_afterSave(); if ($this->isValueChanged()) { Mage::getSingleton('index/indexer')->getProcessByCode('catalogsearch_fulltext')->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); } return $this; }
public function _beforeSave() { $result = $this->validate(); if ($result !== true) { Mage::throwException(implode("\n", $result)); } return parent::_beforeSave(); }
public function save() { if ($value = $this->getValue()) { $value = implode(',', array_unique(explode(',', $this->getValue()))); } $this->setValue($value); return parent::save(); }
public function save() { $value = $this->getValue(); if ($value && !is_numeric($value)) { Mage::throwException("Fields specifying 'Numeric' must have numeric values only!"); } return parent::save(); }
/** * Check permission to read product prices before the value is shown to user * * @return Enterprise_PricePermossions_Model_System_Config_Backend_Catalog_Product_Price_Default */ protected function _afterLoad() { parent::_afterLoad(); if (!Mage::helper('enterprise_pricepermissions')->getCanAdminReadProductPrice()) { $this->setValue(null); } return $this; }
/** * @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(); }
/** * Prepare and store cron settings after save * * @return Mage_Tax_Model_Config_Notification */ protected function _afterSave() { if ($this->isValueChanged()) { $this->_resetNotificationFlag(Mage_Tax_Model_Config::XML_PATH_TAX_NOTIFICATION_DISCOUNT); $this->_resetNotificationFlag(Mage_Tax_Model_Config::XML_PATH_TAX_NOTIFICATION_PRICE_DISPLAY); } return parent::_afterSave(); }
function save() { if ($this->getFieldsetDataValue('active')) { $merchantId = $this->getFieldsetDataValue("merchant_id"); Litle_CreditCard_Model_ValidateMerchantId::validate($merchantId); } return parent::save(); }