Skip to content

Instantly share code, notes, and snippets.

View 0-Sony's full-sized avatar

Phuong LÊ 0-Sony

View GitHub Profile
@0-Sony
0-Sony / GetFileContentFromModule.php
Created July 6, 2023 10:14
Magento 2 : Get File Content from Specific Module
<?php
declare(strict_types=1);
namespace MyNamespace\MyModule\Setup\Patch\Data;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir;
@0-Sony
0-Sony / reset_all_products.sql
Created April 16, 2019 13:10
Magento 2 : Reset all products data and use the default config value
DELETE FROM `catalog_product_entity_text` where store_id <> 0;
DELETE FROM `catalog_product_entity_datetime` where store_id <> 0;
DELETE FROM `catalog_product_entity_decimal` where store_id <> 0;
DELETE FROM `catalog_product_entity_int` where store_id <> 0;
DELETE FROM `catalog_product_entity_varchar` where store_id <> 0;
@scottsb
scottsb / m2-cache-cheat-sheet.md
Last active February 22, 2024 14:56
Magento 2 Cache Cheat Sheet

Magento 2 Cache Cheat Sheet

This page lists what caches or directories you will need to clear to apply various types of changes. It is consolidated and adapted from the complete official documentation on directories and caches.

💁 If your development environment supports it, you are better off using Vinai's automatic cache cleaner. As of this writing, the primary reason why it might not work is if your code is hosted on a NFS share (common with Vagrant).

@0-Sony
0-Sony / CustomAttributeInstaller.php
Last active April 12, 2024 10:36
Magento 2 : Create attributeSet, AttributeGroup, Product Attributes programmatically, and add Options (tested on Version 2.3, but older should work as well)
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <sony@menincode.com> <@>
* @copyright Copyright (c) 2019 Menincode (http://www.menincode.com)
*/
namespace MyNameSpace\Catalog\Setup;
@0-Sony
0-Sony / MyEntityDataProvider.php
Last active April 12, 2024 10:36
Magento 2.2 : Create Simple Grid UI Component List (tested on version 2.2.6)
<?php
/**
* @license All rights reserved
* @author Phuong LE <sony@menincode.con>
*/
namespace MyNamespace\MyModule\Ui\Component;
use MyNamespace\MyModule\Model\ResourceModel\MyEntity\CollectionFactory;
use MyNamespace\MyModule\Model\MyEntity;
@0-Sony
0-Sony / call-custom-js-everywhere.js
Last active February 6, 2023 07:35
Magento 2 : Work around JS : Call a js file using requireJs or call a js file before another one or override existing js method
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <sony@menincode.com> <@>
* @copyright Copyright (c) 2018 Menincode (http://www.menincode.com)
*/
/** MyNamespace/MyModule/view/frontend/web/js/call-custom-js-everywhere.js */
/** check the requirejs-config.js file */
@robhrt7
robhrt7 / MySQL_5-7_macOS.md
Last active February 28, 2024 03:48 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL 5.7 on macOS using Homebrew

This is a fork of original gist https://gist.github.com/nrollr/3f57fc15ded7dddddcc4e82fe137b58e, with slight changes on pointing to 5.7 version branch, instead of 8 (latest default of MySQL in Hombrew).

Install MySQL 5.7 on macOS

This procedure explains how to install MySQL using Homebrew on macOS (Sierra 10.12 and up)

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.
@jaredatch
jaredatch / mailhog-mamp.md
Created January 30, 2018 21:57
Install MailHog with MAMP Pro

Install MailHog with MAMP Pro, using HomeBrew.

MailHog

First let's make sure HB is updated. Open up terminal for the following steps.

$ brew update
@0-Sony
0-Sony / getParameterByName.js
Created January 19, 2018 11:46
Get url GET parameter value by name, depending on given url
getParameterByName: function (name, url) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(url);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
/** Example : We want to know if a param get "page" exist on our current url **/
var results = getParameterByName('page', window.location);
@0-Sony
0-Sony / CmsBlockInstaller.php
Last active August 10, 2020 12:59
Magento 2 : Create Cms Block Programmatically
<?php
namespace Namespace\Cms\Setup;
use Magento\Cms\Api\BlockRepositoryInterface;
use Magento\Cms\Api\Data\BlockInterface;
use Magento\Cms\Api\Data\BlockInterfaceFactory;
use Magento\Framework\App\State;
use Magento\Framework\App\Area;
use Magento\Framework\Setup\InstallDataInterface;