Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / translate_specific_string_module.md
Created May 26, 2014 22:34
Translating strings from specific modules in Magento
@herveguetin
herveguetin / magento_collection_expression.php
Created May 26, 2014 22:49
Use mySQL expression in Magento collection select
<?php
Mage::getModel('my_model')
->getCollection()
->addAttributeToFilter('my_column', array('gt' => Zend_Db_Expr(MY_EXPRESSION)))
;
@herveguetin
herveguetin / canonical_url.php
Created May 26, 2014 22:54
Add canonical URL to Magento <head>
<?php
$canonicalUrl = Mage::getBaseUrl(); // your logic...
$this->getLayout()
->getBlock('head')
->addLinkRel('canonical', $canonicalUrl);
@herveguetin
herveguetin / form_own_model_data.php
Last active August 29, 2015 14:01
Enrich Magento product edit admin form with own model data
<?php
/**
* In some Mage_Adminhtml_Block_Catalog_Form class...
*/
protected function _prepareForm()
{
$formDataObject = new Varien_Object() // Your logic to get original data for your form
$form = new Varien_Data_Form();
@herveguetin
herveguetin / Mage_Core_Model_Email_Template.php
Created May 26, 2014 23:53
Bugfix in Mage_Core_Model_Email_Template
<php
/**
* Parse variables string into array of variables
*
* @param string $variablesString
* @return array
*/
protected function _parseVariablesString($variablesString)
{
$variables = array();
@herveguetin
herveguetin / sales_order_states.xml
Created June 4, 2014 15:05
Make Magento orders of a *state* (thus all attached statuses) visible / hidden on front
<!-- Update config node /config/global/sales/order/states like this: -->
<config>
<global>
<sales>
<order>
<states>
<[state_code]>
<!--
Available state_code are:
. new
@herveguetin
herveguetin / remove_SID_in_url.php
Created June 25, 2014 15:19
Avoid disgraceful SID params in Magento URLs
<?php
Mage::getSingleton('core/session')->setSkipSessionIdFlag(true);
// line below may also be needed
Mage::app()->setUseSessionInUrl(false);
?>
@herveguetin
herveguetin / freeshipping_remainder.php
Created July 16, 2014 16:51
A powerful and easy freeshipping remainder block for Magento based on shopping cart promo rules
<?php
/*
Just create as many shopping cart price rules that are elligible for free shipping
and this block class will use the most appropriate one to define:
- minimum amount to get freeshipping
- remaining amount to purchase to get freeshipping.
If no rule is elligible, the block falls back to a CMS block.
@herveguetin
herveguetin / upgrade_add_column.php
Created July 22, 2014 09:44
The right way to add a column to an existing table in Magento.
<?php
$installer = $this->startSetup();
$installer->getConnection()
->addColumn(
$installer->getTable('module/table_alias'),
'sql_column_name',
array(
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER, // Or any other type from Varien_Db_Ddl_Table
'nullable' => true, // Or false...
@herveguetin
herveguetin / remove_definer_mysqldump
Created July 23, 2014 10:26
Removing DEFINER from mysqldump
mysqldump … | sed -e 's/DEFINER=[^*]*\*/\*/' > dump.sql