Skip to content

Instantly share code, notes, and snippets.

@GreatPotato
GreatPotato / gist:5452745
Last active December 16, 2015 14:59
Gets the best selling products in a LemonStand category
<?php
$obj = new Shop_Product();
$obj->select('count(shop_order_items.id) AS "sold"');
$obj->join('shop_products_categories', 'shop_products.id = shop_products_categories.shop_product_id');
$obj->join('shop_order_items', 'shop_products.id = shop_order_items.shop_product_id');
$obj->join('shop_orders', 'shop_order_items.shop_order_id = shop_orders.id');
$best_selling = $obj->where('shop_products_categories.shop_category_id=? AND shop_orders.payment_processed IS NOT NULL', $category->id)->group('shop_products.id')->order('count(shop_order_items.id) DESC')->limit(3)->find_all();
@GreatPotato
GreatPotato / gist:5460059
Last active December 16, 2015 15:59
Shows the LS loading indicator
window.Phpr.showLoadingIndicator({
loadIndicator: {
overlayClass: 'ajax_loading_indicator',
zIndex: 9999,
html: '<span>Loading...</span>'
}
});
@GreatPotato
GreatPotato / gist:5532070
Last active December 17, 2015 01:58
Extend model with calculated column
<?php
class My_Module extends Core_ModuleBase
{
protected function createModuleInfo()
{
return new Core_ModuleInfo(
'Extend model with calculated column',
'Adds "Total Orders" and "Total Spend" columns to a customer - useful for marketing purposes',
'GreatPotato'
@GreatPotato
GreatPotato / gist:5539870
Created May 8, 2013 11:30
Displays a different theme in Chrome for LemonStand (useful for development)
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome'))
return true;
return false;
@GreatPotato
GreatPotato / gist:5568560
Last active December 17, 2015 06:49
Add total order weight to the order model/form (useful if you use UPS shipping or another shipping method that relies on order weight).
<?php
public function subscribeEvents()
{
Backend::$events->addEvent('shop:onExtendOrderModel', $this, 'extend_order_model');
Backend::$events->addEvent('shop:onExtendOrderForm', $this, 'extend_order_form');
}
public function extend_order_model($order, $context)
{
<?php
function gp_empty_paragraph_fix($content) {
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr($content, $array);
return $content;
@GreatPotato
GreatPotato / gist:5766738
Created June 12, 2013 16:07
Get a list of all font awesome icons
<?php
$pattern = '/\.(icon-(?:\w+(?:-)?)+):before\s+{\s*content:\s*"(.+)";\s+}/';
$subject = file_get_contents('css/font-awesome.css');
preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER);
$icons = array();
echo '<ul>';
@GreatPotato
GreatPotato / gist:5959098
Created July 9, 2013 16:58
Gets the current currency in use for LemonStand
<?php
$obj = new Shop_CurrencySettings;
$obj = $obj::get();
$currency = $obj->sign;
@GreatPotato
GreatPotato / gist:6163423
Created August 6, 2013 10:29
Search by custom column in the backend order search
<?php
public function subscribeEvents()
{
Backend::$events->addEvent('backend:onControllerReady', $this, 'on_backend_controller_ready');
}
public function on_backend_controller_ready($controller)
{
$controller->list_search_fields[] = 'x_custom_column';
@GreatPotato
GreatPotato / gist:6534738
Created September 12, 2013 08:59
Override the default error handling in LemonStand
window.Phpr.response.popupError = window.LS.response.popupError = function(message) {
console.log(message);
}