Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / shipping_method_title.php
Created July 31, 2014 13:02
Oneliner to retrieve shipping method *title* in Magento
Mage::getStoreConfig('carriers/' . $order->getShippingMethod(true)->getCarrierCode() . '/title')
@herveguetin
herveguetin / sanitize_zip_fr.js
Created August 7, 2014 16:35
Sanitize and validate ZIP codes in Magento using Prototype's Validation
/**
* A simple ZIP code validator and sanitizer
*
* @author Hervé Guétin <@herveguetin> <herve.guetin@agence-soon.fr>
*/
var zipSanitizer = {
// All sanitizers available
sanitizers: {},
@herveguetin
herveguetin / varnish_bypass.js
Last active August 29, 2015 14:08
Create varnish_bypass cookie for Turpentine on Magento
document.cookie="varnish_bypass=1"
@herveguetin
herveguetin / Reset Magento permissions
Created November 20, 2014 18:18
Reset Magento permissions
find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \; && chmod 550 mage
@herveguetin
herveguetin / enterprise_category_url_key.php
Created November 24, 2014 12:58
When using Magento EE, and especially when flat category is active, requesting the "url_key" attribute for a category fails because it is not populated in catalog_category_flat_store_*. This method fixes that.
<?php
/**
* Get category URL key for Enterprise
*
* @param Mage_Catalog_Model_Category $category
* @return string
*/
public function getEnterpriseUrlKey(Mage_Catalog_Model_Category $category)
{
$resource = Mage::getSingleton('core/resource');
@herveguetin
herveguetin / htaccess_avoid_robots_indexing.sh
Last active August 29, 2015 14:15
.htaccess lines to avoid robots indexing
# Make sure mod_headers is enabled in Apache
sudo a2enmod headers
# Place this in .htaccess
<IfModule mod_headers.c>
Header set X-Robots-Tag "noindex, nofollow"
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"
</IfModule>
@herveguetin
herveguetin / create_cms_block.php
Last active August 29, 2015 14:16
Create a CMS block programmatically in Magento
<?php
$content = <<<EOD
Block Content line 1
Block Content line 2
EOD;
$cmsBlock = Mage::getModel('cms/block')->addData(
array(
'title' => 'Block Title',
'identifier' => 'block_identifier',
@herveguetin
herveguetin / run_method.php
Created May 5, 2015 09:09
Call a Magento model / method from shell
#!/usr/bin/php -f
<?php
require_once 'abstract.php';
class Herve_Run_Method extends Mage_Shell_Abstract
{
protected function _parseArgs()
{
@herveguetin
herveguetin / wishlist_force_redirection_after_login_magento.php
Created October 27, 2015 14:24
In Magento, when adding a product to wishlist, force redirection to wishlist page after customer login
<?php
// 1. Observe the following event: controller_action_predispatch_wishlist_index_add which calls, for example, the `forceReferer()` method
// 2. In your observer class, implement the `forceReferer()` method
/**
* When adding a product to wishlist,
* force redirection to wishlist page after customer login
*
*/
public function forceReferer(Varien_Event_Observer $observer)
@herveguetin
herveguetin / kill_solr
Last active November 6, 2015 10:53
SolR basic snippets
lsof -i :8983
# and kill returned pid