Magento IMP 5


Overriding A Controller

<config> <frontend> <routers> <checkout> <args> <modules> <your_module before="Mage_Checkout">Your_Module_Checkout</your_module> </modules> </args> </checkout> </routers> </frontend> </config>

Sandbox Script

Sometimes you want to run some code to see what it does, dump an object out or check a class but the thing you want to run/dump/check is hidden deep in the bowels of the code somewhere, and you feel it might be easier to run a bit of PHP to check just that one thing, without having to fire up or your browser, or wait for cron to run - that’s where this sandbox script comes in.
To use either of the examples below, save them into a file in the root of your magento install calledsandbox.php, then either browse to the directory and run php -f sandbox.php or visithttp://your.dev.site/sandbox.php
To run the default store:
<?php require 'app/Mage.php'; Mage::app(); // your code
To act as cron:
<?php require 'app/Mage.php'; $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']); $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']); Mage::app('admin')->setUseSessionInUrl(false); Mage::getConfig()->init()->loadEventObservers('crontab'); Mage::app()->addEventArea('crontab'); // your code

Config Transactional Email Template Definition

<config> <global> <template> <email> <your_module_email_something_template translate="label" module="namespace_module"> <label>Something</label> <file>namespace/module/something.html</file> <type>html</type> </your_module_email_something_template> </email> </template> </global> </config>

Block Caching

To cache a block individually, add this method to the blocks class:
protected function _construct() { $this->addData(array( 'cache_lifetime' => 3600, 'cache_tags' => array(Mage_Cms_Model_Block::CACHE_TAG), 'cache_key' => 'CACHE_KEY', )); }
Note - if you set cache_lifetime to 0 (or any other value which PHP evaluates to false) then the cache will actually last 7200 seconds (2 hours), so in order to have a very high cache time then the cache_lifetime should be set to anything up to 9999999999 (about 317 years)

Category Product Collection

This snippet provides a collection of products within a category
$cat = Mage::getModel('catalog/category')->load(1); $coll = Mage::getResourceModel('catalog/product_collection'); $coll->addCategoryFilter($cat);

Config Redis Cache Definition

You needCm_Cache_Backend_Redisfor this
<config> <global> <cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>localhost</server> <!-- or absolute path to unix socket for better performance --> <port>6379</port> <database>0</database> <force_standalone>0</force_standalone> <!-- 0 for phpredis, 1 for standalone PHP --> <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --> <compress_data>1</compress_data> <!-- 0-9 for compression level, recommended: 0 or 1 --> <compress_tags>1</compress_tags> <!-- 0-9 for compression level, recommended: 0 or 1 --> <compress_threshold>20480</compress_threshold> <!-- Strings below this size will not be compressed --> <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> </backend_options> </cache> <full_page_cache> <backend>Cm_Cache_Backend_Redis</backend> <backend_options> <server>localhost</server> <!-- or absolute path to unix socket for better performance --> <port>6379</port> <database>1</database> <force_standalone>0</force_standalone> <!-- 0 for phpredis, 1 for standalone PHP --> <automatic_cleaning_factor>0</automatic_cleaning_factor> <!-- Disabled by default --> <compress_data>1</compress_data> <!-- 0-9 for compression level, recommended: 0 or 1 --> <compress_tags>1</compress_tags> <!-- 0-9 for compression level, recommended: 0 or 1 --> <compress_threshold>20480</compress_threshold> <!-- Strings below this size will not be compressed --> <compression_lib>gzip</compression_lib> <!-- Supports gzip, lzf and snappy --> </backend_options> </full_page_cache> </global> </config>

Config Two-Level Memcached & DB Definition

<config> <global> <cache> <backend>memcached</backend> <slow_backend>database</slow_backend> <id_prefix>cache_</id_prefix> <memcached> <servers> <server1> <host><![CDATA[localhost]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[0]]></persistent> <weight><![CDATA[1]]></weight> <timeout><![CDATA[60]]></timeout> <retry_interval><![CDATA[10]]></retry_interval> </server1> </servers> <compression><![CDATA[0]]></compression> <cache_dir><![CDATA[]]></cache_dir> <hashed_directory_level><![CDATA[]]></hashed_directory_level> <hashed_directory_umask><![CDATA[]]></hashed_directory_umask> <file_name_prefix><![CDATA[]]></file_name_prefix> </memcached> </cache> <full_page_cache> <backend>memcached</backend> <slow_backend>database</slow_backend> <id_prefix>fullpagecache_</id_prefix> <memcached> <servers> <server1> <host><![CDATA[localhost]]></host> <port><![CDATA[11211]]></port> <persistent><![CDATA[0]]></persistent> <weight><![CDATA[1]]></weight> <timeout><![CDATA[60]]></timeout> <retry_interval><![CDATA[10]]></retry_interval> </server1> </servers> <compression><![CDATA[0]]></compression> <cache_dir><![CDATA[]]></cache_dir> <hashed_directory_level><![CDATA[]]></hashed_directory_level> <hashed_directory_umask><![CDATA[]]></hashed_directory_umask> <file_name_prefix><![CDATA[]]></file_name_prefix> </memcached> </full_page_cache> </global> </config>

No comments:

Post a Comment