Skip to content

Instantly share code, notes, and snippets.

View peterjaap's full-sized avatar

Peter Jaap Blaakmeer peterjaap

  • elgentos ecommerce solutions / Blaakmeer Webdevelopment
  • Groningen, the Netherlands
View GitHub Profile
@peterjaap
peterjaap / soldprod.php
Created December 3, 2012 12:12
Sold products % by category
<?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 January 16, 2013 10:52
Quickly generate modman file for Magento extensions
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 December 14, 2015 18:19
Prototype javascript thingy to autofocus on search element on typing (ignoring navigational keys) and setting the search box as the first tab index
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 December 14, 2015 19:28
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/
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 March 13, 2013 12:28
Navicat tunnel file (the nearly unfindable ntunnel_mysql.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 July 16, 2017 09:45 — forked from astorm/gist:992233
Fix Magento console in Chrome
<!-- 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 April 24, 2013 08:12
PHP script to create admin user for Magento
<?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 December 17, 2015 03:28
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…
<?php
chdir(dirname(__FILE__));
class Notifier {
public function __construct() {
require_once 'simple_html_dom.php';
}
@peterjaap
peterjaap / cleanImages.php
Last active February 14, 2024 14:17
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.
<?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.
<?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