Convert EPS files to SVG graphics using PHP and Inkscape

Recently I had the job to convert EPS files to SVG graphics. It has been done for a product configurator that had to be implemented. The whole implementation mentioned here was done for a Magento Online Shop. But the base-paradigms described here can be used in other PHP based applications too because I’ve implemented them […]

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

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: <?php /** * Associates products to the newly created websites */ private function _associateProducts() { $aWebsiteIDs = Mage::getModel(‘core/website’) ->getResourceCollection() ->getAllIds(); //remove default website array_shift($aWebsiteIDs); // […]

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