1

I'm trying to limit the states that show in the dropdown in the store. I thought that overriding the _initSelect() method in the app/code/core/Mage/Directory/Model/Resource/Region/Collection.php would help do the trick. Unfortunately, while the change works when applied to the original file, it doesn't work in the override.

Here's the relevant line in my config.xml:

<global>
    <models>
        <directory>
            <rewrite>
                <resource_region_collection>
                    Test_Test_Model_Directory_Resource_Region_Collection
                </resource_region_collection>
            </rewrite>
        </directory>
    </models>
</global>

Here's my version of the file in app/code/local/Test/Test/Model/Directory/Resource/Region/Collection.php:

<?php
class Test_Test_Model_Directory_Resource_Region_Collection extends Mage_Directory_Model_Resource_Region_Collection
{
    protected function _initSelect()
    {
        parent::_initSelect();
        $excludeRegions = array ('AS','AF','AA','AC','AE','AM','AP','FM','GU','MH','MP','PW','VI');
        $this->getSelect()->where('code NOT IN (?)', $excludeRegions);

        return $this;
    }
}

The "Test" module is working for other Magento overrides I have running, but for some reason isn't working for this one in particular. Any thoughts or suggestions would be awesome, thanks!

0

Resource models overwrites are not declared the same way as normal models you should replace:

<directory>
        <rewrite>
            <resource_region_collection>
                Test_Test_Model_Directory_Resource_Region_Collection
            </resource_region_collection>
        </rewrite>
    </directory>

with:

<directory_resource>
        <rewrite>
            <region_collection>
                Test_Test_Model_Directory_Resource_Region_Collection
            </region_collection>
        </rewrite>
    </directory_resource>
  • Thank you so much! That was the answer, I didn't realize the declaration was different. Thanks again! – Zero Wing Jul 5 '16 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.