Skip to content

Instantly share code, notes, and snippets.

@drewgillson
drewgillson / DG_tester
Created January 4, 2012 07:48
Lightweight Javascript testing tool
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery.cookie = function(name, value, options) {
// @author Klaus Hartl/[email protected]
if (typeof value != 'undefined') {
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
@drewgillson
drewgillson / customers.sql
Created January 6, 2012 07:08
Customer report from Magento
-- assuming Magento 1.6.1 data model
SELECT DISTINCT customer_email,
COUNT(*) AS purchases,
(SELECT LEFT(created_at,11) FROM `sales_flat_order` WHERE customer_email = a.customer_email ORDER BY created_at DESC LIMIT 0,1) AS last_purchase,
(SELECT COUNT(*) FROM sales_flat_order_item WHERE product_type = 'simple' AND sku LIKE '%IB%' AND order_id IN (SELECT entity_id FROM `sales_flat_order` WHERE customer_email = a.customer_email)) AS icebreaker,
(SELECT COUNT(*) FROM sales_flat_order_item WHERE product_type = 'simple' AND sku LIKE '%TNF%' AND order_id IN (SELECT entity_id FROM `sales_flat_order` WHERE customer_email = a.customer_email)) AS the_north_face,
(SELECT COUNT(*) FROM sales_flat_order_item WHERE product_type = 'simple' AND sku LIKE '%MHW%' AND order_id IN (SELECT entity_id FROM `sales_flat_order` WHERE customer_email = a.customer_email)) AS mountain_hardwear,
(SELECT COUNT(*) FROM sales_flat_order_item WHERE product_type = 'simple' AND sku LIKE '%MAR%' AND order_id IN (SELECT entity_id FROM `sales
@drewgillson
drewgillson / sproc_exportObjectToCSV.sql
Created March 3, 2012 04:02
An MSSQL stored procedure to export a table or view to CSV, with column headers, using BCP
/****** Object: StoredProcedure [dbo].[sproc_exportObjectToCSV] Script Date: 03/02/2012 21:00:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
@drewgillson
drewgillson / CustomerWishlist.sql
Created June 2, 2012 13:52
Magento customer wishlist report
SELECT b.email, c.value AS name, a.updated_at, d.added_at, d.product_id, e.name, SUM(g.qty_ordered) AS purchased
FROM `wishlist` AS a
INNER JOIN customer_entity AS b ON a.customer_id = b.entity_id
INNER JOIN customer_entity_varchar AS c ON a.customer_id = c.entity_id AND c.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'firstname' AND entity_type_id = b.entity_type_id)
INNER JOIN wishlist_item AS d ON a.wishlist_id = d.wishlist_id
INNER JOIN catalog_product_flat_1 AS e ON d.product_id = e.entity_id
LEFT JOIN sales_flat_order AS f ON f.customer_email = b.email
LEFT JOIN sales_flat_order_item AS g ON (f.entity_id = g.order_id AND g.sku LIKE CONCAT(e.sku,'%') AND g.product_type = 'simple')
GROUP BY b.email, c.value, a.updated_at, d.added_at, d.product_id, e.name
@drewgillson
drewgillson / Grid.php
Created June 10, 2012 17:40
Example - add custom columns to the Magento administration Catalog > Product grid
<?php
class Zyn_Common_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid {
protected function _prepareColumns() {
$this->addColumn('zyn_featured',
array(
'header'=> 'Show on Homepage',
'width' => '50px',
'index' => 'zyn_featured',
@drewgillson
drewgillson / Grid.php
Created June 10, 2012 17:47
Do not copy and paste this code - it won't work!
<?php
class Zyn_Common_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid {
protected function _prepareColumns() {
$this->addColumn('zyn_featured',
array(
'header'=> 'Show on Homepage',
'width' => '50px',
'index' => 'zyn_featured',
'type' => 'options',
@drewgillson
drewgillson / redirectReferer.php
Created June 14, 2012 17:46
Notes on Mage_Core_Controller_Varien_Action::_redirectReferer()
<input type="hidden" name="uenc" value="<?= Mage::helper('core')->urlEncode(Mage::app()->getStore()->getBaseUrl() . 'your_page_url_key') ?>"/>
@drewgillson
drewgillson / config.xml
Created June 28, 2012 05:01
Dg_Pricerulesextended config.xml
<?xml version="1.0"?>
<config>
<modules>
<Dg_Pricerulesextended>
<version>0.1</version><platform>ce</platform>
</Dg_Pricerulesextended>
</modules>
<global>
<models>
@drewgillson
drewgillson / observer.php
Created June 28, 2012 05:06
Dg_Pricerulesextended Observer.php
class Dg_Pricerulesextended_Model_Observer {
public function newsletterSubscriberSave(Varien_Event_Observer $observer) {
$helper = Mage::helper('pricerulesextended');
$subscriber = $observer->getEvent()->getSubscriber();
$email = $subscriber->getEmail();
$promo_value = Mage::getStoreConfig('pricerulesextended/promocode/dollarvalue');
$promo_min = Mage::getStoreConfig('pricerulesextended/promocode/minpurchase');
@drewgillson
drewgillson / GenerateController.php
Created June 28, 2012 05:07
Dg_Pricerulesextended GenerateController.php
class Dg_Pricerulesextended_GenerateController extends Mage_Core_Controller_Front_Action
{
public function promocodeAction() {
$helper = Mage::helper('pricerulesextended');
$params = $this->getRequest()->getParams();
$email = $params['email'];
$email = explode(',',$email);
$email = $email[0];