Category Archives: Magento

Add static block to template

First you have to create the static block in admin->CMS-> Static Blocks. Let’s name it “home_banner”

Then, In the layout (app/design/frontend/your_theme/layout/page.xml) add this code:

[xml]

<cms_page>
        <reference name="content">
            <block type="cms/block" name="home_banner" as="home_banner">
                <action method="setBlockId"><block_id>home_banner</block_id></action>
            </block>
        </reference>
    </cms_page>

[/xml]

 

After that, in the phtml template file, add this line where the static block should be visible:

[php]

<?php echo $this->getChildHtml(‘banner’)?>

[/php]

Now refresh the page and be amazed! (watch out for cache)

OKU – fix magento when enabling compilation

I also had this problem, when enabling the Compilation setting.

The code above threw me at first, I found the file at:

/includes/config.php

On the root of the Magento Installation (1.5.1 in my case).

Simply swap this:

 

define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
#define('COMPILER_COLLECT_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'stat');

For this:

 

#define('COMPILER_INCLUDE_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'src');
define('COMPILER_COLLECT_PATH', dirname(__FILE__).DIRECTORY_SEPARATOR.'stat');

Executing Magento Indexer From Shell

In some situation when you want to re-index Magento catalog you will get an error message or reindex process will be broken. This problem is appearing when you have a lot of products in database and limited server resource. You can try to reindex from command line or shell.
In Magento there is folder with name “shell” in this folder you will find file with name “indexer.php” this is shell script for reindexing. You will ask yourself how to call this script, and take a look on my examples below and everything will be clear.

First of all you need to have access to linux commnad line or shell, and then go to your “MAGENTO_ROOT_FOLDER/shell“.

[php]

$ php -f indexer.php help
  --status             Show Indexer(s) Status
  --mode               Show Indexer(s) Index Mode
  --mode-realtime      Set index mode type "Update on Save"
  --mode-manual        Set index mode type "Manual Update"
  --reindex            Reindex Data
  info                          Show allowed indexers
  reindexall                    Reindex Data by all indexers
  help                          This help
       Comma separated indexer codes or value "all" for all indexers

<div>[/php]

catalog_product_attribute     Product Attributes
catalog_product_price         Product Prices
catalog_url                   Catalog Url Rewrites
catalog_product_flat          Product Flat Data
catalog_category_flat         Category Flat Data
catalog_category_product      Category Products
catalogsearch_fulltext        Catalog Search Index
cataloginventory_stock        Stock status