首页>Magento>source

我是新的magento,我想覆盖位于 /app/code/core/Mage/Directory/Helper/Data.php的"Data.php"文件

我想从DropDownList中删除不需要的状态。

下面是我在Data.php文件中的函数

 受保护的函数_getRegions($ storeId)
     {
         $ countryIds = array();
         $ countryCollection = $ this->getCountryCollection() - >loadByStore($ storeId);
         foreach($ countryCollection as $ country){
             $ countryIds [] = $ country->getCountryId();
         }
         / ** @var $ regionModel Mage_Directory_Model_Region * /
         $ regionModel = $ this - >_ factory->getModel('directory / region');
         / ** @var $ collection Mage_Directory_Model_Resource_Region_Collection * /
         $ collection = $ regionModel->getResourceCollection()
             - >addCountryFilter($ countryIds)
             - >负载();
         $ regions = array(
             'config'=>array(
                 'show_all_regions'=>$ this->getShowNonRequiredState(),
                 'regions_required'=>$ this->getCountrieswithStatesRequired()
             )
         );
         foreach($ collection as $ region){
             if(!$ region->getRegionId()){
                 继续;
             }
             // EOF自定义逻辑
             $ regions [$ region->getCountryId()] [$ region->getRegionId()] = array(
                 'code'=>$ region->getCode(),
                 'name'=>$ this - >__($ region->getName())
             );
         }
         返回$ regions;
     }

在上面的函数中,我想添加用于从下拉列表中删除不需要的状态的代码.我已经为此添加了代码,但是当我添加上述函数时,我没有任何效果。

 受保护的函数_getRegions($ storeId)
     {
         $ countryIds = array();
         $ countryCollection = $ this->getCountryCollection() - >loadByStore($ storeId);
         foreach($ countryCollection as $ country){
             $ countryIds [] = $ country->getCountryId();
         }
         / ** @var $ regionModel Mage_Directory_Model_Region * /
         $ regionModel = $ this - >_ factory->getModel('directory / region');
         / ** @var $ collection Mage_Directory_Model_Resource_Region_Collection * /
         $ collection = $ regionModel->getResourceCollection()
             - >addCountryFilter($ countryIds)
             - >负载();
         $ regions = array(
             'config'=>array(
                 'show_all_regions'=>$ this->getShowNonRequiredState(),
                 'regions_required'=>$ this->getCountrieswithStatesRequired()
             )
         );
         $ excludeRegions = array('AE','AA');
         foreach($ collection as $ region){
             if(!$ region->getRegionId()){
                 继续;
             }
              // BOF自定义逻辑
             *** $ regionCode = $ region->getCode();
             从(阵列( '区域'=>$此>_选择 - >-  - $这>_ regionTable),
             array('region_id'=>'region_id','country_id'=>'country_id','code'=>'code','default_name'=>'default_name')
             ) - >where('code NOT IN(?)',$ exclude_regions); ***
             // EOF自定义逻辑
             $ regions [$ region->getCountryId()] [$ region->getRegionId()] = array(
                 'code'=>$ region->getCode(),
                 'name'=>$ this - >__($ region->getName())
             );
         }
         返回$ regions;
     }

即使是整个Data.php文件以及上面的更改我都保存在本地目录中但它不起作用。

最新回答
  • 2019-12-5
    1 #

    我不鼓励你使用这种覆盖方式,比如创建 app/code/local/Mage/Directory/Helper/Data.php ,这只是意大利面条代码的好方法..

    创建一个模块 Vids_Directory   在游泳池 local   类似 app/code/local/Vids/Directory

    创建 app/etc/modules/Vids_Directory.xml   和这段代码:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Vids_Directory>
                <active>true</active>
                <codePool>local</codePool>
                <depends>
                    <Mage_Directory />
                </depends>
            </Vids_Directory>
        </modules>
    </config>
    

    创建 app/code/local/Vids/Directory/etc/config.xml   并添加以下代码:

    <?xml version="1.0"?>
    <config>
        <modules>
            <Vids_Directory>
                <version>0.1.0</version>
            </Vids_Directory>
        </modules>
        <global>
            <helpers>
                <directory>
                    <rewrite>
                        <data>Vids_Directory_Helper_Data</data>
                    </rewrite>
                <directory>
            </helpers>
        </global>
    </config>
    

    最后,你可以创建 app/code/local/Vids/Helper/Data.php   并添加:

    <?php
    class Vids_Directory_Helper_Data extends Mage_Directory_Helper_Data 
    {
        protected function _getRegions($storeId) {
            // Your code inside
        }
    }
    

    Note   :你的代码 $this->_select->from...   什么都没有,小心(或者你可能错过了添加完整的代码?)。

    希望它能帮到你:)。

  • magento2:Magento 2:仅限作曲家安装
  • model:更新自定义管理模块中的EAV属性值