Skip to content

Instantly share code, notes, and snippets.

{
"head":{
"udid": "UDIDBYJAMES",
"api_key": "test123",
"api_token": "test123"
},
"body":{
"order_id": "20300",
"transaction_id": "PAY-69X87306BF709670NKUABN4Q"
}
public function process_paypal_ipn($params)
{
try
{
$order = null;
/*
* Find order and load paypal settings
*/
@GreatPotato
GreatPotato / gist:61460869f5eb03f02444
Created February 4, 2015 15:11
Convert PayPal Date/Time fields into MySQL DateTime
UPDATE transactions
SET DateTime = CAST(CONCAT(STR_TO_DATE(Date,'%d/%m/%Y'), ' ', Time) AS DateTime)
@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; ?>