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) […]

Force HTTPS for the whole store

Since Magento 1.9.1 you can force HTTPS for the whole shop by adding the following configuration-snipped to /app/etc/config.xml or any module config.xml (own module!!!): <frontend> <secure_url> <all>/</all> </secure_url> </frontend> After cleaning the config cache, Magento should generate secure URLs everywhere. That’s how to force secure URL’s in Magento.

Create your own Backend theme

When developing Magento Backend functionalities, sometimes you need to add own layout files or templates. In these cases it is a good idea to create a new Backend theme under adminhtml and to modify the Magento configuration to lookup layout files and templates in this new theme before searching in the default one. Therefore you have to create […]

Install attribute in entity main table

Sometimes it is useful to add some fields to the attribute main table (f.e.: IDs from external systems like a middleware or a PIM). In the following example you can see how to add ID-fields to the category entity. Therefore I created a setupscript as an instance of Mage_Catalog_Model_Resource_Setup. Setup-model declaration in config.xml: <?xml version=”1.0″?> […]

Rewrite exiting Magento models

To rewrite exiting Magento models, you can add the following snippet to your modules config.xml: <?xml version=”1.0″?> <config> <modules> <AskSheldon_Module> <version>0.1.3</version> </AskSheldon_Module> </modules> <!– … –> <global> <models> <checkout> <rewrite> <session>AskSheldon_Module_Model_Checkout_Session</session> <type_onepage>AskSheldon_Module_Model_Checkout_Type_Onepage</type_onepage> </rewrite> </checkout> </models> </global> <!– … –> </config> In this case Mage_Checkout_Model_Session and Mage_Checkout_Model_Type_Onepage are rewritten.

Translation files for custom modules

To register a translation file for your module: <!– Translation file for FE –> <frontend> <translate> <modules> <Sheldon_Module> <files> <!– filename under app/locale/LANGUAGE_CODE/ f.e.: LANGUAGE_CODE = “EN_US” –> <default>filename.csv</default> </files> </Sheldon_Module> </modules> </translate> </frontend>   <!– Translation file for BE–> <adminhtml> <translate> <modules> <Sheldon_Module> <files> <!– filename under app/locale/LANGUAGE_CODE/ f.e.: LANGUAGE_CODE = “EN_US” –> <default>filename.csv</default> […]

Magento – Define default values in config.xml

You can define system config value defaults in your modules config.xml like that. <?xml version=”1.0″?> <default> <myconfig_group> <settings> <test>1</test> <cronjobs>0</cronjobs> <client>0813</client> <serviceprovider>117</serviceprovider> <pricelist></pricelist> </settings> <productexport> <lux_kategorie>21</lux_kategorie> <store_view_german>1</store_view_german> <store_view_english>12</store_view_english> </productexport> </myconfig_group> </default> This sets the default value for all stores. If you want to set default values for a special store (scope), you can do it […]

Event Observer

The following snippet have to be added to the config.xml under the frontend (for FE-events) – or the adminhtml (for BE-Events) – tag: <events> <event_name> <observers> <observer_unique_config_name> <!– singleton or model –> <type>singleton</type> <class>Namespace_Modul_Model_Modelname</class> <method>functionToCallOnModelClassInstance</method> </observer_unique_config_name> </observers> </event_name> </events>  

Automatically load custom product attribute with collection (every time)

You can do this with the following XML in your config.xml: <frontend> <product> <collection> <attributes> <ATTRIBUTECODE/> </attributes> </collection> </product> </frontend> But ATTENTION: This can become a performance issue, because it loads the attribute every time the product collection is loaded! If you added too many attributes, the performance can get worse!