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

Image resizer

Just a testscript to test the quality of Magento’s image processing: <?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 this URL: * http://opensource.org/licenses/osl-3.0.php * * * @category AskSheldon * @package AskSheldon_FeaturedProducts […]

Install CMS pages with your module

You can do this as shown in the following example of a Magento data setup script: <?php /* @var $installer Mage_Core_Model_Resource_Setup */ $oInstaller = $this; $oInstaller->startSetup(); $aCmsPages = [ [ ‘title’ => ‘FAQ’, ‘root_template’ => ‘two_columns_left’, ‘meta_keywords’ => ‘FAQ’, ‘meta_description’ => ‘FAQ’, ‘identifier’ => ‘faq’, ‘is_active’ => 1, ‘stores’ => 0, ‘sort_order’ => 0, ‘content_heading’ => […]

Install CMS blocks with your module

You can do this as shown in the following example: <?php /* @var $installer Mage_Core_Model_Resource_Setup */ $oInstaller = $this; $oInstaller->startSetup(); $oCmsBlocks = [ [ ‘title’ => ‘Footer bar for benefits’, ‘identifier’ => ‘footer-bar’, ‘content’ => <<<HTML <ul> <li>Shop Benefit 1</li> <li>Shop Benefit 2</li> <li>Shop Benefit 3</li> <li>Shop Benefit 4</li> <li>Customer Service (D): <a href=”tel:08008828838″ class=”tel”>0800 […]

Debug database queries with parameters

Sometimes you have to query the database directly in your module. In these situations you can use the placeholder feature of the Zend_Db_Statement component. :placeholder will be replaced by the respective value when calling fetch on a Zend_Db_Adapter_Mysqli instance with an array of replacements for example. If you need to debug the query with all parameters in it, […]

Change config during runtime

Sometimes you need to change the Magento configuration during runtime. For example this is the way to temporarily disable the category flat tables <?php Mage::app()->getCacheInstance()->banUse(‘config’); //better switch of config cache Mage::app()->getStore()->setConfig(‘catalog/frontend/flat_catalog_category’, “0”); // … Do wired stuff … Mage::app()->getStore()->setConfig(‘catalog/frontend/flat_catalog_category’, “1”); Attention: You have to reindex categories afterwards!!!

Disable usage of flat tables for categories via code

<?php $oCategoryCollection = Mage::getModel(‘catalog/category’, array(‘disable_flat’ => true))->getCollection(); That’s it! Now the “normal” entity tables are used. That work’s because the field disable_flat decides what kind of collection is loaded in the constructor of Mage_Catalog_Model_Category: <?php class Mage_Catalog_Model_Category extends Mage_Catalog_Model_Abstract { //… /** * Initialize resource mode * * @return void */ protected function _construct() { // […]

Simulate store to set or get store specific values

In earlier Magento versions it was quite difficult to set or read store specific values on entities. In most cases you have to set the store on the whole application instance like that: <?php Mage::app(STOREID)->setStore(STOREID); … $oProduct->setStore(STOREID); … $oCollection->setStore(STOREID); Sometimes it was even necessary to add the store  to entities or collections it-selves too. Now (at least […]