Skip to content

Instantly share code, notes, and snippets.

View tuyennn's full-sized avatar
💿

Tuyen Nguyen tuyennn

💿
View GitHub Profile
@tuyennn
tuyennn / magedeploy.sh
Created March 20, 2024 12:02 — forked from rafaelstz/magedeploy.sh
Magento 2 Deploy script
#!/usr/bin/env bash
LANGUAGES="en_US pt_BR"
# production or developer
ENVIRONMENT="production"
COMPOSER=$(which composer)
PHP=$(which php)
ROOT=$(pwd)
@tuyennn
tuyennn / tortoise_n_hare.php
Last active September 29, 2021 15:06
Find duplicate in array tortoise and hare
<?php
function findDuplicate($arr)
{
// Initialise variables
$tortoise = $arr[0];
$hare = $arr[0];
// Loop till we find the
@tuyennn
tuyennn / find_dup_val_arr.php
Created September 29, 2021 15:01
Duplicate values in array
<?php
$arr = [ 2, 6, 4, 1 , 1, 3, 1, 5, 2 ];
$dups = [];
foreach(array_count_values($arr) as $val => $c) {
if($c > 1) {
$dups[] = ['value' => $val, 'dup_times' => $c];
}
}
@tuyennn
tuyennn / my.cnf
Created October 15, 2020 15:55 — forked from fevangelou/my.cnf
Optimized my.cnf configuration for MySQL/MariaSQL (on Ubuntu, CentOS etc. servers)
# Optimized my.cnf configuration for MySQL/MariaSQL
#
# by Fotis Evangelou, developer of Engintron (engintron.com)
#
# ~ Updated January 2020 ~
#
#
# The settings provided below are a starting point for a 2GB - 4GB RAM server with 2-4 CPU cores.
# If you have different resources available you should adjust accordingly to save CPU, RAM & disk I/O usage.
#
@tuyennn
tuyennn / UpgradeData.php
Created February 26, 2019 02:15
Magento 2 Quote, Sales Attribute Data Installer
<?php
namespace Vendor\Module\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Sales\Setup\SalesSetupFactory;
use Magento\Quote\Setup\QuoteSetupFactory;
@tuyennn
tuyennn / InstallData.php
Created November 16, 2018 06:35
Magento 2 Create text swatch programmatically
<?php
namespace Vendor\Module\Setup;
use Magento\Framework\Setup;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Catalog\Model\Product\Type;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
@tuyennn
tuyennn / 0001-MAGETWO-57153-Backport-Github-Custom-options-not-dis.patch
Created November 14, 2018 10:07
MAGETWO-57153: [Backport] - [Github] Custom options not displayed correctly on a store view level
From 2b154f47cac22b48238714aaff57d86fff6ea3ac Mon Sep 17 00:00:00 2001
From: tuyennn <thinghost76@gmail.com>
Date: Wed, 14 Nov 2018 17:03:14 +0700
Subject: [PATCH] MAGETWO-57153: [Backport] - [Github] Custom options not
displayed correctly on a store view level #2908 #5885 #5612
---
.../Product/Initialization/Helper.php | 91 +++++++++++++++----
.../Model/Product/Option/Repository.php | 37 +++++++-
.../Model/Product/Option/SaveHandler.php | 20 +++-
@tuyennn
tuyennn / gist:538828972d2542fbad3daec18c884439
Created June 15, 2018 09:05
Magento 2 Get Top Rated Product
public function getTopRateProducts($limit = 12)
{
$collection = $this->_productReportCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('visibility', \Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH);
$collection->addAttributeToFilter('status', \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED);
$collection->joinField(
'rating_summary',
'review_entity_summary',
'rating_summary',
@tuyennn
tuyennn / install-0.1.0.php
Created February 2, 2018 08:08
Magento Customer Attribute Setup
<?php
/* @var $installer Mage_Customer_Model_Resource_Setup */
$installer = Mage::getResourceModel('customer/setup','customer_setup');
$installer->startSetup();
if (!$installer->getAttributeId('customer', 'attribute_name')) {
$installer->addAttribute('customer', 'attribute_name', array( // TABLE.COLUMN: DESCRIPTION:
/** Standard values defined @see Mage_Eav_Model_Entity_Setup::_prepareValues() */
'label' => 'Label', // eav_attribute.frontend_label admin input label
'backend' => 'module/class_name', // eav_attribute.backend_model backend class (module/class_name format)
'type' => 'varchar', // eav_attribute.backend_type backend storage typ
@tuyennn
tuyennn / ImageChooser.php
Created January 14, 2018 17:44 — forked from cedricblondeau/ImageChooser.php
Image Chooser for Magento2 widgets
<?php
namespace Vendor\Module\Block\Adminhtml\Widget;
class ImageChooser extends \Magento\Backend\Block\Template
{
/**
* @var \Magento\Framework\Data\Form\Element\Factory
*/
protected $_elementFactory;