Skip to content

Instantly share code, notes, and snippets.

herveguetin / customer_group_massupdate_magento.php
Created Jun 12, 2015
Affect all Magento customers to a group
View customer_group_massupdate_magento.php
$customerGroupId = SOME_CUSTOMER_GROUP_ID;
$table = Mage::getModel('customer/customer')->getResource()
$query = "UPDATE {$table} SET group_id = {$customerGroupId} WHERE group_id != {$customerGroupId}";
herveguetin / create_group_prices_magento.php
Created Jun 10, 2015
Create/update group prices programmatically in Magento
View create_group_prices_magento.php
class Namespace_Module_Model_Price_Import extends Mage_Core_Model_Abstract
* DB Connection
* @var Varien_Db_Adapter_Interface
protected $_conn;
herveguetin / next_business_day.php
Last active Aug 26, 2017
Retrieve the next business or calendar day in Magento with an optional leadtime. Magento weekend days config is taken into account.
View next_business_day.php
* Retrieve the next business day with an optional leadtime.
* If leadtime = 1 => find the next business day
* If leadtime = 2 => find the "next next" business day
* etc...
* @param int $leadtime
* @return string|bool
herveguetin / run_method.php
Created May 5, 2015
Call a Magento model / method from shell
View run_method.php
#!/usr/bin/php -f
require_once 'abstract.php';
class Herve_Run_Method extends Mage_Shell_Abstract
protected function _parseArgs()
herveguetin / convert_string_to_url_key.php
Last active Nov 13, 2015
Transform any string to url-like string in Magento (useful for dynamic CSS classes for example)
View convert_string_to_url_key.php
$string = 'My String';
$urlKeyString = Mage::getSingleton('catalog/product')->formatUrlKey($string);
// Returns => my-string
herveguetin / cart_price_rule_1_steps.txt
Last active Jan 13, 2017
Programmatically create a cart price rule in Magento
View cart_price_rule_1_steps.txt
This is a quick an easy hack to programmatically create a cart price rule.
1. Temporarely edit Mage_Adminhtml_Promo_QuoteController::saveAction()
2. Around line 123, you will find $data = $this->getRequest()->getPost();
3. Below this line create a new line containing :
herveguetin / create_cms_block.php
Last active Aug 29, 2015
Create a CMS block programmatically in Magento
View create_cms_block.php
$content = <<<EOD
Block Content line 1
Block Content line 2
$cmsBlock = Mage::getModel('cms/block')->addData(
'title' => 'Block Title',
'identifier' => 'block_identifier',
herveguetin / Observer.php
Last active Apr 1, 2019
Dynamically add items to admin menu in Magento
View Observer.php
class My_Module_Model_Observer {
* Update admin menu with dynamic items
public function updateAdminMenu()
$menu = Mage::getSingleton('admin/config')->getAdminhtmlConfig()->getNode('menu/MAIN_MENU_ITEM/children/MENU_ITEMS_CONTAINER/children');
herveguetin /
Last active Aug 29, 2015
.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"
herveguetin /
Created Dec 9, 2014
Quick, easy and dirty cache warmer based on sitemap.xml
wget --quiet http://$URL/$SITEMAP --no-cache --output-document - | egrep -o "http://$URL[^<]+" | while read line; do
time curl -A 'Cache Warmer' -s -L $line > /dev/null 2>&1
echo $line
You can’t perform that action at this time.