Skip to content

Instantly share code, notes, and snippets.

View erikhansen's full-sized avatar

Erik Hansen erikhansen

View GitHub Profile
@erikhansen
erikhansen / 1_product_queries.sql
Last active April 2, 2024 01:48
Magento 2 - Remove duplicate store view-specific product and category data
/*
* IMPORTANT: The queries below are written for Magento Enterprise. If you're going to run them on Magento Community, you need
* to replace all instances of ".row_id" with ".entity_id". See this for context: http://magento.stackexchange.com/questions/139740/magento-2-schema-changes-for-ee-catalog-staging
*
* When importing products in Magento 2, if you specify store view codes in the store_view_code column, product data will be set at
* both the global scope as well as the specific store view scope. This is not ideal because now you have duplicate
* data at two different scopes that shouldn't actually be duplicated. The scripts below clean up this data by finding
* data set at specific store view scopes and if it's an exact match to the data set at the global store view, then it
* deletes the data set at the specific store view scope.
*
@erikhansen
erikhansen / issue.md
Last active March 26, 2024 14:53
Amasty M2 Full Page Cache Warmer Issue - Submitted this issue to Amasty on 2019-12-11

I have a client using this extension, and we recently discovered a big performance issue.

Description: The query generated by the \Amasty\Fpc\Model\ResourceModel\Activity::matchUrl method runs a query on a table that is missing an index.

Here is a screenshot showing the slow query:

Slow query in New Relic

Once the client added a MySQL index for the table, the slow query went away:

@erikhansen
erikhansen / gist:d80b54dca751d92a585fea84651fbac3
Created March 6, 2024 16:33
module-shipper-show-company-name-in-addresses-in-checkout.patch
Index:/src/view/frontend/web/template/shipping-address/address-renderer/default.html
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/view/frontend/web/template/shipping-address/address-renderer/default.html b/src/view/frontend/web/template/shipping-address/address-renderer/default.html
--- a/src/view/frontend/web/template/shipping-address/address-renderer/default.html
+++ b/src/view/frontend/web/template/shipping-address/address-renderer/default.html (date 1709742374536)
@@ -11,6 +11,11 @@
<div class="shipping-address-item" css="'selected-item' : isSelected() , 'not-selected-item':!isSelected()">
@erikhansen
erikhansen / README.md
Last active December 6, 2023 17:15
Troubleshoot long-running PHP script in Magento 2 on Warden

For future reference:

I just had to troubleshoot a script that ran so long that it eventually died without any relevant errors ([pid 6048:tid 139809649469184] (104)Connection reset by peer: [client 184.4.89.70:0] FastCGI: comm with server "/var/run/a49982b9-remi-safe-php81.fcgi" aborted: read failed, referer was getting written to the Apache error logs).

Thankfully I was able to reproduce the issue locally. Here are the steps I took in Warden to troubleshoot:

In pub/index.php I added this line: set_time_limit(15); above the $bootstrap->run($app);

cd <PATH TO MAGENTO 2 DIRECTORY>
@erikhansen
erikhansen / README.md
Last active August 15, 2023 09:21
Running Warden on Windows with WSL 1 & 2

Running Warden on Windows with WSL 2

See this Github comment thread for any issues or additional context for getting Warden running on Windows with WSL 2.

The instructions below cover how to install Warden on Windows, using WSL 2.

  1. Install Ubuntu 20 LTS in WSL 2
    1. To access the shell/terminal inside of Ubuntu WSL, open the Ubuntu 20.04 program that will have been installed in the step above (If you want to be able to copy/paste, see here. Going forward, this article assumes you will run all commands inside of the Ubuntu terminal
  2. Install Docker Desktop (these instructions were tested using Docker 4.9.0 on June 13th, 2022)
  3. Install homebrew `
@erikhansen
erikhansen / _README.md
Last active July 28, 2023 02:08
MacOS Automator Script to export list of on-premise Jira issues to PDF

Instructions

This document covers how to export Jira tickets to PDF from the on-premise version of Jira. For the cloud version of Jira, you can write a script to download Word versions of each issue (e.g., https://krakencommerce.atlassian.net/si/jira.issueviews:issue-word/DMC-95/DMC-95.doc) and you don't need this approach.

  1. Prepare a text file containing all urls of the Jira issues you want to export. For example:
https://krakencommerce.atlassian.net/browse/DMC-1
https://krakencommerce.atlassian.net/browse/DMC-2
@erikhansen
erikhansen / _readme.md
Last active April 17, 2023 11:42
Crawl Magento 1 / Magento 2 site for pricing

Overview

This basic script crawls a Magento 1 or Magento 2 website and logs the prices, SKUs, and product urls to a CSV file. This script was put togther for a company that had consent from the website(s) being scraped. Please use responsibility.

This script uses https://scrapy.org/

This script was tested on macOS Mojave, but it should run on any *NIX system.

You can tweak the body.css code to match the specific CSS selectors on the site you're crawling. See this documentation. When you're testing this script, refer to the command above the def parse_item line to learn how to run the code for only a single product.

@erikhansen
erikhansen / README.md
Last active February 28, 2023 13:59
Patch Magento 2 extension that must be installed in app/code

See also this alternative approach: https://gist.github.com/cmtickle/8900629447429126ffd7ff84e56ec780#to-patch-code-in-appcode

If you need to patch an M2 extension that isn't available to be installed via Composer, and you're concerned about losing edits directly to files in app/code/<Vendor> directory, you can install and then patch the extension locally using these steps:

  1. Copy the extension into an arbitrary folder location like app/code/packages/VendorName/ModuleName (this assumes this module has a composer.json file with the package name of vendorname/module-modulename)

  2. Run this command to add your custom package location to the composer repositories list:

    composer config repositories.vendorname/module-modulename path app/packages/VendorName/ModuleName
    
  3. Require the extension:

@erikhansen
erikhansen / sync_prod_to_stage.sh
Last active November 11, 2022 23:31
Magento 2 script to push DB and `pub/media` changes from prod>stage
#!/bin/bash
# stop on errors
set -e
# turn on debugging if you're running into issues
#set -x
# Static variables
ENVIRONMENT=$1
RED='\033[0;31m'
NC='\033[0m' # No Color
@erikhansen
erikhansen / daily_errors_report.sh
Last active August 2, 2021 11:41
Magento 2 - Send nightly error email, grouped and sorted by count
#!/bin/bash
# stop on errors
set -e
# turn on debugging if running into issues
#set -x
# This script sends a nightly email, showing errors, grouped and sorted by count.
# Getting these errors emailed can be especially useful for the first few weeks after launching a new Magento site.
# Assumptions: