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.

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: /** * Get saleable simple products from configurable parent product * * @var Mage_Catalog_Model_Product_Type_Configurable $oParentProduct * @return array of Mage_Catalog_Model_Product(Mage_Catalog_Model_Product_Type_Simple) */ public function getAllowedProducts($oParentProduct) { $aProducts = []; $bSkipSaleableCheck = Mage::helper(‘catalog/product’)->getSkipSaleableCheck(); $oAllProducts = […]

Remove items from a collection

Sometimes you need to remove items from a collection (products f.e.) after it was loaded. The following example shows how I removed non salable product items from a collection of sibling products. The respective collection have to be inherited from Varien_Data_Collection. <?php public function getSiblingsCollection() { $oCollection = Mage::getModel(‘catalog/product’)->getCollection() ->addFieldToFilter(‘sheldon_articlenbr’, array(‘eq’ => $this->getProduct()->getData(‘sheldon_articlenbr’))) ->addFieldToFilter(‘type_id’, array(‘eq’ => Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)) […]