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 / getDirectoryPath.php
Created May 6, 2021 18:53
Magento 2 : get Directory Path
<?php
namespace MyNamespace\MyModule\Controller\Index;
use Magento\Framework\App\Action\Action;
use Magento\Framework\App\Action\Context;
use Magento\Framework\Module\Dir;
class Example extends Action
{
public function __construct(
@0-Sony
0-Sony / query.sql
Created April 29, 2021 15:59
Magento2 : Example updateFromSelect SQL
UPDATE `finale_table` AS `ft`
LEFT JOIN `tmp_table` AS `tmp`
ON ft.crm_id = tmp.crm_id
AND ft.code = tmp.code
SET
`ft`.`libelle` = `tmp`.`libelle`,
`ft`.`cli_eligible` = `tmp`.`name`,
`ft`.`date` = `tmp`.`date`
WHERE (tmp.mvt = 2)
@0-Sony
0-Sony / ProductFilter.php
Created January 14, 2021 11:22
Magento 2 : Filter product using search criteria
<?php
namespace MyNamespace\MyModule\Model;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Catalog\Api\ProductRepositoryInterface;
class ProductFilter
{
/** @var ProductRepositoryInterface */
protected $productRepository;
@0-Sony
0-Sony / test.php
Created November 2, 2020 15:26
Magento 2 : Script for Quick Test purpose
<?php
require __DIR__ . '/app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('TestApp');
$bootstrap->run($app);
@0-Sony
0-Sony / AddCustomQuoteItemOrderItemAttribute.php
Created October 12, 2020 08:13
Magento 2 : Add Quote Item / Order Item attribute (Patch/Schema)
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]>
* @copyright Copyright (c) 2020 Men In Code Ltd (https://www.menincode.com)
*/
namespace MyNamespace\MyModule\Setup\Patch\Schema;
use Magento\Framework\DB\Ddl\Table;
@0-Sony
0-Sony / PaymentInformationManagementPlugin.php
Created August 12, 2020 14:41
Magento2 : Alter the payment methods list in checkout
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]>
* @copyright Copyright (c) 2020 Men In Code Ltd (https://www.menincode.com)
*/
namespace MyNamespace\MyModule\Plugin\Model;
class PaymentInformationManagementPlugin
@0-Sony
0-Sony / addCustomCustomerAttribute.php
Last active December 28, 2021 16:13
Magento 2: Create custom Customer Attribute (Using Patch Data for Magento version >= 2.3.x )
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]>
* @copyright Copyright (c) 2020 Men In Code Ltd (https://www.menincode.com)
*/
namespace MyNamespace\MyModule\Setup\Patch\Data;
use Magento\Customer\Model\Customer;
@0-Sony
0-Sony / minicart-refresh.js
Last active July 14, 2020 07:26
Magento2 : Minicart Reload
require([
'Magento_Customer/js/customer-data'
], function (customerData) {
var sections = ['cart'];
customerData.invalidate(sections);
customerData.reload(sections, true);
});
@0-Sony
0-Sony / check_constraint.sql
Created June 8, 2020 15:21
Check Constraint SQL
SELECT `TABLE_SCHEMA`, `TABLE_NAME`
FROM `information_schema`.`KEY_COLUMN_USAGE`
WHERE `CONSTRAINT_NAME` IN ('MY_CONSTRAINT_NAME');
@0-Sony
0-Sony / useCriteria.php
Last active May 11, 2020 10:17
Magento 2 : Filter a collection using search criteria builder
<?php
/**
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Phuong LE <[email protected]>
* @copyright Copyright (c) 2020 Men In Code Ltd (https://www.menincode.com)
*/
namespace Namespace\MyModule\Block
use Magento\Customer\Api\CustomerRepositoryInterface;