Skip to content

Instantly share code, notes, and snippets.

View mrkhoa99's full-sized avatar
🎯
Don't repeat yourself

Mr Khoa mrkhoa99

🎯
Don't repeat yourself
View GitHub Profile
@mrkhoa99
mrkhoa99 / GMO Payment Gateway Magento 2
Created July 19, 2016 10:48
The API does not return error messages, so I translated these from the example english-like messages in the GMO documentation
#Resource reference: https://docs.omniref.com/github/veracross/active_merchant/HEAD/symbols/ActiveMerchant::Billing::GmoGateway#line=46
# The API does not return error messages, so I translated these from the
# example english-like messages in the GMO documentation
ERROR_CODES = {
'E01010001' => 'Shop ID not specified',
'E01010008' => 'Shop ID contains invalid characters or is too long',
'E01010010' => 'Shop ID is invalid',
'E01020001' => 'Shop Password not specified',
'E01020008' => 'Shop Password contains invalid characters or is too long',
'E01030002' => 'Shop ID and Password are invalid',
class Totals extends \Magento\Framework\View\Element\Template
{
/**
* @var \Magento\Sales\Model\Order
*/
protected $_order;
/**
* @var \Magento\Framework\DataObject
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.cart.totals">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="block-totals" xsi:type="array">
<item name="children" xsi:type="array">
<item name="before_grandtotal" xsi:type="array">
<item name="children" xsi:type="array">
@mrkhoa99
mrkhoa99 / Set related products programatically Magento 2
Created September 15, 2016 06:07
Set related products programatically Magento 2
@mrkhoa99
mrkhoa99 / Playground Dirty - test.php
Last active July 14, 2022 05:03
Dirty Playground Magento 2
//put under pub/test.php
<?php
require dirname(__FILE__) . '/../app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('TestApp');
$attributeData = [
"attribute": [
"is_wysiwyg_enabled": true,
"is_html_allowed_on_front": true,
"used_for_sort_by": true,
"is_filterable": true,
"is_filterable_in_search": true,
"is_used_in_grid": true,
"is_visible_in_grid": true,
"is_filterable_in_grid": true,
<?php
class ApiClient
{
const METHOD_GET = 'GET';
const METHOD_PUT = 'PUT';
const METHOD_POST = 'POST';
const METHOD_DELETE = 'DELETE';
protected $validMethods = [
self::METHOD_GET,
self::METHOD_PUT,
<?php
$userData = ["username" => "customeruser@gmail.com", "password" => "123456"];
$ch = curl_init("http://magen2.loc/rest/V1/integration/customer/token");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));
$token = curl_exec($ch);
@mrkhoa99
mrkhoa99 / Clean up database Magento 2
Last active January 15, 2024 12:20
Clean up database Magento 2 for local enviroment
//Orders, Invoices, Shipments
DELETE FROM sales_order;
DELETE FROM sales_creditmemo_comment;
DELETE FROM sales_creditmemo_item;
DELETE FROM sales_creditmemo;
DELETE FROM sales_creditmemo_grid;
DELETE FROM sales_invoice_comment;
DELETE FROM sales_invoice_item;
DELETE FROM sales_invoice;
@mrkhoa99
mrkhoa99 / Add Translation Javascript Magento 2
Last active March 12, 2017 10:48
Add Translation Javascript Magento 2
For example:
require(["jquery","mage/translate"], function($){
$.mage.translate.add({"Filters":"Filters","Processing":"Processing","per page":"per page","records":"records"})
});