Skip to content

Instantly share code, notes, and snippets.

View tegansnyder's full-sized avatar
💭
Stay'n cold in Minnesota

Tegan Snyder tegansnyder

💭
Stay'n cold in Minnesota
View GitHub Profile
@tegansnyder
tegansnyder / clv-less-than.sql
Last active January 2, 2016 20:59
Customers who purchased less than $100 in product
SELECT COUNT(entity_id) as num_custs FROM (
SELECT entity_id
FROM `sales_flat_order`
GROUP BY customer_email
HAVING SUM(base_subtotal) < 100
) sub_query
@tegansnyder
tegansnyder / clv.sql
Created January 10, 2014 19:01
Magento CLV breakdown by months
SELECT sub_query.month_ordered,
AVG(sub_query.base_subtotal) AS average_base_subtotal,
AVG(sub_query.discount_amount) AS average_discount_amt,
AVG(sub_query.order_qty) AS average_total_item_count,
COUNT(sub_query.entity_id) AS total_orders
FROM
(SELECT so.entity_id,
MONTH(so.created_at) AS month_ordered,
YEAR(so.created_at) AS year_ordered,
so.base_subtotal,
@tegansnyder
tegansnyder / disable-all-extensions-and-theme.sh
Last active January 3, 2016 09:59
Reverting Magento to it's stock form. Disabling all extensions and current theme for testing purposes.
# define your Mage install directory
MAGENTO_ROOT=/var/www/beep/us
THEME_BASE=enterprise
CURRENT_THEME=global_base
# create directory to hold existing extension configs
mkdir $MAGENTO_ROOT/app/etc/modules_backup
mkdir $MAGENTO_ROOT/app/etc/modules_backup/stock_magento
# copy all stock Magento configs to stock_magento folder
@tegansnyder
tegansnyder / MageStocker.sh
Last active June 7, 2017 11:14
MageStocker - Convert your Magento to stock disabling all extensions and your theme. Allows you to switch it back when you are done testing brining your theme and extensions back to life.
#! /bin/bash
if [ "$#" == "0" ]; then
echo
echo "Sorry cant run!"
echo "No arguments provided. Please pass this script agruments in the following format:"
echo "./magestocker.sh magento_root theme_base current_theme_name"
echo "example: "
echo "./magestocker.sh /var/www/magento default mytheme"
echo "another example:"
@tegansnyder
tegansnyder / attributes-products-csv.php
Last active January 3, 2016 11:49
Example of producing a CSV of Magento product attributes with direct SQL for speed
<?php
require_once('app/Mage.php');
umask(0);
Mage::app('default');
$db_conn = Mage::getSingleton('core/resource');
$r_conn = $db_conn->getConnection('core_read');
@tegansnyder
tegansnyder / find-products-without-images.sql
Created January 16, 2014 21:58
Magento - finding products without images. Raw SQL.
SELECT *
FROM `catalog_product_entity` AS a
LEFT JOIN `catalog_product_entity_media_gallery` AS b ON a.entity_id = b.entity_id
WHERE b.value IS NULL
@tegansnyder
tegansnyder / get-images-for-sku.sql
Created January 16, 2014 22:05
Get images and position for a specific sku with direct SQL Magento
SELECT a.sku, b.value, c.position
FROM `catalog_product_entity` AS a
LEFT JOIN `catalog_product_entity_media_gallery` AS b ON a.entity_id = b.entity_id
INNER JOIN `catalog_product_entity_media_gallery_value` AS c ON c.value_id = b.value_id
WHERE a.sku = 98044057168
@tegansnyder
tegansnyder / grab-all-product-attributes.sql
Created January 20, 2014 15:29
Magento grab all product attributes for a SKU in direct SQL. "static" backend_type attributes are stored in catalog_product_entity
SELECT * FROM ( SELECT
ce.sku,
ea.attribute_id,
ea.attribute_code,
CASE ea.backend_type
WHEN 'varchar' THEN ce_varchar.value
WHEN 'int' THEN ce_int.value
WHEN 'text' THEN ce_text.value
WHEN 'decimal' THEN ce_decimal.value
WHEN 'datetime' THEN ce_datetime.value
@tegansnyder
tegansnyder / export-all-product-attributes.php
Last active November 22, 2018 15:31
Really rough around the edge way (not complete) way to grab all product attributes to a csv with direct SQL in Magento. Don't trust this worth your life :)
<?php
/**
* export-all-product-attributes.php
* @author Tegan Snyder <tsnyder@tegdesign.com>
*/
// init Magento
require_once('app/Mage.php');
umask(0);
Mage::app('default');
@tegansnyder
tegansnyder / create-admin-user.php
Created January 22, 2014 15:46
Create admin user programmatically
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
umask(0);
Mage::app();
try {
$user = Mage::getModel('admin/user')
->setData(array(