Skip to content

Instantly share code, notes, and snippets.

View mttjohnson's full-sized avatar

Matt Johnson mttjohnson

View GitHub Profile
@mttjohnson
mttjohnson / magento2-include-static-blocks.md
Last active May 23, 2021 20:05
Magento 2 - Include Static Blocks (template/cms/layout)

In .phtml tempalte file:

<?php echo $block->getLayout()->createBlock('Magento\Cms\Block\Block')->setBlockId('block_identifier')->toHtml();?>

In CMS content:

{{block class="Magento\\Cms\\Block\\Block" block_id="block_identifier"}}

In layout .xml file:

<referenceContainer name="content">
  <block class="Magento\Cms\Block\Block" name="block_identifier">
#!/bin/bash
# stop on errors
set -e
# turn on debugging
set -x
mysql -e "DROP DATABASE IF EXISTS \`test_import\`; CREATE DATABASE IF NOT EXISTS \`test_import\` DEFAULT CHARACTER SET utf8;"
START_TIME=$(date -u +"%s")
@mttjohnson
mttjohnson / mod_rewrite.htaccess
Created December 9, 2015 18:48
mod_rewrite RewriteRule - Redirects
<IfModule mod_rewrite.c>
RewriteEngine on
############################################
## Define some initial variables for use in RewriteRules later
## Sets an env var on secure page loads for www redirects ##
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} https [NC]
@mttjohnson
mttjohnson / PHPStormRegExExamples.md
Last active February 3, 2016 19:58
PHPStorm RegEx Examples

Multi word search anywhere in a file:

(text1)[\s\S]*(text2)|\2[\s\S]*\1

Mulit word search on the same line in a file

^.*text1.+?text2

@mttjohnson
mttjohnson / magento1_enterprise_index_diagnostics.sql
Last active November 9, 2017 19:53
Magento 1.x Enterprise Partial Indexing Diagnostics Toolset
-- When products are added/removed from a category this table stores all the relation data
select * from catalog_category_product where product_id = '24526';
-- The index that is used for presenting products in a category on the frontend
select * from catalog_category_product_index where product_id = '24526';
-- The change log table used for Magento EE partial index functionality
select * from catalog_category_product_index_cl where product_id = '24526' and version_id > (select version_id from enterprise_mview_metadata where changelog_name = 'catalog_category_product_index_cl');
@mttjohnson
mttjohnson / php.ini-editing.sh
Created February 24, 2016 18:03
php.ini scripted update for max_input_vars
sed -i .bak -e "s/openssl.cafile/max_input_vars = 16384\\
openssl.cafile/" /server/vagrant/etc/php.d/00-php.ini
cd /server/
vagrant ssh
sudo sed -i -e "s/openssl.cafile/max_input_vars = 16384\\
openssl.cafile/" /etc/php.d/00-php.ini
sudo apachectl restart
# clear the entire cache
varnishadm "ban req.url ~ /"
# monitor varnish stats
varnishstat -n prod
# monitor varnish log with multiple patterns
varnishlog | grep 'eqURL\|Age:\|VCL_call\|TTL\|Expires:\|Cache-Control:'
# Use a query with varnishlog to watch requests from a specific IP
@mttjohnson
mttjohnson / mage1-cron-debug.txt
Created April 4, 2016 20:23
Magento 1.x Cron Debugging
Notes from conversations with David Alger and Zach Nanninga about Magento 1.x cron jobs runnign duplicate processes
running double cron jobs because of this section in cron.php:
if ($isShellDisabled) {
Mage::dispatchEvent('always');
Mage::dispatchEvent('default');
} else {
Mage::dispatchEvent($cronMode);
}