Beispiel #1
0
 /**
  * Save config section
  * Require set: section, website, store and groups
  *
  * @return Mage_Adminhtml_Model_Config_Data
  */
 public function save()
 {
     Mage::dispatchEvent('searchanise_adminhtml_config_data_save_before', array('object' => $this));
     $ret = parent::save();
     Mage::dispatchEvent('searchanise_adminhtml_config_data_save_after', array('object' => $ret));
     return $ret;
 }
Beispiel #2
0
 /**
  * Init fieldset fields
  *
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Varien_Simplexml_Element $group
  * @param Varien_Simplexml_Element $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return Mage_Adminhtml_Block_System_Config_Form
  */
 public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
 {
     if (!$this->_configDataObject) {
         $this->_initObjects();
     }
     // Extends for config data
     $configDataAdditionalGroups = array();
     foreach ($group->fields as $elements) {
         // sort either by sort_order or by child node values bypassing the sort_order
         $elements = $this->_sortElements($group, $fieldset, (array) $elements);
         foreach ($elements as $element) {
             if (!$this->_canShowField($element)) {
                 continue;
             }
             /**
              * Look for custom defined field path
              */
             $path = (string) $element->config_path;
             if (empty($path)) {
                 $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $element->getName();
             } elseif (strrpos($path, '/') > 0) {
                 // Extend config data with new section group
                 $groupPath = substr($path, 0, strrpos($path, '/'));
                 if (!isset($configDataAdditionalGroups[$groupPath])) {
                     $this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
                     $configDataAdditionalGroups[$groupPath] = true;
                 }
             }
             $this->_initElement($element, $fieldset, $group, $section, $path, $fieldPrefix, $labelPrefix);
         }
     }
     return $this;
 }
 public function load()
 {
     if ($this->getSection() != Mage::app()->getRequest()->getParam('section')) {
         $this->setSection(Mage::app()->getRequest()->getParam('section'));
         $this->_configData = null;
     }
     return parent::load();
 }
Beispiel #4
0
 /**
  * @param array $groups
  * @magentoDbIsolation enabled
  * @dataProvider saveDataProvider
  * @magentoConfigFixture current_store general/single_store_mode/enabled 1
  */
 public function testSaveWithSingleStoreModeEnabled($groups)
 {
     $_configDataObject = new Mage_Adminhtml_Model_Config_Data();
     $_configData = $_configDataObject->setSection('dev')->setWebsite('base')->load();
     $this->assertEmpty($_configData);
     $_configDataObject = new Mage_Adminhtml_Model_Config_Data();
     $_configDataObject->setSection('dev')->setGroups($groups)->save();
     Mage::getConfig()->reinit();
     Mage::app()->reinitStores();
     $_configDataObject = new Mage_Adminhtml_Model_Config_Data();
     $_configDataObject->setSection('dev')->setWebsite('base');
     $_configData = $_configDataObject->load();
     $this->assertArrayHasKey('dev/debug/template_hints', $_configData);
     $this->assertArrayHasKey('dev/debug/template_hints_blocks', $_configData);
     $_configDataObject = new Mage_Adminhtml_Model_Config_Data();
     $_configDataObject->setSection('dev');
     $_configData = $_configDataObject->load();
     $this->assertArrayNotHasKey('dev/debug/template_hints', $_configData);
     $this->assertArrayNotHasKey('dev/debug/template_hints_blocks', $_configData);
 }
