Skip to content

Instantly share code, notes, and snippets.

View jreinke's full-sized avatar

Johann Reinké jreinke

  • Freelance
  • France
View GitHub Profile
@jreinke
jreinke / unused.php
Created April 7, 2014 15:55
Magento: find potential unused product attributes
<?php
/**
* MAGENTO_ROOT_DIR/unused.php
* php -f unused.php
*/
$mageFilename = 'app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
@jreinke
jreinke / AbstractEntity.php
Last active August 29, 2015 13:57
Symfony2 Abstract Entity
<?php
namespace Clever\BlogBundle\Entity;
use Doctrine\Common\Util;
abstract class AbstractEntity
{
public function __construct($data = array())
{
@jreinke
jreinke / di.xml
Last active December 29, 2015 08:29
Testing a simple Magento 2 module installation
<?xml version="1.0"?>
<!-- app/code/Namespace/Test/etc/di.xml -->
<config>
<type name="Magento\Module\Updater\SetupFactory">
<param name="resourceTypes">
<value>
<test_setup>Magento\Core\Model\Resource\Setup</test_setup>
</value>
</param>
</type>
@jreinke
jreinke / gist:6508802
Created September 10, 2013 12:36
Magento: get attribute id by code
<?php
$attributeId = Mage::getResourceModel('eav/entity_attribute')
->getIdByCode('catalog_product', 'color');
@jreinke
jreinke / .htaccess
Created April 29, 2013 21:19
gzip static files when mod_gzip is not available
<Files *.js.gz>
AddType "text/javascript" .gz
AddEncoding gzip .gz
</Files>
<Files *.css.gz>
AddType "text/css" .gz
AddEncoding gzip .gz
</Files>
# Check to see if browser can accept gzip files.
@jreinke
jreinke / Collection.php
Last active December 16, 2015 02:39
Workaround when filters don't appear anymore on left column with the elasticsearch module for Magento.
<?php
// app/code/community/JR/Search/Model/Resource/Catalog/Product/Collection.php
// Making an override would be better!
protected function _getParams()
{
$store = Mage::app()->getStore($this->getStoreId());
$params = array();
$params['locale_code'] = $store->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE);
$params['filters'] = $this->_searchQueryFilters;
@jreinke
jreinke / Group.php
Last active December 15, 2015 09:19
Bubble Launcher custom indexer example (customer groups indexation)
<?php
// app/code/local/Namespace/Module/Model/Indexer/Group.php
class Namespace_Module_Model_Indexer_Group extends Bubble_Launcher_Model_Indexer_Abstract
{
protected function _buildIndexData()
{
$data = array();
$collection = Mage::getModel('customer/group')->getCollection();
@jreinke
jreinke / generate.php
Created August 14, 2012 14:45
Default password encoding in Silex micro-framework
<?php
use Symfony\Component\Security\Core\Encoder\MessageDigestPasswordEncoder;
$encoder = new MessageDigestPasswordEncoder();
echo $encoder->encodePassword('foo', '');
// 5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg==
@jreinke
jreinke / mysql4-install-0.1.0.php
Created January 25, 2012 20:12
Example of how to add attribute to customer entity type in Magento
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'civility', array(
'label' => 'Civility',
'visible' => true,
'required' => false,
'type' => 'int',
'input' => 'select',
'user_defined' => '1',