Skip to content

Instantly share code, notes, and snippets.

Peter Jaap Blaakmeer peterjaap

Block or report user

Report or block peterjaap

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@peterjaap
peterjaap / soldprod.php
Created Dec 3, 2012
Sold products % by category
View soldprod.php
<?php
require_once("app/Mage.php");
Mage::app();
$orders = Mage::getModel('sales/order')->getCollection();
$i = 0;
foreach ($orders as $key => $order) {
if (!$i) {
$startDate = strtotime($order->getCreatedAt());
@peterjaap
peterjaap / quickmodman
Created Jan 16, 2013
Quickly generate modman file for Magento extensions
View quickmodman
for i in `find . -type f | grep -v \.git | grep -v "^.$" | grep -v "modman" | sed 's/\.\///'`; do echo ${i} ${i}; done > modman
@peterjaap
peterjaap / search_autofocus.js
Last active Dec 14, 2015
Prototype javascript thingy to autofocus on search element on typing (ignoring navigational keys) and setting the search box as the first tab index
View search_autofocus.js
Event.observe(window,'load',function() {
$('search').tabIndex = 1;
$(document).observe('keyup', function(e) {
var navKeys = new Array(Event.KEY_BACKSPACE,Event.KEY_TAB,Event.KEY_RETURN,Event.KEY_ESC,Event.KEY_LEFT,Event.KEY_UP,Event.KEY_RIGHT,Event.KEY_DOWN,Event.KEY_DELETE,Event.KEY_HOME,Event.KEY_END,Event.KEY_PAGEUP,Event.KEY_PAGEDOWN,Event.KEY_INSERT);
if(Event.element(e) == document.body) {
if(navKeys.indexOf(e.keyCode)==-1){
$('search').focus();
$('search').value = String.fromCharCode(e.keyCode).toLowerCase();
}
}
@peterjaap
peterjaap / betterforgotpassword.js
Last active Dec 14, 2015
This little snippet improves the 'forgot password' workflow in a Magento shop by adding a button (after a failed login attempt) that directly posts the email address to the forgot password action ----------- Idea inspired by http://www.alasdairmonk.com/journal/improving-the-forgotten-password-process/
View betterforgotpassword.js
Event.observe(window, "load", function(){
if(document.location.href.indexOf('customer/account/login')>0 && $$('ul.messages li.error-msg ul li span').length>0) { // check for login page and actual error message
$('pass').addClassName('validation-failed').focus(); // add red dotted lining & set focus to the password field
$('pass').insert({after: '<div class="validation-advice" id="advice-required-entry-pass" style="">Your password is incorrect.</div>'}); // add an error message below the password field
$$('div.buttons-set > a').first().remove(); // remove the Forgot Password link
$$('ul.messages li.error-msg ul li span').first().innerHTML+=' <a href="javascript:newPasswordSubmit()">Click here to reset your password</a>'; // add an actionable link to the error message
$('send2').insert({after: '<button type="button" class="button" title="Reset my password" name="send" id="forgotpass" onclick="newPasswordSubmit()"><span><span>Reset my password</span></span></button>'}
@peterjaap
peterjaap / navicat_tunnel.php
Created Mar 13, 2013
Navicat tunnel file (the nearly unfindable ntunnel_mysql.php)
View navicat_tunnel.php
<?php //version my104
header("Content-Type: application/octet-stream");
error_reporting(0);
set_time_limit(0);
set_magic_quotes_runtime(0);
function phpversion_int()
{
list($maVer, $miVer, $edVer) = split("[/.-]", phpversion());
@peterjaap
peterjaap / FixConsole.xml
Last active Jul 16, 2017 — forked from astorm/gist:992233
Fix Magento console in Chrome
View FixConsole.xml
<!-- Add to the package layout (via local.xml or however you prefer) -->
<!-- Also, best to remove before deployment, as some users report -->
<!-- it makes IE 7 crash -->
<default>
<reference name="content">
<block type="core/text" name="fix.console" as="fix.console">
<action method="setText">
<text><![CDATA[<script type="text/javascript">
iframe = document.createElement('iframe');
iframe.style.display = 'none';
@peterjaap
peterjaap / createAdminUser.php
Created Apr 24, 2013
PHP script to create admin user for Magento
View createAdminUser.php
<?php
error_reporting(E_ALL | E_STRICT);
require_once 'app/Mage.php';
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$username = 'peterjaap';//desired username
@peterjaap
peterjaap / Notifier.php
Last active Dec 17, 2015
Notifier class for Raspberry notifications. Replace values on line 13, 34, 35, 46, 47, 108, 117 and 118 to your context. Current values line 46 and 47 are defaults for Ziggo modems (Dutch ISP). You'll also need: - A Raspberry Pi ;-) - Simple HTML DOM class; http://simplehtmldom.sourceforge.net/ - Pushover account (http://www.pushover.net) - Push…
View Notifier.php
<?php
chdir(dirname(__FILE__));
class Notifier {
public function __construct() {
require_once 'simple_html_dom.php';
}
@peterjaap
peterjaap / cleanImages.php
Last active Jan 11, 2019
Script to clean up the images tables in a Magento installation. Removes references to non-existing images, removes duplicate images, sets correct default image and deletes orphaned images from the filesystem.
View cleanImages.php
<?php
/*
* This script deletes duplicate images and imagerows from the database of which the images are not present in the filesystem.
* It also removes images that are exact copies of another image for the same product.
* And lastly, it looks for images that are on the filesystem but not in the database (orphaned images).
*
* This script can most likely be optimized but since it'll probably only be run a few times, I can't be bothered.
*
* Place scripts in a folder named 'scripts' (or similar) in the Magento root.
View create_website_scope.php
<?php
// Base-name
$name = 'foobar';
// Init Magento
require_once 'app/Mage.php';
Mage::app();
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
// Create the root catalog
You can’t perform that action at this time.