Skip to content

Instantly share code, notes, and snippets.

View SchumacherFM's full-sized avatar

Cyrill Schumacher SchumacherFM

View GitHub Profile
@SchumacherFM
SchumacherFM / switch.php
Created October 10, 2013 04:30
The always nice and awesome and total cool Switch Statements :-(
<?php
/**
* Returns a PDO parameter constant to bind a variable with
*
* @param string $type Which variable type to check
*
* @return int PDO parameter constant
*/
public static function getBindConstant($type)
@SchumacherFM
SchumacherFM / Renderer.php
Last active February 18, 2018 17:50
Love it! ;-) Best practice switch/case statement in PHP. Magento 3rd party module. #fail
<?php
switch ($templateOption->getType()) {
case "select":
$block = "painModule/select";
$template = "painModule/type/select.phtml";
break;
case "radiobuttons":
$block = "painModule/radiobuttons";
$template = "painModule/type/radiobuttons.phtml";
break;
@SchumacherFM
SchumacherFM / Magento-HHVM.md
Last active May 17, 2018 18:26
Running Magento Enterprise Edition with Facebook HipHop HHVM

Running Magento Enterprise Edition with Facebook HipHop HHVM

Prerequisites

Hardware

MacBook Air (MBA) Mid 2012

@SchumacherFM
SchumacherFM / copy-store-view.sql
Created June 6, 2013 14:48
Magento - Copy Store Views / Some tables are still missing
-- idea: rebuild this via php and use mysql.information_schema to automatically figure out tables with column store_id resp. website_id
-- maybe include it into n98-magerun
# DEFINE
SET @to_store := 8;
SET @to_website := 4;
SET @from_store := 2;
SET @from_website := 3;
@SchumacherFM
SchumacherFM / gist:5371312
Created April 12, 2013 11:12
Magento Truncate Quote and Orders
SET foreign_key_checks = 0;
TRUNCATE `log_quote`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
@SchumacherFM
SchumacherFM / mysql4-upgrade-0.0.x-0.0.y.php
Last active December 15, 2015 11:59
Magento: Want to use negative position values in Category Product Relation? Just include this MySQL update routine and rerun the indexer for catalog_category_product. Problem: Table catalog_category_product with its column position is type signed while the column position in the indexers anchor idx and tmp table are unsigned. Unsigned columns ca…
<?php
/**
* @var $installer Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
*/
$installer = $this;
$installer->startSetup();
$tables = array(
$installer->getTable('catalog/category_anchor_products_indexer_idx'),
$installer->getTable('catalog/category_anchor_products_indexer_tmp')
);
@SchumacherFM
SchumacherFM / FormatPrice.php
Created January 24, 2013 12:31
Magento: reformat the price system wide for any locale to a consistent format width the event currency_display_options_forming
<?php
class Namespace_Module_Model_Observer_FormatPrice
{
public function formatPrice(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$options = $event->getCurrencyOptions();
/**
@SchumacherFM
SchumacherFM / Attribute2.php
Created January 11, 2013 16:45
Magento (CE1.7) Catalog Category Layer Filter: Filtering for the attribute gender. Adding a second value to this attribute for the filter query. In this example we add the unisex value to the query when someone searches for a product which gender attribute is lady or gentlemen.
<?php
/**
* XML rewrite:
*
* <config><global><models>
<catalog_resource>
<rewrite>
<layer_filter_attribute>Namespace_Module_Model_Resource_Layer_Filter_Attribute</layer_filter_attribute>
</rewrite>
</catalog_resource>
@SchumacherFM
SchumacherFM / Related.php
Created December 14, 2012 14:02
Magento: Extended Version of the related products in the community edition / Get a product collection and filter by a multiselect field with another multiselect field. sto_artsc3_line is the multiselect field, type varchar. FIND_IN_SET() handles the magic in MySQL. If anybody knows a better solution, post it here :-)
@SchumacherFM
SchumacherFM / Namespace_Module_Block_Adminhtml_Edit_Tab_XXXX.php
Created December 4, 2012 08:41
Magento backend admin: Edit form with a multiselect field with product categories
<?php
/* Set up: */
class Namespace_Module_Block_Adminhtml_News_Edit_Tab_Linking {
protected function _prepareForm(){
...
$fieldSet->addField('product_categories', 'multiselect',