Skip to content

Instantly share code, notes, and snippets.

View jonatanrdsantos's full-sized avatar
🏠
Working from home

Jonatan Santos jonatanrdsantos

🏠
Working from home
View GitHub Profile
@jonatanrdsantos
jonatanrdsantos / magento-update-state.php
Created October 5, 2015 17:46
Magento update state based in incrementalId
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
Mage::app();
echo "Testando<br>";
$order = Mage::getModel('sales/order')->loadByIncrementId('100045842');
@jonatanrdsantos
jonatanrdsantos / Magento-errors-and-causes.md
Last active October 9, 2015 17:47
Magento errors and causes.

##Magento errors and causes

###Error: Not valid template file

CRIT (2): Not valid template file: frontend/base/default/template/path/to/template.phtml
$ curl -s -o /dev/null -w "Status: %{http_code} Connect: %{time_connect} TTFB: %{time_starttransfer} Total time: %{time_total} \n" www.site-domain.com
Status: 200 Connect: 0,688 TTFB: 1,523 Total time: 2,756 
@jonatanrdsantos
jonatanrdsantos / load-payment-block-outside-magento.php
Created October 26, 2015 23:21
Load custom block outside magento
<?php
include_once "app/Mage.php";
umask(0);
Mage::app()->loadArea('frontend');
$layout = Mage::getSingleton('core/layout');
//load default xml layout handle and generate blocks
$layout->getUpdate()->load('default');
$layout->generateXml()->generateBlocks();
@jonatanrdsantos
jonatanrdsantos / mage-database.sh
Created October 30, 2015 16:05 — forked from diogobaracho/mage-database.sh
Magento common queries: mysqldump , import database, change admin user password, change site url, change cookie domain
#!/bin/sh
echo "Generate dump?(yes)"
read godump
if [ $godump = 'yes' ] || [ $godump = 'y' ]; then
read -p "mysql user: " YOUR_USER
read -p "mysql password: " YOUR_PASSWORD
read -p "mysql host: " YOUR_HOST
<?php
/**
* A simple fix for a shell execution on preg_match('/[0-9]\.[0-9]+\.[0-9]+/', shell_exec('mysql -V'), $version);
* The only edit that was done is that shell_exec('mysql -V') was changed to mysql_get_server_info() because not all
* systems have shell access. XAMPP, WAMP, or any Windows system might not have this type of access. mysql_get_server_info()
* is easier to use because it pulls the MySQL version from phpinfo() and is compatible with all Operating Systems.
* @link http://www.magentocommerce.com/knowledge-base/entry/how-do-i-know-if-my-server-is-compatible-with-magento
* @author Magento Inc.
*/
@jonatanrdsantos
jonatanrdsantos / Good dump
Last active September 1, 2016 17:05
Make good dump like stars
mysqldump -uUSERNAME -pPASSWORD -hHOSTNAME DATABASE_NAME --single-transaction --opt -R | gzip > dump_database_$(date +%Y-%m-%d:%H:%M:%S).sql.gz
@jonatanrdsantos
jonatanrdsantos / magento-groupby.md
Created December 17, 2015 13:47
Magento: Wrong count in admin Grid when using GROUP BY clause, overriding lib module

Magento when you use GROUP BY clause in any Grid.php file in admin, the count always display wrong. Many times it displays 1 even if there are hundreds of records. Due to this your pagination also doesn’t work. This is a bug in Magento. Your getSize() always returns wrong count whereas total records in grid are proper.

To fix this, you need to edit one of your core file. As it’s not a good practice to edit core file, we will here override the core file. Overriding LIB module

Create a rewrite to yout collection main.table:

Mage_[MODULE]Model_Resource[RESOURCENAME]_Grid_Collection

And rewrite getSelectCountSql function with below one:

@jonatanrdsantos
jonatanrdsantos / cancel-ordre.php
Created February 17, 2016 15:48
Cancel order magento admin
<?php
/**
* Error reporting
*/
error_reporting(E_ALL | E_STRICT);
/**
* Compilation includes configuration file
*/
@jonatanrdsantos
jonatanrdsantos / mamp-mysql.sh
Created April 14, 2016 21:39
To make MAMP MySQL works in command line
$ sudo mkdir /var/mysql
$ cd /var/mysql
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock