Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
GreatPotato / gist:1978941
Created March 5, 2012 15:52
Cloud SSL Infinite Redirection
<?php
/**
* Cloud load balancer sets these for us so we know we're secure,
* preventing LemonStand from performing a redirect loop.
**/
if( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' )
{
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}
@GreatPotato
GreatPotato / List unique attributes in category
Created May 31, 2012 16:06
Gets a list of attributes that are unique to the products in a given category
public static function list_unique_values_in_category($name, $category = NULL)
{
$category = (int) $category;
$values = Db_DbHelper::scalarArray('
SELECT DISTINCT value, t4.name
FROM shop_product_properties t1
LEFT JOIN shop_products_categories t3
ON t1.product_id = t3.shop_product_id
LEFT JOIN shop_categories t4
@GreatPotato
GreatPotato / gist:3225912
Created August 1, 2012 11:18
Set shipping method automatically in LemonStand
<?php
$default_method = Shop_ShippingOption::find_by_api_code('default');
Shop_CheckoutData::set_shipping_method($default_method->id);
?>
@GreatPotato
GreatPotato / ls_om_records.php
Last active October 8, 2015 06:58
Output LemonStand option matrix images
<?php
foreach($product->option_matrix_records as $option) {
foreach($option->images as $image) {
echo $image->getPath();
}
}
@GreatPotato
GreatPotato / ls_top_products
Last active July 3, 2017 15:58
Gets the 50 top selling products that cost over 15.00
SELECT t3.name, t3.sku, t3.price, count(t1.shop_product_id) AS "Number of orders"
FROM shop_order_items t1
LEFT JOIN shop_orders t2
ON t1.shop_order_id = t2.id
LEFT JOIN shop_products t3
ON t1.shop_product_id = t3.id
WHERE t2.payment_processed != ''
http://www.my-lemonstand-site.com/?show_page_structure
@GreatPotato
GreatPotato / average_shipping_quote.sql
Last active December 15, 2015 19:18
LemonStand average shipping quote per country
SELECT t2.name AS 'Country name', ROUND(AVG(t1.shipping_quote), 2) AS 'Average shipping price'
FROM shop_orders t1
LEFT JOIN shop_countries t2
ON t1.shipping_country_id = t2.id
WHERE t1.status_id != 1
GROUP BY(t2.name)
@GreatPotato
GreatPotato / most_sold_products.sql
Created April 12, 2013 13:23
Gets the top selling products in LemonStand
SELECT t2.sku, t2.name, t2.price, SUM(t1.quantity)
FROM shop_order_items t1
LEFT JOIN shop_products t2
ON t1.shop_product_id = t2.id
GROUP BY t2.id
@GreatPotato
GreatPotato / unsold.sql
Created April 12, 2013 13:49
Get LemonStand products which have never been sold
SELECT t2.id, t2.sku, t2.name, t2.price
FROM shop_products t2
WHERE NOT EXISTS (SELECT * FROM shop_order_items t1 WHERE t1.shop_product_id=t2.id)
@GreatPotato
GreatPotato / gist:5445303
Last active July 27, 2016 11:00
Gets the security details of a LS installation (including encryption key)
<?php
print_r( Phpr_SecurityFramework::create()->get_config_content() );
?>