Skip to content

Instantly share code, notes, and snippets.

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

Maxime AVELINE WaximeA

🤷‍♂️
View GitHub Profile
@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 / 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 / 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)
@WaximeA
WaximeA / ionic_usefull.md
Created April 22, 2018 16:51
Usefull commands for Ionic

General

Run ionic project with lab and consol :

$ ionic serve -lc

Pages

@WaximeA
WaximeA / sql_memory_aid.md
Created April 12, 2018 08:46
SQL memory-aid

How to truncate a foreign key constrained table?

$ SET FOREIGN_KEY_CHECKS = 0; 
$ TRUNCATE table table_name; 
$ SET FOREIGN_KEY_CHECKS = 1;