Exemple #1
0
 /**
  * @param Mage_Backend_Model_Config_Structure_Reader $structureReader
  * @param Mage_Backend_Model_Config_Structure_Element_Iterator_Tab $tabIterator
  * @param Mage_Backend_Model_Config_Structure_Element_FlyweightFactory $flyweightFactory
  * @param Mage_Backend_Model_Config_ScopeDefiner $scopeDefiner
  */
 public function __construct(Mage_Backend_Model_Config_Structure_Reader $structureReader, Mage_Backend_Model_Config_Structure_Element_Iterator_Tab $tabIterator, Mage_Backend_Model_Config_Structure_Element_FlyweightFactory $flyweightFactory, Mage_Backend_Model_Config_ScopeDefiner $scopeDefiner)
 {
     $this->_data = $structureReader->getData();
     $this->_tabIterator = $tabIterator;
     $this->_flyweightFactory = $flyweightFactory;
     $this->_scopeDefiner = $scopeDefiner;
 }
Exemple #2
0
 public function testGetConfigurationLoadsConfigFromFilesAndCachesIt()
 {
     $expected = array('var' => 'val');
     $this->_cacheMock->expects($this->once())->method('load')->will($this->returnValue(false));
     $this->_converterMock->expects($this->once())->method('convert')->will($this->returnValue(array('config' => array('system' => $expected))));
     $filePath = dirname(dirname(__DIR__)) . '/_files';
     $this->_appConfigMock->expects($this->once())->method('getModuleConfigurationFiles')->will($this->returnValue(array($filePath . '/system_2.xml')));
     $this->_cacheMock->expects($this->once())->method('save')->with(serialize($expected));
     $model = new Mage_Backend_Model_Config_Structure_Reader($this->_appConfigMock, $this->_cacheMock, $this->_converterMock, false);
     $this->assertEquals($expected, $model->getData());
 }
Exemple #3
0
 public function testGetConfigurationLoadsConfigFromFilesAndCachesIt()
 {
     $this->_cacheMock->expects($this->once())->method('load')->will($this->returnValue(false));
     $testFiles = array('file1', 'file2');
     $this->_appConfigMock->expects($this->once())->method('getModuleConfigurationFiles')->will($this->returnValue($testFiles));
     $configMock = new StdClass();
     $configMock->foo = "bar";
     $this->_appConfigMock->expects($this->once())->method('getModelInstance')->with('Mage_Backend_Model_Config_Structure', array('sourceFiles' => $testFiles))->will($this->returnValue($configMock));
     $this->_cacheMock->expects($this->once())->method('save')->with($this->isType('string'));
     $this->assertEquals($configMock, $this->_model->getConfiguration());
 }
