Skip to content

Instantly share code, notes, and snippets.

@nklatt
nklatt / create_attributes.php
Last active May 14, 2020 07:45
Programmatically add new product attribute with options to a Magento 2 store and add to Default attribute group
<?php
defined('STDIN') or die(_("Access Denied. CLI Only"));
// execute from the command line: php <path to magento root>/cli/create_attributes.php
require __DIR__.'/../app/bootstrap.php'; // assuming this file is in /cli under the root magento dir
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$installer = $bootstrap->getObjectManager()->create('Magento\Catalog\Setup\CategorySetup');
$objectManager = $bootstrap->getObjectManager();
@nklatt
nklatt / add_column.php
Created May 12, 2016 17:11
Ensure a column exists in a MySQL table using concrete5, though that is secondary
<?php defined('C5_EXECUTE') or die(_('Access Denied.'));
function addColumnToTable($table, $column, $type = 'tinyint(1) not null default 0') {
$db = Loader::db();
$qResult = $db->Execute('show columns from `'.$table.'` like "'.$column.'"');
$columnAlreadyExists = false;
foreach ($qResult as $row) {
if (is_array($row) && !empty($row['Field']) && $row['Field'] === $column) {
$columnAlreadyExists = true;
}
}
@nklatt
nklatt / dbTablesLoop.php
Created November 17, 2015 15:42
Loop over all tables in a database.
use Illuminate\Database\Capsule\Manager as DB;
$capsule->addConnection(array(
'host' => 'localhost',
'database' => 'information_schema',
'username' => 'usr',
'password' => 'pwd',
'collation' => 'utf8_general_ci',
'charset' => 'utf8',
'driver' => 'mysql',
@nklatt
nklatt / myApp.js
Last active August 29, 2015 14:18
Extending Angular number inputs to validate for step attribute
angular
.module('myApp', [])
.directive("step", function() {
return {
restrict: "A",
require: "ngModel",
link: function(scope, element, attributes, ngModelCtrl) {
ngModelCtrl.$validators.step = function(modelValue, viewValue) {
var isValid = true; // assumed innocent until proven guilty
if ( ! ngModelCtrl.$isEmpty(modelValue) ) { // empty is okay
@nklatt
nklatt / mountsshfs
Last active August 29, 2015 14:11 — forked from pete-otaqui/mountsshfs
mountsshfs with addition of MOUNT_AS variable
#!/bin/sh
## http://ubuntuforums.org/showthread.php?t=430312
## The script will attempt to mount any fstab entry with an option
## "...,comment=$SELECTED_STRING,..."
## Use this to select specific sshfs mounts rather than all of them.
SELECTED_STRING="sshfs"
## mount as user, default = "root"
MOUNT_AS="root"