can a magento adminhtml field depend on more then one field or value?

前端 未结 4 1609
名媛妹妹
名媛妹妹 2020-12-17 03:40

In http://alanstorm.com/magento_system_configuration_in_depth_tutorial @AlanStorm gives a very good tutorial for system configuration.

He also explains how to use a

4条回答
  •  清歌不尽
    2020-12-17 04:06

    Andrew's answer almost did the trick. I'm on 1.6.2.0 right now and I modified the initFields() method in app\code\core\Mage\Adminhtml\Block\System\Config\Form.php as follows:

    if ($e->depends) {
        foreach ($e->depends->children() as $dependent) {
            Mage::log((array)$dependent);
            $dependentId = $section->getName()
                . '_' . $group->getName()
                . '_' . $fieldPrefix
                . $dependent->getName();
    
            if ($dependent->hasChildren()) {
                $dependentValue = (array) $dependent;
                $dependentValue = array_values($dependentValue);
            } else {
                $dependentValue = (string) $dependent;
            }
    
            $shouldBeAddedDependence = true;
            $dependentFieldName      = $fieldPrefix . $dependent->getName();
            $dependentField          = $group->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()
                    . '/' . $group->getName()
                    . '/' . $fieldPrefix
                    . $dependent->getName();
                if (is_array($dependentValue)) {
                    foreach ($dependentValue as $dependentOption) {
                        $shouldBeAddedDependence |= $dependentOption != Mage::getStoreConfig(
                            $dependentFullPath,
                            $this->getStoreCode()
                        );
                    }
                } else {
                    $shouldBeAddedDependence = $dependentValue != Mage::getStoreConfig(
                        $dependentFullPath,
                        $this->getStoreCode()
                    );
                }
            }
            if($shouldBeAddedDependence) {
                $this->_getDependence()
                    ->addFieldMap($id, $id)
                    ->addFieldMap($dependentId, $dependentId)
                    ->addFieldDependence($id, $dependentId, $dependentValue);
            }
        }
    }
    

    Also it's not necessary to edit the core files. I overrode the admin theme to insert my own version of form.js and rewrote the two PHP classes using the config.xml of a custom module.

提交回复
热议问题