Skip to content

Instantly share code, notes, and snippets.

@herveguetin
herveguetin / magentoObserverArgs.php
Created Aug 10, 2012
Pass arguments to observer method using <args> node in Magento's observer design pattern
View magentoObserverArgs.php
<?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 Oct 24, 2019
Magento .gitignore example
View .gitignore_magento
######################
# Magento .gitignore #
######################
# Magento Core unnecessary files #
##################################
/errors/local.xml
/index.php
/install.php
/mage
@herveguetin
herveguetin / breadcrumbs_history_back_button.phtml
Last active Dec 24, 2015
Avoid displaying history back if referrer is from different domain
View breadcrumbs_history_back_button.phtml
<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 Dec 25, 2015
Update Magento's single attribute option value
View catalog_attribute_option_value_update.php
<?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
Add custom or CMS-page-title-based translated breadcrumbs with simple layout update in Magento
View breadcrumb_custom_helper.php
<?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 May 14, 2017
Use renderers for shipping methods in Magento
View shipping_method_renderer_available.phtml
<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 Aug 29, 2015
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)
View flat_source_table_select_varchar.php
<?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 Aug 29, 2015 — forked from leek/README.md
Clean Magento Database
View clean_catalogsearch.sql
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 Aug 29, 2015
Remove coupon code in parenthesis from discount total title in Magento
View checkout_total_discount_no_code.phtml
<?php
$title = ($this->getTotal()->getCode() == 'discount') ? preg_replace('@\(.*?\)@', '', $this->getTotal()->getTitle()) : $this->getTotal()->getTitle();
?>
@herveguetin
herveguetin / autoshipping.php
Last active Oct 17, 2017
Set shipping method and rate if they do not exist yet in Magento
View autoshipping.php
<?php
/**
* Has shipping been applied to quote?
*
* @var bool
*/
protected $_hasShipping = false;
/**
You can’t perform that action at this time.