Instantly share code, notes, and snippets.

View privateaccess.php
<?php
class MyParent
{
public function includeFile()
{
include "privateaccess_included.php";
}
}
class MyChild extends MyParent
View Data.php
<?php
class Myvendor_Mymodule_Helper_Data extends Mage_Core_Helper_Data
{
/**
* Check whether current Magento version supports Transactions
*/
public function isTransactionSupported()
{
return version_compare(Mage::getVersion(), '1.4.0.1', '>');
}
View load_media_gallery
View log.php
public function log()
{
$args = func_get_args();
$formattedMsg = call_user_func_array('sprintf', $args);
Mage::log($formattedMsg, null, 'vendor_module.log', Mage::getStoreConfig('path/to/config'));
}
View shell_delete_unused_images
<?php
require_once 'abstract.php';
class Mage_Shell_CheckImages extends Mage_Shell_Abstract
{
const CATALOG_PRODUCT = '/catalog/product';
const CACHE = '/cache/';
protected function _glob_recursive($pattern, $flags = 0)
View collection_copy
$originalCollection = Mage::getModel('catalog/product')
->getCollection();
$newCollection = Mage::getModel('catalog/product')
->getCollection();
$selectParts = array(
Varien_Db_Select::DISTINCT,
Varien_Db_Select::COLUMNS,
Varien_Db_Select::UNION,
View beforesave
protected function _beforeSave()
{
$this->setUpdatedAt(Mage::getSingleton('core/date')->gmtDate());
if ($this->isObjectNew() && null === $this->getCreatedAt()) {
$this->setCreatedAt(Mage::getSingleton('core/date')->gmtDate());
}
return parent::_beforeSave();
}
View rt_admin
<?php
// Prevent this script to be called via HTTP
if (isset($_SERVER['REQUEST_METHOD']))
{
die('Permission denied.');
}
// Avoid any time limit
set_time_limit(0);
View rt_customer
<?php
// Prevent this script to be called via HTTP
if (isset($_SERVER['REQUEST_METHOD']))
{
die('Permission denied.');
}
// Avoid any time limit
set_time_limit(0);
View Create.php
// This snippet from line 267 of class Mage_Adminhtml_Model_Sales_Order_Create of Magento CE 1.8.x or EE 1.13.x
public function initFromOrder(Mage_Sales_Model_Order $order)
{
// ...
$this->getQuote()->getPayment()->addData($order->getPayment()->getData()); // line 329
// ...
$this->getQuote()->save();
return $this;
}