Magento: change applied attribute product types

Sometimes it is necessary to change the product type(s) an attribute is applied to in Magento. A common example is, that you designed and implemented an attribute for a configurable product, because you thought its real world value is equal over all child manifestations. But after a while you realize, that there are differences that you […]

Magento change attribute scope in setup script

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

And the config.xml:


Associate products to all websites more performant

Recently I had to associate all products of a shop to newly created websites in a setup shell script (Associate products to all websites). This could have been implemented like that:

A much better approach was it to use class Mage_Catalog_Model_Product_Action like that:

This was much more performant, than saving each product all the time. By the […]

Get all attribute options

To get all attribute options from a Magento dropdown attribute (select field) you can use the following snippet:

That gives you an array like that:

This can be used as source for a system config field for example. See my blogpost about Category dropdown element. To get a specific value by given label, you can […]

Load product attributes more performant

Recently I had performance issues when importing several ten tausend products. The problem was, that I always used the “normal” product entity model to load attribute values. The following snippet shows, how to load product attributes directly instead. Therefore I use the product resource singleton.

Option value position (select value sort order)

This Magento shell script sorts the values of a given attribute after the order of values in a given CSV file (sets option value position).

So it is not necessary to set the values via BE-Interface. The value matching to find the respective option-id is done by using the value of the Storeview specified in REFERENCESTORE and the attribute […]

Query Magento database object oriented

Naturally you can query Magento database directly as described in my earlier post about querying Magento database. But a much smarter way is it, to use exiting Magento objects and constructs like that:

This is a simplified version of a function (better to say shell script class) that sets attribute value positions for a certain […]

Get product attribute ID in Magento

This is how to get product EAV attribute ID without querying the database directly:


Create database tables in setup scripts

The following snippet shows, how to create database tables in a setup script. It uses no direct queries against the database but the an object oriented way Magento does such things. (This snipped assumes  that your resource setup model is derived from Mage_Core_Model_Resource_Setup)

As you can see, it is also possible to add indexes and […]

Get all saleable simple products from configurable product

The following function just gets all saleable (if saleable check is enabled in the Magento configuration) child products from a configurable product: