Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
GreatPotato / gist:987d389b2f2d18a7361b
Created February 4, 2015 15:05
Get incorrect timezone payments from PayPal
SELECT DateTime, `Time Zone`, Name, Currency, Gross, `Transaction ID`, Type
FROM transactions
WHERE TIME(DateTime) BETWEEN '00:00:00' AND '00:59:59'
AND (Type = 'Website Payments Pro API Solution' OR Type = 'Shopping Cart Payment Received')
AND `Time Zone` = 'BST'
AND DateTime > '2014-09-22 00:00:00'
@GreatPotato
GreatPotato / gist:9420178
Last active August 29, 2015 13:57
Add a $_FILES to Db_File
<?php
$file = Db_File::create();
$file->is_public = true;
$file->fromPost($_FILES['file']);
$file->master_object_class = 'Shop_OrderItem';
$file->save();
$item->files->add($file);
$item->save();
@GreatPotato
GreatPotato / gist:9366899
Created March 5, 2014 13:13
Customize flash messages in LemonStand
<?php
class Advantage {
public static function show_error()
{
if (array_key_exists('system', Phpr::$session->flash->flash))
{
$system_message = Phpr::$session->flash['system'];
@GreatPotato
GreatPotato / gist:8600713
Last active January 4, 2016 09:18
Total sales for category custom column
<?php
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onExtendCategoryModel', $this, 'extend_category_model');
}
public function extend_category_model($category, $context)
{
@GreatPotato
GreatPotato / gist:8600579
Last active January 4, 2016 09:09
Gets number of sales per category in LemonStand (paid orders only and supports products with multiple categories)
SELECT shop_categories.name, count(shop_order_items.id)*shop_order_items.quantity as 'total_sales'
FROM shop_order_items
LEFT JOIN shop_orders
ON shop_order_items.shop_order_id = shop_orders.id
LEFT JOIN shop_products
ON shop_order_items.shop_product_id = shop_products.id
LEFT JOIN shop_products_categories
ON shop_products.id = shop_products_categories.shop_product_id
@GreatPotato
GreatPotato / my_module.php
Last active January 4, 2016 05:39
Adds top spending and top ordering customers widget to the dashboard
public function listDashboardReports()
{
return array(
'top_customers_revenue'=>array('partial'=>'top_customers_revenue.htm', 'name'=>'Top spending customers'),
'top_customers_orders'=>array('partial'=>'top_customers_orders.htm', 'name'=>'Top ordering customers')
);
}
@GreatPotato
GreatPotato / gist:7928022
Last active December 31, 2015 03:29
Create basic breadcrumb with page blocks in LemonStand
// Create a page block called "breadcrumb"
<?php $category = isset($product) ? $product->categories[0] : null; ?>
<?php if($category): ?>
<?php foreach ($category->get_parents() as $parent): ?>
<li><a href="<?php echo $parent->page_url('/category') ?>"><?php echo h($parent->name); ?></a></li>
<?php endforeach; ?>
<li><a href="<?php echo $category->page_url('/category'); ?>"><?php echo h($category->name); ?></a></li>
<?php endif; ?>
@GreatPotato
GreatPotato / gist:7786948
Created December 4, 2013 12:47
Deploys and ebook into your page
var ebook_deploy = {
_cdn: '/',
_container: 'ebook',
_head: document.getElementsByTagName('head')[0],
_host: (("https:" == document.location.protocol) ? "https:" : "http:"),
init: function(container, cdn) {
@GreatPotato
GreatPotato / gist:7786746
Last active December 30, 2015 05:59
Minifys and escapes a HTML file ready for deploying via JS
<?php
class Ebook {
public $input = 'ebook.html';
public $output = 'ebook.min.html';
public function __construct($array)
{
@GreatPotato
GreatPotato / gist:7785541
Created December 4, 2013 10:37
Validate a VAT number
<?php
class vat
{
function check_vat($vat_no,$state_code)
{
$states = array(
27 => 'RO',
1 => 'AT',
2 => 'BE',
3 => 'BG',