Skip to content

Instantly share code, notes, and snippets.

View timneutkens's full-sized avatar
👋

Tim Neutkens timneutkens

👋
View GitHub Profile
@timneutkens
timneutkens / index.js
Created November 25, 2016 11:37
Save PDF using javascript (isomorphic-fetch and file-saver)
import fetch from 'isomorphic-fetch'
import { saveAs } from 'file-saver'
fetch('/url/with/pdf', {
headers: {
'Content-Type': 'application/pdf'
},
responseType: 'blob'
}).then(response => response.blob())
.then(blob => saveAs(blob, 'test.pdf'))
@timneutkens
timneutkens / installCustomCategoryAttributeExample.php
Created November 21, 2016 11:38
Magento2 | Install custom category attribute
<?php
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) {
$setup->startSetup();
/** @var \Magento\Eav\Setup\EavSetup $eavSetup */
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$entityTypeId = $eavSetup->getEntityTypeId(\Magento\Catalog\Model\Category::ENTITY);
@timneutkens
timneutkens / category_form.xml
Created November 14, 2016 15:02
Magento 2 Attribute true/false switch (view/adminhtml/ui_component/)
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="general">
<field name="YOUR_ATTRIBUTE">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">60</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
@timneutkens
timneutkens / .zshrc
Last active November 3, 2016 10:48
Open https://www.git-tower.com in any directory that has a git repository anywhere as parent
alias tower='gittower $(git rev-parse --show-toplevel)'
@timneutkens
timneutkens / default.xml
Created October 19, 2016 08:45
Add block to <head> Magento 2
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="head.additional">
<!-- Your block -->
</referenceBlock>
</body>
</page>
@timneutkens
timneutkens / magento2-mage-template.md
Created September 23, 2016 14:16
Magento2 mage/template example

How to use mage/template in Magento2

define(['mage/template'], function (mageTemplate) {
  // mageTemplate is a wrapper around `_.template`. See http://underscorejs.org/#template
  var template = mageTemplate('<underscore.js template string>')
  var html = mageTemplate({ /* optional data object */ })
  document.getElementById('<id here'>).innerHTML = html
})
@timneutkens
timneutkens / getconfig.md
Last active March 24, 2019 17:45 — forked from wsakaren/gist:3a26a61347cbe485677f
Mage::getStoreConfig in Magento 2 compared to Magento 1

Magento 1.x:

Mage::getStoreConfig('carriers/shipper/active')

Magento 2.x (using constructor injection):

protected $scopeConfig;
@timneutkens
timneutkens / slack-smartdashes.txt
Last active September 12, 2016 10:23
Disable smart dashes in Slack
Open Slack -> Go to Edit at the menu bar -> Substitutions -> Smart Dashes
@timneutkens
timneutkens / block.xml
Created September 8, 2016 07:57
Magento2 - Create block for static block
<block class="Magento\Cms\Block\Block" name="BLOCK_NAME_HERE">
<arguments>
<argument name="block_id" xsi:type="string">STATIC_BLOCK_IDENTIFIER_HERE</argument>
</arguments>
</block>