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 / GEO.php
Created September 27, 2016 16:48
Geo php
<?php
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: :*/
/*:: This routine calculates the distance between two points (given the :*/
/*:: latitude/longitude of those points). :*/
/*:: :*/
/*:: Definitions: :*/
/*:: South latitudes are negative, east longitudes are positive :*/
/*:: :*/
@jonatanrdsantos
jonatanrdsantos / remove-unused-media-catalog-image.php
Created August 30, 2016 16:17
Magento remove unused media catalog images
<?php
// Avoid any time limit
set_time_limit(0);
// Avoid any memory limit
ini_set('memory_limit', -1);
// Include bootstrap code and Mage class
require_once 'app/Mage.php';
@jonatanrdsantos
jonatanrdsantos / magento-custom-order-report.php
Created July 29, 2016 01:26
Magento custom order report to CSV
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once 'app/Mage.php';
Mage::app();
//echo "Testando<br>";
$fromDate = date('Y-m-d H:i:s', strtotime('2016-05-28 00:00:01'));
$toDate = date('Y-m-d H:i:s', strtotime('2016-07-28 23:59:59'));
$orders = Mage::getModel('sales/order')->getCollection()
->addFieldToSelect('increment_id')
<?php
switch($_SERVER['HTTP_HOST']) {
case 'shoes.com':
case 'www.shoes.com':
$mageRunCode = 'shoes';
$mageRunType = 'website';
break;
@jonatanrdsantos
jonatanrdsantos / Processlist MYSQL.md
Created May 14, 2016 18:45
Show processlist mysql

Show MySQL process list without sleeping connections

Usually you don't need to, but when you want to see which queries your MySQL server currently needs to handle (and if there are locks, etc), you could say SHOW PROCESSLIST in a MySQL shell.

Unfortunately, SHOW PROCESSLIST does not allow filtering. When you are on MySQL ≥ 5.1.7, do this instead:

SELECT * FROM information_schema.processlist WHERE command != 'Sleep' ORDER BY id;

That also allows you to only show some values or order differently, like so:

@jonatanrdsantos
jonatanrdsantos / prototype-update-select-option.md
Last active April 28, 2016 18:24
Update select option based in ajax request

PHP

    public function stateSearchAction()
    {
        $country = $this->getRequest()->getParam('code');
        $collection = Mage::getModel('directory/region')->getCollection()
            ->addFieldToFilter('country_id', $country)->getData();
        $this->getResponse()->clearHeaders()->setHeader('Content-type', 'application/json');
        $this->getResponse()->setBody(Zend_Json::encode($collection));
    }
@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
@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 / 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 / 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