Magento IMP 8


Resizing via Varien_Image

$image = new Varien_Image('/full/fs/path/to/image.jpg'); // you cannot use method chaining with Varien_Image $image->constrainOnly(false); $image->keepFrame(true); // avoid black borders by setting background colour $image->backgroundColor(array(255,255,255)); $image->keepAspectRatio(true); $image->resize(216, 139); $image->save('/full/fs/path/to/save/to.jpg');

Table Creation In Magento 1.6/1.11+

Magento CE 1.6 and PE/EE 1.11 introduced database abstraction, this is the way to set up tables using the new code.
// @var $installer Mage_Core_Model_Resource_Setup $installer = $this; $installer->startSetup(); $table = $installer->getConnection() ->newTable($installer->getTable('your_module/table_name_in_xml')) ->addColumn( 'entity_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( 'identity' => true, 'unsigned' => true, 'nullable' => false, 'primary' => true, ), 'Entity ID' ) ->addColumn( 'category_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array( 'unsigned' => true, 'nullable' => false, ), 'Category ID' ) ->addIndex( $installer->getIdxName( 'your_module/table_name_in_xml', array('category_id') ), array('category_id') ) ->addForeignKey( $installer->getFkName( 'your_module/table_name_in_xml', 'category_id', 'catalog/category', 'entity_id' ), 'category_id', $installer->getTable('catalog/category'), 'entity_id', Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_CASCADE ) ->setComment('Some table which links to categories'); $installer->getConnection()->createTable($table);

Config Model & Resource Model Definition

<config> <global> <models> <namespace_module> <class>Namespace_Module_Model</class> <resourceModel>namespace_module_resource</resourceModel> </namespace_module> <namespace_module_resource> <class>Namespace_Module_Model_Resource</class> <entities> <some_entity> <table>namespace_module_some_entity</table> </some_entity> </entities> </namespace_module_resource> </models> </global> </config>

Config Setup Definition (EAV & Flat)

EAV:
<config> <global> <resources> <namespace_module_setup> <setup> <module>Namespace_Module</module> <class>Mage_Eav_Model_Entity_Setup</class> </setup> </namespace_module_setup> </resources> </global> </config>
Flat:
<config> <global> <resources> <namespace_module_setup> <setup> <module>Namespace_Module</module> <class>Mage_Core_Model_Resource_Setup</class> </setup> </namespace_module_setup> </resources> </global> </config>

Config Block Definition

<config> <global> <blocks> <namespace_module> <class>Namespace_Module_Block</class> </namespace_module> </blocks> </global> </config>

Config Event Observer Definition (Frontend, Admin & Global)

Frontend:
<config> <frontend> <events> <the_name_of_the_event_to_observe> <observers> <namespace_module> <class>namespace_module/observer</class> <method>someMethod</method> </namespace_module> </observers> </the_name_of_the_event_to_observe> </events> </frontend> </config>
Admin:
<config> <adminhtml> <events> <the_name_of_the_event_to_observe> <observers> <namespace_module> <class>namespace_module/observer</class> <method>someMethod</method> </namespace_module> </observers> </the_name_of_the_event_to_observe> </events> </adminhtml> </config>
Global (before area has been initialized):
<config> <global> <events> <the_name_of_the_event_to_observe> <observers> <namespace_module> <class>namespace_module/observer</class> <method>someMethod</method> </namespace_module> </observers> </the_name_of_the_event_to_observe> </events> </global> </config>

Config Cronjob Definition

<config> <crontab> <jobs> <cron_job_name> <schedule> <cron_expr>* * * * *</cron_expr> </schedule> <run> <model>your_module/model::batchTransactions</model> </run> </cron_job_name> </jobs> </crontab> </config>

Config Layout Definition (Frontend & Admin)

Frontend:
<config> <frontend> <layout> <updates> <namespace_module> <file>namespace-module.xml</file> </namespace_module> </updates> </layout> </frontend> </config>
Admin:
<config> <adminhtml> <layout> <updates> <namespace_module> <file>namespace-module.xml</file> </namespace_module> </updates> </layout> </adminhtml> </config>

Config Controller Definition (Frontend & Admin)

Frontend With Route:
<config> <frontend> <routers> <namespace_module> <use>standard</use> <args> <module>Namespace_Module</module> <frontName>whatever</frontName> <!-- http://dev.local/whatever/*/* --> </args> </namespace_module> </routers> </frontend> </config>
Frontend Injected (Sales given as an example):
<config> <frontend> <routers> <sales> <args> <modules> <Namespace_Module before="Mage_Sales">Namespace_Module</Namespace_Module> <!-- http://dev.local/sales/*/* --> </modules> </args> </sales> </routers> </frontend> </config>
Admin:
<config> <admin> <routers> <adminhtml> <args> <modules> <Namespace_Module before="Mage_Adminhtml">Namespace_Module_Adminhtml</Namespace_Module> <!-- http://dev.local/admin/*/* --> </modules> </args> </adminhtml> </routers> </admin> </config>

Boilerplate Block Class

With template support:
/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Something block * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Block_Something extends Mage_Core_Block_Template { }
Without template support:
/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Something block * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Block_Something extends Mage_Core_Block_Abstract { }

Boilerplate Helper Class

/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Module translation helper * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract { }

Boilerplate Model Class

/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Something model * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Model_Something extends Mage_Core_Model_Abstract { /** * Initialize resource (links resource model) * * @return void */ protected function _construct() { $this->_init('namespace_module/something'); } }

Boilerplate Resource Model Class (1.6/1.11+)

/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Something resource model * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Model_Resource_Something extends Mage_Core_Model_Resource_Db_Abstract { /** * Link domain model and set primary key * * @return void */ protected function _construct() { $this->_init( 'namespace_module/something', # model class name 'entity_id' # table primary key ); } }

Boilerplate Resource Model Collection Class (1.6/1.11+)

/** * Yourcompany.com * * PHP Version 5 * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @copyright 2012 yourcompany.com * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ /** * Something resource collection model * * @category Namespace * @package Namespace_Module * @author Your Name <your.name@yourcompany.com> * @license http://www.yourcompany.com/license.txt Your license * @link N/A */ class Namespace_Module_Model_Resource_Something_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract { /** * Link domain model * * @return void */ protected function _construct() { $this->_init('namespace_module/something'); } }

No comments:

Post a Comment