Exemple #4
0
 /**
  * Save config section
  * Require set: section, website, store and groups
  *
  * @return Mage_Backend_Model_Config
  */
 public function save()
 {
     $this->_validate();
     $this->_getScope();
     $this->_eventManager->dispatch('model_config_data_save_before', array('object' => $this));
     $section = $this->getSection();
     $website = $this->getWebsite();
     $store = $this->getStore();
     $groups = $this->getGroups();
     $scope = $this->getScope();
     $scopeId = $this->getScopeId();
     if (empty($groups)) {
         return $this;
     }
     $sections = $this->_structureReader->getConfiguration()->getSections();
     $oldConfig = $this->_getConfig(true);
     $deleteTransaction = $this->_transactionFactory->create();
     /* @var $deleteTransaction Mage_Core_Model_Resource_Transaction */
     $saveTransaction = $this->_transactionFactory->create();
     /* @var $saveTransaction Mage_Core_Model_Resource_Transaction */
     // Extends for old config data
     $oldConfigAdditionalGroups = array();
     foreach ($groups as $group => $groupData) {
         /**
          * Map field names if they were cloned
          */
         $groupConfig = $sections[$section]['groups'][$group];
         if ($clonedFields = isset($groupConfig['clone_fields']) && !empty($groupConfig['clone_fields'])) {
             if (isset($groupConfig['clone_model']) && $groupConfig['clone_model']) {
                 $cloneModel = $this->_objectFactory->getModelInstance((string) $groupConfig['clone_model']);
             } else {
                 Mage::throwException('Config form fieldset clone model required to be able to clone fields');
             }
             $mappedFields = array();
             if (isset($groupConfig['fields'])) {
                 $fieldsConfig = $groupConfig['fields'];
                 foreach ($fieldsConfig as $field => $node) {
                     foreach ($cloneModel->getPrefixes() as $prefix) {
                         $mappedFields[$prefix['field'] . (string) $field] = (string) $field;
                     }
                 }
             }
         }
         // set value for group field entry by fieldname
         // use extra memory
         $fieldsetData = array();
         foreach ($groupData['fields'] as $field => $fieldData) {
             $fieldsetData[$field] = is_array($fieldData) && isset($fieldData['value']) ? $fieldData['value'] : null;
         }
         foreach ($groupData['fields'] as $field => $fieldData) {
             /**
              * Get field backend model
              */
             if (isset($groupConfig['fields'][$field]['backend_model'])) {
                 $backendClass = $groupConfig['fields'][$field]['backend_model'];
             } else {
                 if ($clonedFields && isset($mappedFields[$field]) && isset($groupConfig['fields'][$mappedFields[$field]]['backend_model'])) {
                     $backendClass = $groupConfig['fields'][$mappedFields[$field]]['backend_model'];
                 } else {
                     $backendClass = 'Mage_Core_Model_Config_Data';
                 }
             }
             /* @var $dataObject Mage_Core_Model_Config_Data */
             $dataObject = $this->_objectFactory->getModelInstance($backendClass);
             if (!$dataObject instanceof Mage_Core_Model_Config_Data) {
                 Mage::throwException('Invalid config field backend model: ' . $backendClass);
             }
             if (isset($groupConfig['fields'][$field])) {
                 $fieldConfig = $groupConfig['fields'][$field];
             } else {
                 if ($clonedFields && isset($mappedFields[$field])) {
                     $fieldConfig = $groupConfig['fields'][$mappedFields[$field]];
                 }
             }
             $dataObject->setField($field)->setGroups($groups)->setGroupId($group)->setStoreCode($store)->setWebsiteCode($website)->setScope($scope)->setScopeId($scopeId)->setFieldConfig($fieldConfig)->setFieldsetData($fieldsetData);
             $this->_checkSingleStoreMode($fieldConfig, $dataObject);
             if (!isset($fieldData['value'])) {
                 $fieldData['value'] = null;
             }
             $path = $section . '/' . $group . '/' . $field;
             /**
              * Look for custom defined field path
              */
             if ($fieldConfig && isset($fieldConfig['config_path'])) {
                 $configPath = (string) $fieldConfig['config_path'];
                 if (!empty($configPath) && strrpos($configPath, '/') > 0) {
                     // Extend old data with specified section group
                     $groupPath = substr($configPath, 0, strrpos($configPath, '/'));
                     if (!isset($oldConfigAdditionalGroups[$groupPath])) {
                         $oldConfig = $this->extendConfig($groupPath, true, $oldConfig);
                         $oldConfigAdditionalGroups[$groupPath] = true;
                     }
                     $path = $configPath;
                 }
             }
             $inherit = !empty($fieldData['inherit']);
             $dataObject->setPath($path)->setValue($fieldData['value']);
             if (isset($oldConfig[$path])) {
                 $dataObject->setConfigId($oldConfig[$path]['config_id']);
                 /**
                  * Delete config data if inherit
                  */
                 if (!$inherit) {
                     $saveTransaction->addObject($dataObject);
                 } else {
                     $deleteTransaction->addObject($dataObject);
                 }
             } elseif (!$inherit) {
                 $dataObject->unsConfigId();
                 $saveTransaction->addObject($dataObject);
             }
         }
     }
     $deleteTransaction->delete();
     $saveTransaction->save();
     return $this;
 }