Skip to content

Instantly share code, notes, and snippets.

View brankoajzele's full-sized avatar

Branko Ajzele brankoajzele

View GitHub Profile
@brankoajzele
brankoajzele / gist:1430081
Created December 4, 2011 12:29
Inchoo_Phonebook Magento Test Extension: app/etc/modules/Inchoo_Phonebook.xml
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_Phonebook>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Core />
<Mage_Eav />
@brankoajzele
brankoajzele / gist:1430085
Created December 4, 2011 12:31
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Inchoo_Phonebook>
<version>1.0.0.0</version>
</Inchoo_Phonebook>
</modules>
<global>
<models>
@brankoajzele
brankoajzele / gist:1430086
Created December 4, 2011 12:32
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/Model/User.php
<?php
class Inchoo_Phonebook_Model_User extends Mage_Core_Model_Abstract
{
/**
* Maps to the array key from Setup.php::getDefaultEntities()
*/
const ENTITY = 'inchoo_phonebook_user';
protected $_eventPrefix = 'inchoo_phonebook';
@brankoajzele
brankoajzele / gist:1430090
Created December 4, 2011 12:33
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/Model/Resource/User.php
<?php
class Inchoo_Phonebook_Model_Resource_User extends Mage_Eav_Model_Entity_Abstract
{
public function __construct()
{
$resource = Mage::getSingleton('core/resource');
$this->setType(Inchoo_Phonebook_Model_User::ENTITY);
@brankoajzele
brankoajzele / gist:1430091
Created December 4, 2011 12:34
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/Model/Resource/User/Collection.php
<?php
class Inchoo_Phonebook_Model_Resource_User_Collection extends Mage_Eav_Model_Entity_Collection_Abstract
{
protected function _construct()
{
$this->_init('inchoo_phonebook/user');
}
protected function _initSelect()
@brankoajzele
brankoajzele / gist:1430096
Created December 4, 2011 12:35
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/Model/Resource/Setup.php
<?php
class Inchoo_Phonebook_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup {
public function getDefaultEntities() {
return array(
Inchoo_Phonebook_Model_User::ENTITY => array(
'entity_model' => 'inchoo_phonebook/user',
'table' => 'inchoo_phonebook/user', /* Maps to the config.xml > global > models > inchoo_phonebook_resource > entities > user */
'attributes' => array(
@brankoajzele
brankoajzele / gist:1430098
Created December 4, 2011 12:35
Inchoo_Phonebook Magento Test Extension: app/code/local/Inchoo/Phonebook/sql/inchoo_phonebook_setup/install-1.0.0.0.php
<?php
/* @var $installer Inchoo_Phonebook_Model_Resource_Setup */
$installer = $this;
$installer->startSetup();
/* Create table 'inchoo_phonebook/user' */
$table = $installer->getConnection()
->newTable($installer->getTable('inchoo_phonebook/user'))
@brankoajzele
brankoajzele / gist:1430101
Created December 4, 2011 12:37
Inchoo_Phonebook Magento Test Extension: Test the extension EAV model & collection
<?php
$phonebookUser = Mage::getModel('inchoo_phonebook/user');
$phonebookUser->setFristname('John');
$phonebookUser->setLastname('Doe');
$phonebookUser->setEmail('john.doe@magento.com');
$phonebookUser->setAddress('Sample address line here');
$phonebookUser->setIsActive(true);
@brankoajzele
brankoajzele / gist:1442434
Created December 7, 2011 11:12
Magento Google Maps Geocoding Customer Addresses
<?php
/**
* @author Branko Ajzele <ajzele@gmail.com>
*/
class Inchoo_Extension_Helper_Gmap extends Mage_Core_Helper_Abstract
{
const GOOGLE_MAPS_HOST = 'maps.google.com';
const CONFIG_PATH_GOOGLE_MAPS_API_KEY = 'inchoo_google/maps/api_key';
public function getGoogleMapsApiKey()
@brankoajzele
brankoajzele / gist:1453027
Created December 9, 2011 19:55
Truncate all sales related tables in Magento in a "Multi Database Support" way
<?php
/**
* @author Branko Ajzele <ajzele@gmail.com>
*/
if (version_compare(phpversion(), '5.2.0', '<')===true) {
echo '<div style="font:12px/1.35em arial, helvetica, sans-serif;"><div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;"><h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer. <a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a> Magento using PHP-CGI as a work-around.</p></div>';
exit;
}