Get all attribute options

To get all attribute options from a Magento dropdown attribute (select field) you can use the following snippet: <?php $oAttibute = Mage::getModel(‘eav/config’)->getAttribute(Mage_Catalog_Model_Product::ENTITY, ‘sheldon_special’); $aOptions = $oAttibute->getSource()->getAllOptions(); var_dump($aOptions); That gives you an array like that: <?php $aOptions = {array} [6] 0 = {array} [2] label = “” value = “” 1 = {array} [2] label = […]

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. <?php $iProductId = $aChange[‘pid’]; $oItem = new Varien_Object; /** * […]

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). <?php /** * * Magento * * NOTICE OF LICENSE * * This source file is subject to the Open Software License (OSL 3.0) * It is available through the world-wide-web at […]

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: <?php /** * Sets position (sort order) values for the given attribute for a given option value. Therefore the given store specific value […]

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) <?php /** * * Magento * * NOTICE OF LICENSE * * This […]

Stop running indexes of Magento

Sometimes Magento indexes hang up unexpectedly. They are shown as running in Magento backend but looking at the process status (@see https://www.ask-sheldon.com/list-processes-after-cpu-usage/), you recognize that the respective process doesn’t do anything. Other common problems are, that there are payment transactions failures when price index is running (catalog_product_price @see http://magento.stackexchange.com/questions/260/price-re-index-causes-db-deadlocks-during-checkout) or that the search doesn’t work properly, […]

Find and eliminate dead parent connections

Recently I had the strange problem. In an old Magento installation there where many simple products connected to parent-ids that didn’t exist anymore. Normally that should’t be possible because of foreign key constraints in MySQL but  in fact they where there. Perhaps there was a bug in an importer script or foreign key checks where […]

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.