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 / bulu-customers-who-havent-completed-profiles.sql
Created January 25, 2014 16:41
Find all the customers that have a customer attribute set to 0 or NULL
SELECT cv.value as `profile_complete`, e.* FROM customer_entity AS e
LEFT JOIN customer_entity_varchar AS cv
ON ( cv.attribute_id = (
SELECT attribute_id FROM eav_attribute
WHERE entity_type_id = e.entity_type_id
AND attribute_code = 'profile_complete'
)
AND cv.entity_id = e.entity_id)
WHERE cv.value IS NULL OR cv.value = 0
@tegansnyder
tegansnyder / manual-dataflow-profile.php
Created January 28, 2014 17:23
Running a Magento Dataflow profile manually
<?php
/*
Author: Tegan Snyder <tsnyder@tegdesign.com>
Example of running a Dataflow profile via command line
you can change the profile_id to the one you want to
run and issue:
time php manual-dataflow-profile.php
note you may need to increase the memory_limit in php cli's php_cli.ini
RHEL linux copy /etc/php.ini to /etc/php_cli.ini and make changes there then restart Apache.
@tegansnyder
tegansnyder / product-url-retrieve.sql
Created January 28, 2014 20:12
Getting a product URL path by SQL in Magento Enterprise 1.13.0.1
SELECT b.request_path FROM enterprise_catalog_product_rewrite a
INNER JOIN enterprise_url_rewrite b ON b.url_rewrite_id = a.url_rewrite_id
WHERE a.product_id = 19745
@tegansnyder
tegansnyder / get-product-thumbnail-name-url-key-1.13.0.1.sql
Created January 28, 2014 21:36
Get product thumbnail, product_name, and url key in Magento Enterprise 1.13.0.1 direct sql.
SELECT b.value AS thumbnail,
b.entity_id,
e.request_path,
f.value AS product_name
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
INNER JOIN enterprise_catalog_product_rewrite d ON d.product_id = a.entity_id
INNER JOIN enterprise_url_rewrite e ON e.url_rewrite_id = d.url_rewrite_id
INNER JOIN catalog_product_entity_varchar f ON f.entity_id = a.entity_id
@tegansnyder
tegansnyder / solr-extension-php-rhel.sh
Created January 29, 2014 16:11
Steps to install the SOLR PHP extension on RHEL. Installation is a little trickery because of how curl is built into PHP as a shared library and not statically compiled.
# install dependencies
sudo yum install curl-devel
sudo yum install libxml2-devel
# install extension for solr -- note use pear instead of pecl install
sudo pear install pecl/solr
# when it asks for libcURL path if you are on a 64bit machine
# change:
libcURL install prefix [/usr] : /usr/lib64
@tegansnyder
tegansnyder / Magento-Average-Orders-Average-Discounts-Totals-by-Month-Year.sql
Created January 31, 2014 02:41
Magento get average order, discount, item count, and order amount break down by month and year with direct SQL
SELECT sub_query.month_ordered,
sub_query.year_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,
@tegansnyder
tegansnyder / Magento-new-customer-sales-by-month-year.sql
Created January 31, 2014 02:43
Magento - New Customer Sales Averages and Totals by Month and Year - direct sql
SELECT sub_query.month_ordered,
sub_query.year_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,
@tegansnyder
tegansnyder / Magento-purchases-per-year.sql
Created January 31, 2014 02:49
Magento - Purchases Per Year (PPY) - Direct SQL
SELECT AVG(order_cnt) AS ppy
FROM
(SELECT customer_id,
COUNT(customer_id) AS order_cnt
FROM
(SELECT so.customer_id,
YEAR(so.created_at) AS year_ordered,
group_concat(si.sku SEPARATOR ',') AS skus
FROM `sales_flat_order` AS so
INNER JOIN `sales_flat_order_item` AS si ON si.order_id=so.entity_id
@tegansnyder
tegansnyder / magento-average-cart-purchase-acp-all-time.sql
Created January 31, 2014 02:57
Magento - All time Average Cart Purchase value via direct SQL
SELECT AVG(average_base_subtotal) AS acp
FROM
(SELECT AVG(sub_query.base_subtotal) AS average_base_subtotal
FROM
(SELECT so.base_subtotal
FROM `sales_flat_order` AS so
INNER JOIN `sales_flat_order_item` AS si ON si.order_id=so.entity_id
GROUP BY entity_id) AS sub_query) AS sub_query
@tegansnyder
tegansnyder / Magento-order-sum-breakout-report.sql
Created January 31, 2014 15:41
Magento - Sum of All Orders by Month and Year Breakdown includes Discount Sums
SELECT sub_query.month_ordered,
sub_query.year_ordered,
SUM(sub_query.base_subtotal) AS sum_base_subtotal,
SUM(sub_query.discount_amount) AS sum_discount_amt,
SUM(sub_query.order_qty) AS sum_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,