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 / convertImages.sh
Last active May 11, 2020 08:28
Convert images to smaller size and lower quality to reduce file sizes for Magento's original product photos
#!/bin/bash
# convertImages.sh
# Author: Peter Jaap Blaakmeer (elgentos.nl)
# https://gist.github.com/peterjaap/7080989
NEWQUALITY=80
NEWSIZE=1000
DIRECTORY=media/catalog/product/
du -hs $DIRECTORY
@peterjaap
peterjaap / .bash_profile
Last active December 26, 2015 03:08
See which branch you are on immediately after entering a directory with a Git repository. Add this piece of code to your ~/.bash_profile file to run 'git branch' every time you enter a directory with a Git repository. You can comment out line 5 if you do not want to show the Magento version that is being used, if found.
function runOnFolderEntry() {
if [ "$PWD" != "$MYOLDPWD" ]; then
MYOLDPWD="$PWD";
showGitBranch ${MYOLDPWD};
showMagentoVersion ${MYOLDPWD};
fi
}
function showGitBranch() {
if [ -d "$1/.git" ]; then
@peterjaap
peterjaap / rowsizefix.sql
Last active December 26, 2015 14:39
Row size too large fix - replace ezbase% with your attribute code prefix
UPDATE catalog_eav_attribute SET is_used_for_promo_rules = 0, is_visible_on_front = 1, is_searchable = 1, is_filterable = 0, is_visible = 1, is_used_for_price_rules = 0, is_filterable_in_search = 0, used_in_product_listing = 0, used_for_sort_by = 0 WHERE attribute_id IN (SELECT attribute_id FROM eav_attribute WHERE attribute_code LIKE 'ezbase%');
@peterjaap
peterjaap / Mage_Catalog_Model_Resource_Url_getProduct.php
Last active May 4, 2017 06:09
Modified Mage_Catalog_Model_Resource_Url::_getProduct function. This function now contains a boolean that you can set to switch between rewriting the URL's for ALL products and rewriting only the URL's of products that are visible. Idea inspired by Alan Storm's blog on Scaling Magento - http://alanstorm.com/scaling_magento_at_copious
<?php
protected function _getProducts($productIds, $storeId, $entityId, &$lastEntityId)
{
$products = array();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
$adapter = $this->_getReadAdapter();
if ($productIds !== null) {
if (!is_array($productIds)) {
$productIds = array($productIds);
@peterjaap
peterjaap / convertShortOpenTags.sh
Created October 30, 2013 14:18
Replace short open tag PHP with full form ones. Note; does not account for short open tags followed by a line break. <? to <?php, <?// to <?php //, <?/* to <?php /*, <?= to <?php echo
find . -type f -print0 |xargs -0 sed -i -e 's/<? /<?php /g' -e 's/<?\/\//<?php \/\//g' -e 's/<?\/\*/<?php \/\*/g' -e 's/<?\=/<?php echo/g'
@peterjaap
peterjaap / fixtags.php
Last active February 7, 2021 22:22
Replace PHP short open tags with long form open tags - PHP script version. Slightly adapted from https://github.com/danorton/php_replace_short_tags -- usage; find . -type f -iname "*.phtml" | xargs php -d short_open_tag=On fixtags.php --overwrite
#!php-cli
<?php
/**
* php_replace_short_tags
* Copyright © 2010 Weirdmasters, Austin, Texas
*
* License:
* CC-BY-SA v3.0
* http://creativecommons.org/licenses/by-sa/3.0/
*
@peterjaap
peterjaap / Mage_Catalog_Model_Resource_Eav_Mysql4_Url::_getProduct - Magento 1.5.php
Created October 31, 2013 13:59
For Magento 1.5! Modified Mage_Catalog_Model_Resource_Eav_Mysql4_Url::_getProduct function. This function now contains a boolean that you can set to switch between rewriting the URL's for ALL products and rewriting only the URL's of products that are visible. Idea inspired by Alan Storm's blog on Scaling Magento - http://alanstorm.com/scaling_ma…
<?php
protected function _getProducts($productIds = null, $storeId, $entityId = 0, &$lastEntityId)
{
$products = array();
$websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
if (!is_null($productIds)) {
if (!is_array($productIds)) {
$productIds = array($productIds);
}
@peterjaap
peterjaap / splitMagentoOrderIntoTwoInvoices.php
Last active January 23, 2017 05:41
Split invoice in Magento into two invoices, one for virtual and one for non-virtual products
<?php
chdir(dirname(__FILE__));
require_once '../app/Mage.php';
Mage::app();
umask(0);
$resource = Mage::getModel('core/resource');
$db = $resource->getConnection('core_write');
@peterjaap
peterjaap / exportAttributesToCsv.php
Created December 10, 2013 15:31
Export Magento attributes and their options to a human-readable CSV file.
<?php
chdir(dirname(__FILE__));
require_once '../app/Mage.php';
Mage::app();
umask(0);
$productModel = Mage::getModel('Mage_Catalog_Model_Product');
$categoryModel = Mage::getModel('Mage_Catalog_Model_Category');
@peterjaap
peterjaap / fullquery.diff
Created January 31, 2014 09:36
Show full query in Magento stack trace
diff --git a/lib/Zend/Db/Statement/Pdo.php b/lib/Zend/Db/Statement/Pdo.php
index cd0a947..b116e3d 100644
--- a/lib/Zend/Db/Statement/Pdo.php
+++ b/lib/Zend/Db/Statement/Pdo.php
@@ -231,7 +231,7 @@ class Zend_Db_Statement_Pdo extends Zend_Db_Statement implements IteratorAggrega
}
} catch (PDOException $e) {
#require_once 'Zend/Db/Statement/Exception.php';
- throw new Zend_Db_Statement_Exception($e->getMessage(), (int) $e->getCode(), $e);
+ throw new Zend_Db_Statement_Exception($e->getMessage() . PHP_EOL . $this->_stmt->queryString, (int) $e->getCode(), $e);