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 / changeAttributeSetImport.php
Last active December 31, 2015 21:49
Example of importing skus and changing attribute sets.
<?php
/**
* changeAttributeSetImport.php
* Allows you to change the attribute set for a list of skus
*
* @author Tegan Snyder <tsnyder@mmm.com>
*/
/*
Preparing your file:
@tegansnyder
tegansnyder / n98-urls-to-csv.php
Last active January 1, 2016 08:19
Format the output of the n98-magerun.phar config:get web/ to a csv
<?php
/*
n98-magerun url formater to CSV
usuage: n98-magerun.phar config:get web/ | php n98-urls-to-csv.php > csv-of-urls.csv
*/
$str = stream_get_contents(fopen("php://stdin", "r"));
$str = str_replace("+","",$str);
@tegansnyder
tegansnyder / GetSkusInCategory.php
Created December 30, 2013 17:13
Get a list of skus in a category ID comma separated in Magento
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('default');
$cat_id = 2117;
$skus = array();
@tegansnyder
tegansnyder / CategoryTreePathExportMagento.php
Last active December 3, 2020 15:31
Export Category Tree and Paths for Magento
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
require_once MAGENTO . '/app/Mage.php';
Mage::app();
$category = Mage::getModel ('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
rsync -chavzP --exclude='path/to/installation/var/cache' --exclude='path/to/installation/.git' --exclude='path/to/installation/media/catalog/product/cache' --exclude='path/to/installation/var/tmp' --exclude='path/to/installation/var/session' --exclude='kiboots/var/report' --stats username@host:path/to/installation /destination/path
@tegansnyder
tegansnyder / upgrade-php-mysql-centos-64.sh
Created January 8, 2014 02:27
Updating PHP from PHP Version 5.3.3 to 5.4.23 (and MySQL to 5.5.35) on Digital Ocean x64 Centos 6.4 base image.
# in case you just did a yum install of mysql and php and need to upgrade use the remi repo
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm
yum --enablerepo=remi upgrade php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml
@tegansnyder
tegansnyder / skus-with-category_ids.sql
Created January 8, 2014 03:18
Get list of skus and their corresponding category_ids with direct SQL Magento.
SELECT sku, GROUP_CONCAT(entity_id) as category_ids FROM (
SELECT c3.sku, c2.entity_id
FROM catalog_category_product c1
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id)
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id)
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3)
) main
GROUP BY sku
@tegansnyder
tegansnyder / Purchases-By-Category.sql
Created January 9, 2014 15:50
Purchases by Category ID in Magento direct SQL
## change c2.entity_id to category id
SELECT c3.sku, si.created_at as purchase_date, increment_id
FROM catalog_category_product c1
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id)
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id)
INNER JOIN sales_flat_order_item si ON (si.product_id = c3.entity_id)
INNER JOIN sales_flat_order so ON (so.entity_id = si.order_id)
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3)
AND c2.entity_id = 2117
@tegansnyder
tegansnyder / Sales-by-category.sql
Created January 9, 2014 16:00
Finding the category that has the most sales in Magento
SELECT cat_id, SUM(row_total) as total_sales_by_cat, cv.value FROM (
SELECT c2.entity_id as cat_id, si.row_total
FROM catalog_category_product c1
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id)
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id)
INNER JOIN sales_flat_order_item si ON (si.product_id = c3.entity_id)
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3)
ORDER BY si.created_at DESC
) main
INNER JOIN catalog_category_entity_varchar cv ON (cv.entity_id = cat_id)