Skip to content

Instantly share code, notes, and snippets.

<?php
Api::setConsumerKey($consumerKey);
Api::setConsumerSecret($consumerSecret);
$history = History::getList();
foreach ($history as $historyItem) {
$date = $historyItem->getDate();
$websiteUrls = $historyItem->getWebsiteNamesCsv();
Api::setConsumerKey($consumerKey);
Api::setConsumerSecret($consumerSecret);
$history = History::getList();
foreach ($history as $historyItem) {
$date = $historyItem->getDate();
$websiteUrls = $historyItem->getWebsiteNamesCsv();
$project = $historyItem->getProjectName();
SELECT
l.email as 'Email'
, MAX(l.created_at) as 'Last Viewed'
, group_concat(product_name.value) as 'Products'
, IFNULL(customer_firstname.value, 'Guest') as 'Customer Name'
FROM kj_bettervisitorlog_log AS l
LEFT JOIN sales_flat_order AS o ON o.customer_email = l.email AND o.created_at > l.created_at
LEFT JOIN customer_entity AS customer ON customer.email = l.email
LEFT JOIN customer_entity_varchar AS customer_firstname ON customer_firstname.attribute_id = 5
AND customer_firstname.entity_id = customer.entity_id
@kalenjordan
kalenjordan / repurchase-rate.sql
Last active January 1, 2016 20:59
Magento Repurchase Rate Note: This assumes you don't use guest checkout - if you do, you could probably group by customer_email and get relatively accurate results.
# The number of customers who haveve only purchased once from December 2012 to December 2013
SELECT customers_in_segment
FROM
(
SELECT count(*) AS customers_in_segment, order_count
FROM
(
SELECT customer_id, min(created_at) AS first_order_at, count(*) AS order_count
FROM sales_flat_order
@kalenjordan
kalenjordan / gist:7936461
Created December 12, 2013 22:09
Gmail images
Gmail: Hey, we're caching images now, it's more secure b/c suckas can't inject nastiness on you.
JS: Liars! You're totally making it sound like you're improving privacy by no longer allowing email marketers to track opens using images.
Gmail: But....all we said was we're improving security
JS: Now that's just splitting hairs!
@kalenjordan
kalenjordan / gist:7827914
Created December 6, 2013 16:39
Addon product

I'm trying to figure out what the best way is to implement what I'm calling an "addon product".

The way it works is that when a customer adds the Essentials Shakes to their cart, we want to prompt them to add a Shaker Bottle (it's like a bottle that makes it easy to make shakes) to their order as well for $5.

I would have used a grouped product for this, but you can't combine configurable and grouped products, plus there are issues with subscription orders as well.

So what I'm leaning towards now is maybe a modal that pops up after they add the Essentials to their cart which prompts them to add this other product to their cart.

Somebody has to have run into this use case before.

<?xml version="1.0"?>
<config>
<sections>
<system>
<groups>
<backup>
<fields>
<maintenance>
<comment>supercalifrag</comment>
</maintenance>
@kalenjordan
kalenjordan / autoloader-benchmark.php
Last active December 25, 2015 00:49
Autoloading benchmark - loads ~1k classes in order to benchmark the autoloader. I've used this to compare with and without the AOE ClassPathCache autoloader.
<?php
require_once(dirname(__FILE__) . '/../app/Mage.php');
Mage::app('admin');
$classesRaw = file_get_contents(dirname(__FILE__) . '/data/classes.txt');
$classes = explode("\n", $classesRaw);
echo "Loading " . count($classes) . " classes\r\n";
@kalenjordan
kalenjordan / mass-copyright-replace.sh
Last active December 24, 2015 07:49
Change copyright from 2013 to 2012
@kalenjordan
kalenjordan / gist:6731541
Last active December 24, 2015 02:38
Unique 404's
grep "HTTP\/...\" 404" nginx-access.log | awk '{ print $16}' | sort | uniq