Skip to content

Instantly share code, notes, and snippets.

View gelanivishal's full-sized avatar
🎯
Focusing

Vishal Gelani gelanivishal

🎯
Focusing
View GitHub Profile
@gelanivishal
gelanivishal / sql.md
Created March 6, 2017 12:34
Magento 2: How to truncate customers, products, reviews and orders table

[Note] : Please take database backup prior to executing these queries.

I went through all tables and came up with following list of tables that should be truncated in order to clear test data:

SET FOREIGN_KEY_CHECKS = 0;

Truncate order tables

@gelanivishal
gelanivishal / file.php
Created March 6, 2017 07:09
String sanitizer for filename
public static function normalizeString ($str = '')
{
$str = strip_tags($str);
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|]+/', ' ', $str);
$str = strtolower($str);
$str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
$str = htmlentities($str, ENT_QUOTES, "utf-8");
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
$str = str_replace(' ', '-', $str);

Linux Commands

File CommandsFile Commands

  • ls - directory listing
  • ls -al - Formatted listing with hidden files
  • cd dir - change directory to dir
  • cd - change to home
  • pwd - show current directory
  • mkdir dir - create directory dir
  • rm file - delete file
@gelanivishal
gelanivishal / linux-commands.md
Last active November 17, 2022 14:18
Linux Commands

Linux Commands

File CommandsFile Commands

  • ls - directory listing
  • ls -al - Formatted listing with hidden files
  • cd dir - change directory to dir
  • cd - change to home
  • pwd - show current directory
  • mkdir dir - create directory dir
  • rm file - delete file
@gelanivishal
gelanivishal / magento-2-code-snippets.md
Last active February 25, 2017 05:14
Magento 2 code snippets

Magento2 code snippets

Order state update

To update the order state and and status pro-grammatically in order define the status and state in this format. Initiate order object in the construct function and use that order object in the custom function to update it. To update order state programmatically in model, get order object from the construct function.

public function __construct(
    \Magento\Sales\Model\Order $order
){
@gelanivishal
gelanivishal / default
Created February 18, 2017 15:12
Ubuntu 16.04: Nginx magento2 configuration
# put following two lines under server node of nginx default
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
@gelanivishal
gelanivishal / git_change_user.sh
Last active February 21, 2017 01:36
Git: Change user of your local repository
git config --global user.name "Your name"
git config --global user.email "your@email.com"
@gelanivishal
gelanivishal / m1.gitignore
Created February 18, 2017 15:11
M1 - gitignore
.idea/
nbproject/
/var
/media
/app/etc/local.xml
cgi-bin/
/includes/src
@gelanivishal
gelanivishal / mediasync.sh
Created February 18, 2017 15:10
Bash script for auto backup your Magento media directory on specific path.
#!/bin/bash
# clear screen
clear;
# Get current directory, assume this script is locate under Magento root directory
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
@gelanivishal
gelanivishal / debug_xml_magento2.md
Created February 18, 2017 15:05
Debugging layout XML loading in Magento 2

Open following file :

{root}/vendor/magento/framework/View/Model/Layout/Merge.php

and find _loadFileLayoutUpdatesXml function at line number 681.

Just echo $file->getFilename(); in foerach. You can see list of layout xml files adding in that action.