Skip to content

Instantly share code, notes, and snippets.

View aleron75's full-sized avatar

Alessandro Ronchi aleron75

View GitHub Profile
@aleron75
aleron75 / gitlog.sh
Created June 30, 2015 07:33
Decorated git log
#!/bin/bash
git log --graph --decorate --pretty=oneline --abbrev-commit
@aleron75
aleron75 / privateaccess.php
Created June 19, 2015 07:56
POC that PHP doesn't allow calling private methods from inherited context
<?php
class MyParent
{
public function includeFile()
{
include "privateaccess_included.php";
}
}
class MyChild extends MyParent
@aleron75
aleron75 / Data.php
Created June 16, 2015 09:09
Magento Compare Version
<?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', '>');
}
@aleron75
aleron75 / load_media_gallery
Created May 19, 2015 10:26
Load Magento product media gallery
@aleron75
aleron75 / log.php
Last active August 29, 2015 14:18
Magento log wrapper function
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'));
}
@aleron75
aleron75 / shell_delete_unused_images
Last active October 24, 2023 19:59
Delete no more used Product Images on Magento 1
<?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)
@aleron75
aleron75 / collection_copy
Created February 20, 2015 08:42
Copy a Magento collection
$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,
@aleron75
aleron75 / beforesave
Created December 4, 2014 11:02
_beforeSave() on Magento Models
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();
}
@aleron75
aleron75 / rt_admin
Last active August 23, 2019 00:41
Magento runtime for Administrator
<?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);
@aleron75
aleron75 / rt_customer
Last active August 23, 2019 00:41
Magento runtime for 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);