Skip to content

Instantly share code, notes, and snippets.

View jlnarvaez's full-sized avatar
💻
Programming

Jose Luis Narváez jlnarvaez

💻
Programming
View GitHub Profile
@jlnarvaez
jlnarvaez / Handler.php
Created January 31, 2022 07:56
Create custom Logger file in Magento 2
// Location: app/code/JLNarvaez/CustomLog/Logger/Handler.php
<?php
namespace JLNarvaez\CustomLog\Logger;
use Monolog\Logger;
class Handler extends \Magento\Framework\Logger\Handler\Base
{
/**
@jlnarvaez
jlnarvaez / uiregistry.js
Created October 21, 2021 09:34
[Magento 2] UI Components - uiRegistry
//Initialice uiRegistry (for Chrome debug)
var uiRegistry = require('uiRegistry');
// Get all UI Components names registered on the page
uiRegistry.get(uiItem => console.log(uiItem.name));
// Get all UI Components index registered on the page
uiRegistry.get(uiItem => console.log(uiItem.index));
// Get a specific UI Component by name
@jlnarvaez
jlnarvaez / M2Log.php
Last active July 27, 2023 09:01
Magento 2 Custom Log (for Development purposes)
<?php
/**
* This snippet is useful to debug in production environments.
* DON'T USE THIS CODE TO LOG IN YOUR MODULES.
* To create a custom log check Magento official documentation
* (https://devdocs.magento.com/guides/v2.4/config-guide/log/custom-logger-handler.html)
*/
// Custom Log for Magento v2.3 or <
@jlnarvaez
jlnarvaez / objectToArray.php
Last active February 3, 2021 12:14
Object to array PHP (Recursive)
<?php
public function objectToArray($object)
{
if (!is_object($object)) {
return $object;
}
return array_map([$this, 'objectToArray'], (array) $object);
}
@jlnarvaez
jlnarvaez / place-order-mixin.js
Last active November 10, 2020 10:08
[MAGENTO 2] Mixin JS for place-order action
// Jlnarvaez/Checkout/view/frontend/web/js/action/place-order-mixin
define([
'mage/utils/wrapper'
], function (wrapper) {
'use strict';
return function (placeOrderFunction) {
return wrapper.wrap(placeOrderFunction, function (originalPlaceOrder, paymentData, messageContainer) {
originalPlaceOrder(paymentData, messageContainer);
@jlnarvaez
jlnarvaez / modal.html
Created November 4, 2020 07:32
[MAGENTO 2] Modal JS
<div
id="mymodal"
class="modal-card"
data-mage-init='{"Magento_Ui/js/modal/modal":{"responsive": true, "innerScroll": true,"buttons": []}}'
>
<!-- Content -->
<a href="" class="action primary confirm"><?= __('Confirm') ?></a>
<a href="" class="action cancel"><?= __('Cancel') ?></a>
</div>
@jlnarvaez
jlnarvaez / validation.html
Last active November 4, 2020 07:34
[MAGENTO 2] Validate field manually
<form id="form-send-mail" action="<?= $block->getUrl('jlnarvaez_mymodule/sample/send') ?>" method="POST" >
<div class="field required">
<div class="control">
<input type="email" name="my_email" class="inpt-mail input-text"
id="email_address" value=""
placeholder="<?= __('Email') ?>"
title="<?= __('Email') ?>" data-validate="{required:true, 'validate-email':true}" />
</div>
<a href="" class="confirm-send"><?= __('Confirm') ?></a>
</div>
@jlnarvaez
jlnarvaez / utils.sh
Last active October 15, 2020 10:34
Utils for development (Bash)
# Ignore file permissions as changes in git
alias ignore_git_chmod="git config core.fileMode false"
@jlnarvaez
jlnarvaez / TestObjectManager.php
Last active July 15, 2022 07:24
Magento 2 Snippets Object Manager
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
// PRODUCT
$product = $objectManager->create('\Magento\Catalog\Model\ProductRepository')->get(/* SKU Product */);
// ORDER
$order = $objectManager->create('\Magento\Sales\Model\OrderRepository')->get(/*ID Order*/);
@jlnarvaez
jlnarvaez / dockutils.sh
Last active November 5, 2020 09:38
Utils functions for docker
# Delete all containers that contains a name passed by argument
# (If argument not passed, all containers will be deleted)
# Example: dockrm php
dockrm() {
docker ps --filter name="$1" -aq | xargs docker stop | xargs docker rm
}
# Exec container that contains a name passed by argument
# Example: dockexec php bash
# Can execute a command inside container too