Magento change attribute scope in setup script

This code snippet shows how to change attribute scope in a setup script:

<?php

/* @var $oInstaller Mage_Catalog_Model_Resource_Setup */
$oInstaller = $this;

$oInstaller->startSetup();

$oInstaller->updateAttribute(
    'catalog_product', 'abc_attribute', 'is_global',
    Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
);
$oInstaller->updateAttribute(
    'catalog_product', 'xyz_attribute', 'is_global',
    Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE
);

$oInstaller->endSetup();

// mark index as "reindex required"
$aIndexerCodes = [
    'catalog_product_attribute',
    'catalog_product_flat',
    'catalogsearch_fulltext'
];

$oIndexer = Mage::getModel('index/process');
foreach ($aIndexerCodes as $sCode) {
    $oIndexer->load($sCode, 'indexer_code')
        ->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
}

//clear EAV Cache:
$oInstaller->cleanCache();

And the config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Sheldon_Catalog>
            <version>0.1.0</version>
        </Sheldon_Catalog>
    </modules>
    <global>
        <resources>
            <sheldon_catalog_setup>
                <setup>
                    <module>Sheldon_Catalog</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
            </sheldon_catalog_setup>
        </resources>
    </global>
</config>

 

Leave a Reply

Your email address will not be published.

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.