Skip to content

Instantly share code, notes, and snippets.

View Schrank's full-sized avatar

Fabian Blechschmidt Schrank

View GitHub Profile
@Schrank
Schrank / UserProvider.php
Created June 26, 2011 14:55
Implement UserProvider in Symfony2
<?php
namespace MyApp\MyBundle\DependencyInjection;
use Symfony\Component\Security\Core\User\User;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
class UserProvider implements UserProviderInterface {
@Schrank
Schrank / InformationContainer.php
Created June 26, 2011 15:17
Simple implementation of a Registry
<?php
namespace MyApp\MyBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\Config\FileLocator;
class InformationContainer {
@Schrank
Schrank / Controller.php
Created September 16, 2011 14:15
fetch frontendtemplates in magento backend
<?php
// maybe it is too much, but it works :-)
$design = Mage::getSingleton('core/design_package');
$design->setArea(Mage_Core_Model_Design_Package::DEFAULT_AREA)
->setTheme(
array(
'layout' => Mage_Core_Model_Design_Package::DEFAULT_THEME,
'template' => Mage_Core_Model_Design_Package::DEFAULT_THEME,
'skin' => Mage_Core_Model_Design_Package::DEFAULT_THEME,
'locale' => Mage_Core_Model_Design_Package::DEFAULT_THEME
@Schrank
Schrank / index.php
Created March 26, 2012 11:42
This script imports the ticket-entries from tickspot, changes the format to the TimeLog-XML-format (which GrandTotal can read) and prints it out.
<?php
/**
* This script imports the ticket-entries from tickspot, changes the format to the TimeLog-XML-format
* (which GrandTotal can read) and prints it out.
*
* Tickspot only saves hours, so the day starts at 9:30 and the entries are concatenated. No rest between
* or something.
*
* If this code is useful for you, use it! If you earn money with it, and you want to say thank you:
* https://flattr.com/thing/424316/Fabianikono-on-Twitter
@Schrank
Schrank / class.php
Created March 27, 2012 16:05
Stop Indexing in Magento
<?php
class Klasse {
public static function switchIndexingOff() {
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');
}
public static function rebuildIndices() {
$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
@Schrank
Schrank / Builder.php
Created September 15, 2012 15:47 — forked from mrflory/Builder.php
Twitter Bootstrap Twig Template for KnpMenuBundle in Symfony2
<?php
namespace Linkofy\CommonBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class Builder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
@Schrank
Schrank / code.php
Created February 19, 2013 16:17
Save a product from the frontend
<?php
// save the old id
$oldStoreId = Mage::app()->getStore()->getId();
// set the store to be admin
Mage::app()->getStore()->setId(Mage_Core_Model_App::ADMIN_STORE_ID);
// set the orig data
$product->setOrigData();
// save the product
$product->save();
// reset the store id
@Schrank
Schrank / Observer.php
Created February 20, 2013 18:23
Check wether a collection should load an attribute
<?php
class Observer {
protected function _collectionShouldLoadWidthAndHeight(Mage_Catalog_Model_Resource_Product_Collection $collection)
{
$reflection = new ReflectionProperty($collection, '_selectAttributes');
$reflection->setAccessible(true);
$value = $reflection->getValue($collection);
return array_key_exists('original_height', $value) || array_key_exists('original_width', $value);
}
}
@Schrank
Schrank / gist:7566494
Created November 20, 2013 16:43
Change Attribute for all simple products associated to a configurable
UPDATE
catalog_product_entity_int
SET
value = 1 -- new value
WHERE
attribute_id = 85 AND -- attribute_id you want to change
entity_id IN (
SELECT DISTINCT product_id FROM catalog_product_super_link
);
@Schrank
Schrank / umlauf.php
Created February 19, 2014 19:41
Alle Piratenpartei Umlaufbeschlüsse ziehen und in PDF umwandeln
<?php
namespace MyNamespaceForFunctions;
use FPDF;
require_once 'fpdf.php';
error_reporting(E_ALL);
ini_set('display_errors', 1);
function utf8_decode($string)
{