Skip to content

Instantly share code, notes, and snippets.

View sprankhub's full-sized avatar

Simon Sprankel sprankhub

View GitHub Profile
@odewahn
odewahn / error-handling-with-fetch.md
Last active February 27, 2024 09:56
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@alankent
alankent / pkglist.php
Created May 13, 2016 04:59
Connect to Magento 2 Composer repo and list packages you can access
<?php
/**
* Return the path of the auth.json file.
*/
function findAuthJson() {
// Windows sets HOMEDRIVE and HOMEPATH, but cygwin sets HOME.
if (!isset($_SERVER["HOME"]) && isset($_SERVER["HOMEDRIVE"])) {
@jonathansayag
jonathansayag / magento-delete-attribute-options.php
Last active March 28, 2019 17:48
Magento PHP script to delete all values of an attribute
<?php
$attribute_code = 'ATTRIBUTE_NAME';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = $attribute->getSource()->getAllOptions();
$optionsDelete = array();
foreach($options as $option) {
if ($option['value'] != "") {
$optionsDelete['delete'][$option['value']] = true;
@schmengler
schmengler / SSE_FormFiller Bookmarklets.md
Last active June 27, 2019 11:47
Bookmarklets: Fill Magento forms with data powered by Faker.js

These bookmarklets allow you to use the scripts of SSE_FormFiller in any Magento installation without having to install the extension.

  1. Load FormFiller:

     javascript:(function%20(){document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).src='https://cdnjs.cloudflare.com/ajax/libs/Faker/0.7.2/MinFaker.js';document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).src='https://rawgit.com/schmengler/FormFiller/master/js/sse/formfiller.js';}());
    
  2. Fill billing form:

     javascript:formFiller.fill(billingForm.form)
    
@avoelkl
avoelkl / gist:49563c516d6cb318eb34
Last active November 17, 2020 07:41
Non-blocking and quick database dumps for large databases

How-to

Add --single-transaction and --quick to your mysqldump command.

--single-transaction

sets the isolation mode to REPEATABLE READ and starts a transaction before dumping data. useful for InnoDB tables, dumps the consistent state without blocking any applications.

--quick

@renttek
renttek / 0001-BUGIFX-Magento-Zend-Framework-1-PHP5.6.patch
Last active July 5, 2021 17:42
Bugfix for Zend Framework 1 in Magento (>= 1.7.*.*) + PHP 5.6
From 473846959772d8160b34b92ae3bcecddf24b972f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Julian=20Nu=C3=9F?= <julian.nuss@outlook.com>
Date: Tue, 23 Sep 2014 21:07:29 +0200
Subject: [PATCH 1/1] [BUGIFX] Zend Framework 1 + PHP5.6
---
lib/Zend/Locale/Format.php | 22 +++++++++++-----------
lib/Zend/Service/Audioscrobbler.php | 6 +++---
lib/Zend/Service/Technorati.php | 6 +++---
lib/Zend/Validate/Hostname.php | 4 ++--
@loopool
loopool / magento-delete-test-data.sql
Last active December 7, 2015 10:42
Remove all products,categories,customers,orders,logs from magento database
SET FOREIGN_KEY_CHECKS=0;
-- Delete all products
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
@markshust
markshust / gist:2cee3dd991bafc90e161
Created July 30, 2014 14:44
Search Magento local codePool for invalidly formatted XML
find app/code/local/ -type f -name "*.xml" -exec xmllint --noout {} \;
@reidblomquist
reidblomquist / gist:aa9df1581a7ee8c82910
Last active August 19, 2021 14:41
Force cancel orders in Magento
The following SQL queries should set an orders status to canceled:
UPDATE sales_flat_order SET state = 'canceled', status = 'canceled' WHERE increment_id IN (order#1,order#2,etc);
UPDATE sales_flat_order_grid SET status = 'canceled' WHERE increment_id IN (order#1,order#2,etc);
@erfanimani
erfanimani / .gitignore
Last active June 1, 2019 10:22
A refactored and modern .gitignore for Magento. Compatible for Git versions 2.7.0+. See this revision to use it for versions lower than 2.7.0: https://gist.github.com/erfanimani/8856964/886f5d79d229c21b9c712155c362e5fc1c61a12a
### MAGENTO DIRECTORIES
# Ignore everything in media, except for the htaccess files
# Also include the Lazy Catalog Images (LCI) .htaccess if that's installed
# (https://github.com/AOEpeople/Aoe_LazyCatalogImages)
/media/*
!/media/.htaccess
!/media/customer/.htaccess
!/media/downloadable/.htaccess
!/media/catalog/product/LCI/.htaccess