Skip to content

Instantly share code, notes, and snippets.

@trabulium
trabulium / CustomerWishlist.sql
Last active December 17, 2015 08:58 — forked from drewgillson/CustomerWishlist.sql
Customer Wishlist including lastname, price, sku
SELECT b.email, c.value AS name,d.value as lastname, a.updated_at, e.added_at, e.product_id, f.sku, f.name, f.price, SUM(h.qty_ordered) AS purchased
FROM `mage_wishlist` AS a
INNER JOIN mage_customer_entity AS b ON a.customer_id = b.entity_id
INNER JOIN mage_customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM mage_eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id)
INNER JOIN mage_customer_entity_varchar AS d ON a.customer_id = d.entity_id AND d.attribute_id = (SELECT attribute_id FROM mage_eav_attribute WHERE attribute_code = 'lastname' AND entity_type_id = b.entity_type_id)
INNER JOIN mage_wishlist_item AS e ON a.wishlist_id = e.wishlist_id
INNER JOIN mage_catalog_product_flat_1 AS f ON e.product_id = f.entity_id
LEFT JOIN mage_sales_flat_order AS g ON g.customer_email = b.email
LEFT JOIN mage_sales_flat_order_item AS h ON (g.entity_id = h.order_id AND h.sku LIKE CONCAT(f.sku,'%') AND h.product_type = 'simple')
GROUP
@trabulium
trabulium / sql_product_options_titles
Created July 8, 2013 23:47
Magento: Export of Product Options to assist converting to configurables
SELECT DISTINCT `main_table`.*,
`product_option`.`product_id` AS `entity_id`,
`product_option`.`option_id` AS `option_id`,
`store_value_title`.`title` AS `store_title`,
`default_value_id`.`option_type_id` AS `default_value_type_id`,
`default_value_title`.`title` AS `default_title`
FROM `catalog_product_entity` AS `main_table`
INNER JOIN `catalog_product_option` AS `product_option`
ON product_option.product_id = main_table.entity_id
@trabulium
trabulium / orderCreate.php
Created November 17, 2013 22:51
Magento: Create Order from a Previous Order Programmatically
<?php
define('MAGENTO_ROOT', "/var/www/web");
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
@trabulium
trabulium / gist:7796744
Created December 4, 2013 22:26
Basic Magento Varnish default.vcl for use with Phoenix Varnish
# This is a basic VCL configuration file for PageCache powered by Varnish for Magento module.
# default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "8000";
.first_byte_timeout = 300s;
}
# add your Magento server IP to allow purges from the backend
@trabulium
trabulium / closeOrders.php
Created January 22, 2014 01:42
Close Magento Orders - it's a once off thing. Don't really care about repercussions.
// Instantiate Magento
define('MAGENTO_ROOT', "shop");
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::init();
//$orderIds = array('100006363');
//
@trabulium
trabulium / Reset Stock Status as in Stock
Created May 30, 2016 00:43
Bulk Set Magento Stock Status as True
define('MAGENTO_ROOT', "/path/to/magento");
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
Mage::app()->getStore()->setId(0);
#Convert local timezone DB to AWS
UPDATE customer_entity SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), updated_at = CONVERT_TZ(updated_at,'-10:00','UTC');
UPDATE sales_flat_order SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), updated_at = CONVERT_TZ(updated_at,'-10:00','UTC');
UPDATE sales_flat_order_grid SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), updated_at = CONVERT_TZ(updated_at,'-10:00','UTC');
UPDATE sales_flat_invoice SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), updated_at = CONVERT_TZ(updated_at,'-10:00','UTC');
UPDATE sales_flat_invoice_grid SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), order_created_at = CONVERT_TZ(order_created_at,'-10:00','UTC');
UPDATE sales_flat_shipment SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), updated_at = CONVERT_TZ(updated_at,'-10:00','UTC');
UPDATE sales_flat_shipment_grid SET created_at = CONVERT_TZ(created_at,'-10:00','UTC'), order_created_at = CONVERT_TZ(order_created_at,'-10:00','UTC');
#Convert AWS (UTC
@trabulium
trabulium / IP Scrapers
Last active October 13, 2016 01:46
List of IP's scraping Magento sites with Fake User agent
131.161.8.0/24
131.161.10.0/24
131.161.9.0/24
131.161.11.0/24
131.161.9.253
131.161.9.252
131.161.9.251
131.161.9.250
@trabulium
trabulium / categoryToAttribute.php
Created October 20, 2016 04:39
Convert a set of Magento categories to Multi-Select Attributes.
<?php
/* Mage Australia - 2016-06-20 -
Finds Categories that match multiselect
attribute and saves the product as that style
*/
require_once '../app/Mage.php';
umask(0);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
select sfo.customer_id, cg.customer_group_code, customer_firstname, customer_lastname, customer_email, street, city, region, postcode, country_id, sfoi.type, sfoi.sku, sfoi.name, sfoi.qty_ordered
FROM sales_flat_order as sfo
LEFT JOIN sales_flat_order_address sfoa on (sfo.entity_id = sfoa.parent_id)
LEFT JOIN (SELECT order_id, GROUP_CONCAT(product_type, '\n') as type, GROUP_CONCAT(sku, "\n") as sku, GROUP_CONCAT(name, "\n") as name, GROUP_CONCAT(qty_ordered, "\n") as qty_ordered from sales_flat_order_item GROUP BY order_id) as sfoi on sfo.entity_id = sfoi.order_id
LEFT JOIN customer_group as cg on (sfo.customer_group_id = cg.`customer_group_id`)
WHERE `sfoa`.`address_type` = "shipping"
ORDER BY customer_id ASC;