Skip to content

Instantly share code, notes, and snippets.

View cgi-caesar's full-sized avatar

Andrey Yerokhin cgi-caesar

View GitHub Profile
@cgi-caesar
cgi-caesar / site.php
Last active February 7, 2018 10:26
aMember (site.php): generate username based on customer full name
<?php
Am_Di::getInstance()->hook->add(Am_Event::GENERATE_LOGIN, function (Am_Event $e) {
$user = $e->getUser();
if ($_ = preg_replace('/[^0-9a-zA-Z]/', '', "{$user->name_f}{$user->name_l}")) {
$i = 1;
$l = $_;
while (!$e->getDi()->userTable->checkUniqLogin($l)) {
$l = $_ . $i++;
}
@cgi-caesar
cgi-caesar / functions.php
Created February 8, 2018 13:05
WordPress: remove admin bar for non admin users
<?php
add_action('after_setup_theme', function() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
});
@cgi-caesar
cgi-caesar / site.js
Last active March 5, 2018 12:58
aMember (site.js) UX for menu with many items
jQuery(function(){
var tolerance = 80;
var initialStep = 30;
var speed = 0.35;
var step = initialStep;
var w;
jQuery('.am-tabs-wrapper').css({
overflow: 'hidden'
@cgi-caesar
cgi-caesar / site.php
Last active March 5, 2018 10:49
aMember (site.php): sequential invoice numbers
<?php
function _get_my_number($record)
{
$prefix = $record instanceof InvoicePayment ? 'INV' : 'RFD';
$year = date('Y', amstrtotime($record->dattm));
$table = $record instanceof InvoicePayment ? '?_invoice_payment' : '?_invoice_refund';
$num = Am_Di::getInstance()->db->selectCell(<<<CUT
SELECT COUNT(*) + 1 FROM {$table}
@cgi-caesar
cgi-caesar / site.php
Created August 24, 2018 15:15
aMember (site.php): Allow to switch payment system on resume subscription
<?php
/**
* Allow to switch payment system on resume subscription
*/
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT, function(Am_Event $e) {
$invoice = $e->getInvoice();
if ($invoice->data()->get(Invoice::ORIG_ID) && !$invoice->data()->get('skip-me')) {
$invoice->data()->set('skip-me', 1);
@cgi-caesar
cgi-caesar / site.php
Last active July 29, 2019 07:36
aMember (site.php): Ability to clear invoice log from admin interface
<?php
/**
* Add new item to aMember CP -> Utilities -> Delete Old Records
*/
Am_Di::getInstance()->hook->add(Am_Event::CLEAR_ITEMS, function(Am_Event $e) {
$di = $e->getDi();
$e->addReturn([
@cgi-caesar
cgi-caesar / site.php
Last active July 1, 2019 09:46
aMember (site.php): change access period based on purchased quantity
<?php
/**
* Change access period based on purchased quantity
*/
Am_Di::getInstance()->hook->add(Am_Event::ACCESS_BEFORE_INSERT, function(Am_Event $e) {
$access = $e->getAccess();
if ($access->invoice_item_id && $access->expire_date != Am_Period::MAX_SQL_DATE) {
$item = $e->getDi()->invoiceItemTable->load($access->invoice_item_id);
@cgi-caesar
cgi-caesar / site.php
Last active September 14, 2018 08:14
aMember (site.php): Add 3 digit unique code to the product price
<?php
Am_Di::getInstance()->hook->add(Am_Event::INVOICE_CALCULATE, function(Am_Event $e) {
if (@$GLOBALS['add_fraction']++) return;
$invoice = $e->getInvoice();
$item = $invoice->getItem(0);
$id = $invoice->pk() ?: $e->getDi()->db->selectCell("SELECT MAX(invoice_id)+1 FROM ?_invoice;");
if ($item && $item->first_price > 0 && !$item->data()->get('add_fraction')) {
$item->data()->set('add_fraction', 1);
$item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + ($id % 1000));
@cgi-caesar
cgi-caesar / site.php
Created November 28, 2018 10:23
aMember (site.php): Add images for products within Active Subscriptions widget
<?php
/**
* This feature uses shopping cart module and its product images (cart view size)
*/
$di = Am_Di::getInstance();
if ($di->auth->getUser() && ($pids = $di->user->getActiveProductIds())) {
$di->view->headStyle()
@cgi-caesar
cgi-caesar / site.js
Last active June 2, 2020 15:46
aMember (site.js): switch input-text for quantity select with input-select
//@file application/configs/site.js
setTimeout(function(){
jQuery(function($){
$('.am-product-qty', '.am-signup-form').each(function(){
var s = $('<select class="am-product-qty">\
<option value="1">1</option>\
<option value="2">2</option>\
<option value="3">3</option>\
<option value="4">4</option>\