Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / magentoObserverArgs.php
Created August 10, 2012 09:24
Pass arguments to observer method using <args> node in Magento's observer design pattern
<?php
class Namespace_Module_Helper_Data extends Mage_Core_Helper_Abstract {
/**
* Retrieve args node of observer config
*
* @param Varien_Event_Observer $observer
* @return array $observerArgs
*/
public function getObserverArgs(Varien_Event_Observer $observer, $callingClass, $callingMethod) {
@herveguetin
herveguetin / .gitignore_magento
Last active October 24, 2019 09:06
Magento .gitignore example
######################
# Magento .gitignore #
######################
# Magento Core unnecessary files #
##################################
/errors/local.xml
/index.php
/install.php
/mage
@herveguetin
herveguetin / breadcrumbs_history_back_button.phtml
Last active December 24, 2015 01:59
Avoid displaying history back if referrer is from different domain
<html>
<div id="breadcrumbs_back" style="display: none">
<button class="button" onclick="history.go(-1); return false"><span><span><?php echo $this->__('Back') ?></span></span></button>
</div>
<script type="text/javascript">
var breadcrumbs_back = $('breadcrumbs_back');
if(breadcrumbs_back) {
var referrer_host = document.referrer.split('/')[2];
var host = '<?php echo $_SERVER['HTTP_HOST'] ?>';
@herveguetin
herveguetin / catalog_attribute_option_value_update.php
Last active December 25, 2015 00:09
Update Magento's single attribute option value
<?php
/**
* Données à renseigner
*/
$attributeCode = 'pack_main_color'; // Le code de l'attribut dont on veut modifier les options
$optionId = 4; // option_id dont on veut modifier la valeur
$newValueForOption = 'Nouvelle valeur'; // La nouvelle valeur pour cette option_id
/**
@herveguetin
herveguetin / breadcrumb_custom_helper.php
Last active May 18, 2018 01:41
Add custom or CMS-page-title-based translated breadcrumbs with simple layout update in Magento
<?php
/**
* Retrieve current cms page
*
* @return Mage_Core_Model_Abstract
*/
public function getCurrentCmsPage()
{
$pageId = $this->_getRequest()->getParam('page_id', $this->_getRequest()->getParam('id', false));
$page = Mage::getSingleton('cms/page')->load($pageId);
@herveguetin
herveguetin / shipping_method_renderer_available.phtml
Last active August 8, 2023 08:38
Use renderers for shipping methods in Magento
<dl class="sp-methods">
<?php $shippingCodePrice = array(); ?>
<?php $_sole = count($_shippingRateGroups) == 1; foreach ($_shippingRateGroups as $code => $_rates): ?>
<?php echo Mage::helper('your_module/shipping')->getShippingRatesHtml($code, $_rates, $_sole); ?>
<?php endforeach; ?>
</dl>
@herveguetin
herveguetin / flat_source_table_select_varchar.php
Last active August 29, 2015 13:58
Save an attribute with a select input type with values that are not of "int" type and create correct column type in flat catalog tables (in Magento)
<?php
class Your_Module_Model_Catalog_Attribute_Source_Product_[Attribute] extends Mage_Eav_Model_Entity_Attribute_Source_Table
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = array(
'option_1' => array('value' => 'value_1', 'label' => Mage::helper('adminhtml')->__('-- Not Selected --')),
'option_2' => array('value' => 'value_2', 'label' => 'Label 2'),
@herveguetin
herveguetin / clean_catalogsearch.sql
Last active August 29, 2015 13:59 — forked from leek/_Magento1_DeleteTestData.md
Clean Magento Database
SET FOREIGN_KEY_CHECKS=0;
TRUNCATE `catalogsearch_fulltext`;
TRUNCATE `catalogsearch_query`;
TRUNCATE `catalogsearch_result`;
--
-- Enterprise Edition
--
@herveguetin
herveguetin / checkout_total_discount_no_code.phtml
Last active August 29, 2015 14:00
Remove coupon code in parenthesis from discount total title in Magento
<?php
$title = ($this->getTotal()->getCode() == 'discount') ? preg_replace('@\(.*?\)@', '', $this->getTotal()->getTitle()) : $this->getTotal()->getTitle();
?>
@herveguetin
herveguetin / autoshipping.php
Last active October 17, 2017 07:04
Set shipping method and rate if they do not exist yet in Magento
<?php
/**
* Has shipping been applied to quote?
*
* @var bool
*/
protected $_hasShipping = false;
/**