Skip to content

Instantly share code, notes, and snippets.

View WaximeA's full-sized avatar
🤷‍♂️

Maxime AVELINE WaximeA

🤷‍♂️
View GitHub Profile
@WaximeA
WaximeA / change_definer.md
Last active February 13, 2022 22:15
Change sql script definers before a local magento database import

How to change the sql script's definers before a local magento database import :

  1. First, you have to open your terminal ;)

  2. You have to install homebrew if it's not already done :

$ brew install grep

  1. Once homebrew downloaded, just enter this command in a terminal :
@WaximeA
WaximeA / rewrite_user.md
Last active October 1, 2019 08:06
Rewrite all head branch commits user

How to rewrite all commits user of head branch :

Simply remplace YOUR EMAIL and YOUR NAME. Be carefull, this command will change all head branch commits user.

$ git filter-branch -f --env-filter " GIT_AUTHOR_NAME='YOUR NAME'GIT_AUTHOR_EMAIL='YOUR EMAIL' GIT_COMMITTER_NAME='YOUR NAME' GIT_COMMITTER_EMAIL='YOUR EMAIL' " HEAD

Then, force push $ git push -f

@WaximeA
WaximeA / newOrderAttribute.md
Last active June 4, 2019 15:07
Adding a new attribute to order in magento

Assuming that you want to add my_custom_input_field to your order and add a field to your admin create order page (to add the field to the frontend you just need to add the input field to the front template and double check the observer)

In /app/code/local/MageIgniter/CustomOrderStatus/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MageIgniter_CustomOrderStatus>
            <version>1.1</version>
        </MageIgniter_CustomOrderStatus>
@WaximeA
WaximeA / fix.md
Last active November 22, 2018 10:28
Fix Magento PHP 7.X Fatal error

Fatal error: Uncaught Error: Function name must be a string app\code\core\Mage\Core\Model\Layout.php:555

It happens because in PHP 7 you need to clarify that you are going to call the $callback variable as a method (function). So, the original line of the code looks like the following (file app/code/core/Mage/Core/Model/Layout.php):

$out .= $this->getBlock($callback[0])->$callback[1]();

In order to make it work on the latest PHP version we need to replace this piece of code by this one:

$out .= $this->getBlock($callback[0])->{$callback[1]}();
@WaximeA
WaximeA / generate.php
Created August 29, 2018 13:51
Generate files
<?php
/** @var string $path */
$path = 'semaphores/';
echo '<h3>Semaphores files will be created in '.$path.' folder.</h3>';
echo '<h4>Creating files :</h4>';
for ($second = 0; $second < 60; $second++){
/** @var string $file */
$file = 'test_201808240710'.$second.'.csv.ok';
if ($second < 10){
/** @var string $file */
@WaximeA
WaximeA / script.php
Created August 29, 2018 09:46
Fix csv line separator
<?php
/** @var string $path */
$path = 'import-files/';
/** @var string $file */
$file = 'test.csv';
/** @var string $realFile */
$realFile = $path.$file;
function putCSVLineSeparatorToLF($file){
if (!file_exists($file)){
@WaximeA
WaximeA / csvtoarray.php
Created August 29, 2018 09:05
CSV to ARRAY in php
/**
* Receives CSV string and returns as an array.
* Based on code by fab at tradermail dot info at http://php.net/manual/en/function.str-getcsv.php#119666
* *************************************************************************
*
* @param $csv
* @param $delimiter
* @param $header_line
*
* @return array | boolean
@WaximeA
WaximeA / sort_folder.php
Created August 22, 2018 09:23
Sort folders by their modification date instead of alphabetic order.
<?php
$folder = "files/";
$handle = opendir($folder);
# Making an array containing the files in the current directory:
while ($file = readdir($handle)){
if( $file != ".." && $file != "." ){
$key = filemtime($file);
$files[$key] = $file ;
}
@WaximeA
WaximeA / delete.sql
Created August 9, 2018 12:43
SQL : delete duplicate rows except one
DELETE FROM myTable
WHERE (col1, col2, col2, col3)
IN (
SELECT * FROM (
SELECT col1, col2, col2, col3
FROM myTable
GROUP BY col1, col2, col2, col3
HAVING count(*) > 1
) AS T
-- remove this where condition if you want to delete all duplicate rows

Retrive model data

    const MODEL_PATH = 'path in init of the construct method in Module/Model/Modelname.php';

    /**
     * @param null $storeId
     *
     * @return string
     */
 public function getModelData($storeId = null)