Пример #1
0
 /**
  * Process group data
  *
  * @param string $groupId
  * @param array $groupData
  * @param array $groups
  * @param string $sectionPath
  * @param array $extraOldGroups
  * @param array $oldConfig
  * @param Mage_Core_Model_Resource_Transaction $saveTransaction
  * @param Mage_Core_Model_Resource_Transaction $deleteTransaction
  */
 protected function _processGroup($groupId, array $groupData, array $groups, $sectionPath, array &$extraOldGroups, array &$oldConfig, Mage_Core_Model_Resource_Transaction $saveTransaction, Mage_Core_Model_Resource_Transaction $deleteTransaction)
 {
     $groupPath = $sectionPath . '/' . $groupId;
     $website = $this->getWebsite();
     $store = $this->getStore();
     $scope = $this->getScope();
     $scopeId = $this->getScopeId();
     /**
      *
      * Map field names if they were cloned
      */
     /** @var $group Mage_Backend_Model_Config_Structure_Element_Group */
     $group = $this->_configStructure->getElement($groupPath);
     // set value for group field entry by fieldname
     // use extra memory
     $fieldsetData = array();
     if (isset($groupData['fields'])) {
         if ($group->shouldCloneFields()) {
             $cloneModel = $group->getCloneModel();
             $mappedFields = array();
             /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */
             foreach ($group->getChildren() as $field) {
                 foreach ($cloneModel->getPrefixes() as $prefix) {
                     $mappedFields[$prefix['field'] . $field->getId()] = $field->getId();
                 }
             }
         }
         foreach ($groupData['fields'] as $fieldId => $fieldData) {
             $fieldsetData[$fieldId] = is_array($fieldData) && isset($fieldData['value']) ? $fieldData['value'] : null;
         }
         foreach ($groupData['fields'] as $fieldId => $fieldData) {
             $originalFieldId = $fieldId;
             if ($group->shouldCloneFields() && isset($mappedFields[$fieldId])) {
                 $originalFieldId = $mappedFields[$fieldId];
             }
             /** @var $field Mage_Backend_Model_Config_Structure_Element_Field */
             $field = $this->_configStructure->getElement($groupPath . '/' . $originalFieldId);
             /** @var Mage_Core_Model_Config_Data $backendModel */
             $backendModel = $field->hasBackendModel() ? $field->getBackendModel() : $this->_configDataFactory->create();
             $data = array('field' => $fieldId, 'groups' => $groups, 'group_id' => $group->getId(), 'store_code' => $store, 'website_code' => $website, 'scope' => $scope, 'scope_id' => $scopeId, 'field_config' => $field->getData(), 'fieldset_data' => $fieldsetData);
             $backendModel->addData($data);
             $this->_checkSingleStoreMode($field, $backendModel);
             if (false == isset($fieldData['value'])) {
                 $fieldData['value'] = null;
             }
             $path = $field->getGroupPath() . '/' . $fieldId;
             /**
              * Look for custom defined field path
              */
             if ($field && $field->getConfigPath()) {
                 $configPath = $field->getConfigPath();
                 if (!empty($configPath) && strrpos($configPath, '/') > 0) {
                     // Extend old data with specified section group
                     $configGroupPath = substr($configPath, 0, strrpos($configPath, '/'));
                     if (!isset($extraOldGroups[$configGroupPath])) {
                         $oldConfig = $this->extendConfig($configGroupPath, true, $oldConfig);
                         $extraOldGroups[$configGroupPath] = true;
                     }
                     $path = $configPath;
                 }
             }
             $inherit = !empty($fieldData['inherit']);
             $backendModel->setPath($path)->setValue($fieldData['value']);
             if (isset($oldConfig[$path])) {
                 $backendModel->setConfigId($oldConfig[$path]['config_id']);
                 /**
                  * Delete config data if inherit
                  */
                 if (!$inherit) {
                     $saveTransaction->addObject($backendModel);
                 } else {
                     $deleteTransaction->addObject($backendModel);
                 }
             } elseif (!$inherit) {
                 $backendModel->unsConfigId();
                 $saveTransaction->addObject($backendModel);
             }
         }
     }
     if (isset($groupData['groups'])) {
         foreach ($groupData['groups'] as $subGroupId => $subGroupData) {
             $this->_processGroup($subGroupId, $subGroupData, $groups, $groupPath, $extraOldGroups, $oldConfig, $saveTransaction, $deleteTransaction);
         }
     }
 }