Tegan Snyder tegansnyder

View Table.php
1 2 3 4 5 6 7 8 9 10
<?php
 
/**
* Optimized version of attribute source options model
*
* That allows to preload options once and reuse them instead of doing calls to db all the time
*
*/
class EcomDev_Optimization_Model_Resource_Attribute_Source_Table
extends Mage_Eav_Model_Entity_Attribute_Source_Table
View CustomerWishlist.sql
1 2 3 4 5 6 7 8 9
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
View average-orders-per-customer.sql
1 2 3
SELECT AVG(num_orders) FROM (
SELECT COUNT(customer_id) as num_orders, customer_id FROM sales_flat_order
GROUP BY customer_id) as sub
View no-results-search-breakdown.sql
1 2 3 4 5 6 7 8 9 10
SELECT COUNT(query_id) AS no_results_count,
y,
m
FROM
(SELECT cq.query_id,
MONTH(cq.updated_at) AS m,
YEAR(cq.updated_at) AS y
FROM catalogsearch_query cq
WHERE cq.num_results = 0
ORDER BY cq.popularity DESC) sub_query
View exportCats.php
1 2 3 4 5 6 7 8 9
<?php
 
require_once 'app/Mage.php';
Mage::app();
 
 
$x = 0;
$categories = array();
$csv = array();
View magento-code-snippets.md

Magento Code Snippets

Download extension manually using mage

./mage config-set preferred_state stable
./mage clear-cache
./mage sync
./mage download community Module_Name
View translation-helpers.sh
1 2 3 4 5 6 7 8 9 10
echo "Community Namespace"
echo "------------------------------------------"
cd app/code/community
for i in $(ls -d */)
do
echo ${i%%/} && fgrep -Rho --include='*.php' '__(' ${i%%/} | wc -l
done
echo
echo "Local Namespace"
echo "------------------------------------------"
View get-customer-names.sql
1 2 3 4 5 6 7 8 9 10
SELECT `e`.*,
`at_prefix`.`value`
AS `prefix`,
`at_firstname`.`value`
AS `firstname`,
`at_middlename`.`value`
AS `middlename`,
`at_lastname`.`value`
AS `lastname`,
`at_suffix`.`value`
View base_image.php
1 2 3 4 5 6 7
<?php
require_once('app/Mage.php');
umask(0);
Mage::app();
$product = Mage::getModel('catalog/product')->load(1);
echo Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage());
View array_2_csv.php
1 2 3 4 5 6 7 8 9
<?php
 
$arr = array();
$arr[0]['derp'] = 'hi';
$arr[0]['blerg'] = 'hey';
 
produceCSV('data.csv', $arr);
 
function produceCSV($file_name, $arr) {
Something went wrong with that request. Please try again.