Beispiel #5
0
 /**
  * Init fieldset fields
  *
  * @param Varien_Data_Form_Element_Fieldset $fieldset
  * @param Varien_Simplexml_Element $group
  * @param Varien_Simplexml_Element $section
  * @param string $fieldPrefix
  * @param string $labelPrefix
  * @return Mage_Adminhtml_Block_System_Config_Form
  */
 public function initFields($fieldset, $group, $section, $fieldPrefix = '', $labelPrefix = '')
 {
     if (!$this->_configDataObject) {
         $this->_initObjects();
     }
     // Extends for config data
     $configDataAdditionalGroups = array();
     foreach ($group->fields as $elements) {
         $elements = (array) $elements;
         // sort either by sort_order or by child node values bypassing the sort_order
         if ($group->sort_fields && $group->sort_fields->by) {
             $fieldset->setSortElementsByAttribute((string) $group->sort_fields->by, $group->sort_fields->direction_desc ? SORT_DESC : SORT_ASC);
         } else {
             usort($elements, array($this, '_sortForm'));
         }
         foreach ($elements as $element) {
             if (!$this->_canShowField($element)) {
                 continue;
             }
             if ((string) $element->getAttribute('type') == 'group') {
                 $this->_initGroup($fieldset->getForm(), $element, $section, $fieldset);
                 continue;
             }
             /**
              * Look for custom defined field path
              */
             $path = (string) $element->config_path;
             if (empty($path)) {
                 $path = $section->getName() . '/' . $group->getName() . '/' . $fieldPrefix . $element->getName();
             } elseif (strrpos($path, '/') > 0) {
                 // Extend config data with new section group
                 $groupPath = substr($path, 0, strrpos($path, '/'));
                 if (!isset($configDataAdditionalGroups[$groupPath])) {
                     $this->_configData = $this->_configDataObject->extendConfig($groupPath, false, $this->_configData);
                     $configDataAdditionalGroups[$groupPath] = true;
                 }
             }
             $data = $this->_configDataObject->getConfigDataValue($path, $inherit, $this->_configData);
             if ($element->frontend_model) {
                 $fieldRenderer = Mage::getBlockSingleton((string) $element->frontend_model);
             } else {
                 $fieldRenderer = $this->_defaultFieldRenderer;
             }
             $fieldRenderer->setForm($this);
             $fieldRenderer->setConfigData($this->_configData);
             $helperName = $this->_configFields->getAttributeModule($section, $group, $element);
             $fieldType = (string) $element->frontend_type ? (string) $element->frontend_type : 'text';
             $name = 'groups[' . $group->getName() . '][fields][' . $fieldPrefix . $element->getName() . '][value]';
             $label = Mage::helper($helperName)->__($labelPrefix) . ' ' . Mage::helper($helperName)->__((string) $element->label);
             $hint = (string) $element->hint ? Mage::helper($helperName)->__((string) $element->hint) : '';
             if ($element->backend_model) {
                 $model = Mage::getModel((string) $element->backend_model);
                 if (!$model instanceof Mage_Core_Model_Config_Data) {
                     Mage::throwException('Invalid config field backend model: ' . (string) $element->backend_model);
                 }
                 $model->setPath($path)->setValue($data)->setWebsite($this->getWebsiteCode())->setStore($this->getStoreCode())->afterLoad();
                 $data = $model->getValue();
             }
             $comment = $this->_prepareFieldComment($element, $helperName, $data);
             $tooltip = $this->_prepareFieldTooltip($element, $helperName);
             $id = $section->getName() . '_' . $group->getName() . '_' . $fieldPrefix . $element->getName();
             if ($element->depends) {
                 foreach ($element->depends->children() as $dependent) {
                     /* @var $dependent Mage_Core_Model_Config_Element */
                     if (isset($dependent->fieldset)) {
                         $dependentFieldGroupName = (string) $dependent->fieldset;
                         if (!isset($this->_fieldsets[$dependentFieldGroupName])) {
                             $dependentFieldGroupName = $group->getName();
                         }
                     } else {
                         $dependentFieldGroupName = $group->getName();
                     }
                     $dependentFieldNameValue = $dependent->getName();
                     $dependentFieldGroup = $dependentFieldGroupName == $group->getName() ? $group : $this->_fieldsets[$dependentFieldGroupName]->getGroup();
                     $dependentId = $section->getName() . '_' . $dependentFieldGroupName . '_' . $fieldPrefix . $dependentFieldNameValue;
                     $shouldBeAddedDependence = true;
                     $dependentValue = (string) (isset($dependent->value) ? $dependent->value : $dependent);
                     if (isset($dependent['separator'])) {
                         $dependentValue = explode((string) $dependent['separator'], $dependentValue);
                     }
                     $dependentFieldName = $fieldPrefix . $dependent->getName();
                     $dependentField = $dependentFieldGroup->fields->{$dependentFieldName};
                     /*
                      * If dependent field can't be shown in current scope and real dependent config value
                      * is not equal to preferred one, then hide dependence fields by adding dependence
                      * based on not shown field (not rendered field)
                      */
                     if (!$this->_canShowField($dependentField)) {
                         $dependentFullPath = $section->getName() . '/' . $dependentFieldGroupName . '/' . $fieldPrefix . $dependent->getName();
                         $dependentValueInStore = Mage::getStoreConfig($dependentFullPath, $this->getStoreCode());
                         if (is_array($dependentValue)) {
                             $shouldBeAddedDependence = !in_array($dependentValueInStore, $dependentValue);
                         } else {
                             $shouldBeAddedDependence = $dependentValue != $dependentValueInStore;
                         }
                     }
                     if ($shouldBeAddedDependence) {
                         $this->_getDependence()->addFieldMap($id, $id)->addFieldMap($dependentId, $dependentId)->addFieldDependence($id, $dependentId, $dependentValue);
                     }
                 }
             }
             $sharedClass = '';
             if ($element->shared && $element->config_path) {
                 $sharedClass = ' shared shared-' . str_replace('/', '-', $element->config_path);
             }
             $requiresClass = '';
             if ($element->requires) {
                 $requiresClass = ' requires';
                 foreach (explode(',', $element->requires) as $groupName) {
                     $requiresClass .= ' requires-' . $section->getName() . '_' . $groupName;
                 }
             }
             $field = $fieldset->addField($id, $fieldType, array('name' => $name, 'label' => $label, 'comment' => $comment, 'tooltip' => $tooltip, 'hint' => $hint, 'value' => $data, 'inherit' => $inherit, 'class' => $element->frontend_class . $sharedClass . $requiresClass, 'field_config' => $element, 'scope' => $this->getScope(), 'scope_id' => $this->getScopeId(), 'scope_label' => $this->getScopeLabel($element), 'can_use_default_value' => $this->canUseDefaultValue((int) $element->show_in_default), 'can_use_website_value' => $this->canUseWebsiteValue((int) $element->show_in_website)));
             $this->_prepareFieldOriginalData($field, $element);
             if (isset($element->validate)) {
                 $field->addClass($element->validate);
             }
             if (isset($element->frontend_type) && 'multiselect' === (string) $element->frontend_type && isset($element->can_be_empty)) {
                 $field->setCanBeEmpty(true);
             }
             $field->setRenderer($fieldRenderer);
             if ($element->source_model) {
                 // determine callback for the source model
                 $factoryName = (string) $element->source_model;
                 $method = false;
                 if (preg_match('/^([^:]+?)::([^:]+?)$/', $factoryName, $matches)) {
                     array_shift($matches);
                     list($factoryName, $method) = array_values($matches);
                 }
                 $sourceModel = Mage::getSingleton($factoryName);
                 if ($sourceModel instanceof Varien_Object) {
                     $sourceModel->setPath($path);
                 }
                 if ($method) {
                     if ($fieldType == 'multiselect') {
                         $optionArray = $sourceModel->{$method}();
                     } else {
                         $optionArray = array();
                         foreach ($sourceModel->{$method}() as $value => $label) {
                             $optionArray[] = array('label' => $label, 'value' => $value);
                         }
                     }
                 } else {
                     $optionArray = $sourceModel->toOptionArray($fieldType == 'multiselect');
                 }
                 $field->setValues($optionArray);
             }
         }
     }
     return $this;
 }
Beispiel #6
0
 /**
  * Return formatted config data for specified path prefix
  *
  * @param string $path Config path prefix
  * @param bool $full Simple config structure or not
  * @return array
  */
 protected function _getPathConfig($path, $full = true)
 {
     $is_csgroup = Mage::app()->getRequest()->getParam('is_csgroup', false);
     if (!$is_csgroup) {
         return parent::_getPathConfig($path, $full);
     }
     switch ($is_csgroup) {
         case 1:
             $groupData = Mage::app()->getRequest()->getPost();
             $gcode = isset($groupData['group_code']) && strlen($groupData['group_code']) > 0 ? $groupData['group_code'] : (Mage::app()->getRequest()->getParam('gcode', false) ? Mage::app()->getRequest()->getParam('gcode') : '');
             if (strlen($gcode) > 0) {
                 $path = $gcode . '/' . $path;
             }
             break;
         case 2:
             $vendorId = Mage::app()->getRequest()->getParam('vendor_id', 0);
             $vendor = Mage::getModel('csmarketplace/vendor')->load($vendorId);
             if ($vendor && $vendor->getId()) {
                 $path = $vendor->getId() . '/' . $path;
             }
     }
     $configDataCollection = Mage::getModel('core/config_data')->getCollection()->addScopeFilter($this->getScope(), $this->getScopeId(), $path);
     $config = array();
     foreach ($configDataCollection as $data) {
         if ($full) {
             $config[$data->getPath()] = array('path' => $data->getPath(), 'value' => $data->getValue(), 'config_id' => $data->getConfigId());
         } else {
             $config[$data->getPath()] = $data->getValue();
         }
     }
     return $config;
 }
 private function _isNotCloudinaryConfigurationSection(Mage_Adminhtml_Model_Config_Data $configObject)
 {
     return $configObject->getSection() != self::CLOUDINARY_CONFIG_SECTION;
 }