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
Created July 10, 2020 12:00
aMember (site.php): Affiliate autocomplete without full access to affiliate module
<?php
Am_Di::getInstance()->router->addRoute('aff-autocomplete', new Am_Mvc_Router_Route('aff/admin/autocomplete', [
'module' => 'default',
'controller' => 'admin-aff-autocomplete',
'action' => 'index',
]));
class AdminAffAutocompleteController extends Am_Mvc_Controller
{
@cgi-caesar
cgi-caesar / site.php
Last active September 9, 2020 10:32
aMember (site.php): Different Menu for member and affiliate
<?php
//replace standard menu with affiliate specific if currently logged in user is affiliate
$di = Am_Di::getInstance();
if ($di->auth->getUserId() && $di->auth->getUser()->is_affiliate) {
$n = new Am_Navigation_User();
$n->addMenuPages('_aff');
$di->setService('navigationUser', $n);
}
@cgi-caesar
cgi-caesar / site.php
Last active October 13, 2020 12:08
aMember (site.php): Add Filter {Active|Expired|All} for invoices on payment history page
<?php
// Add Filter {Active|Expired|All} for invoices on payment history page
Am_Di::getInstance()->blocks->add(
'member/payment-history/top',
new Am_Block_Base(null, 'inv-filter', null, function(Am_View $v) {
$user = $v->di->user;
$ids = $v->di->db->selectCol(<<<CUT
@cgi-caesar
cgi-caesar / site.php
Last active November 4, 2020 15:27
aMember (site.php): Add CSRF token to login form
<?php
function _csrf_hash($tm)
{
$sesid = Am_Di::getInstance()->session->getId();
$id = 'login';
return Am_Di::getInstance()->security->hash("{$tm}:{$id}:{$sesid}", 10);
}
function _csrf_token()
@cgi-caesar
cgi-caesar / site.php
Created December 25, 2020 08:47
aMember (site.php): Hide sidebar for some products in shopping cart catalogue
<?php
Am_Di::getInstance()->productTable->customFields()
->add(new Am_CustomFieldSingle_Checkbox('remove_sidebar', 'Remove Sidebar?'));
Am_Di::getInstance()->front->registerPlugin(new class extends Zend_Controller_Plugin_Abstract {
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($request->getModuleName() == 'cart'
&& $request->getControllerName() == 'index'
@cgi-caesar
cgi-caesar / README.md
Last active March 4, 2021 13:42
Pay As You Wish (Above Product Price)

Pay As You Wish (Above Product Price)

  • Add Product brick
  • Add donation Brick for each product that you want user can choose price for
  • Add JavScript brick with code (you need to correct map array to map products to donation bricks)
  • Add Code to site.php
@cgi-caesar
cgi-caesar / site.php
Last active March 12, 2021 15:46
aMember (site.php): extend standard filter for payments grid
<?php
Am_Di::getInstance()->hook->add('gridPaymentInitGrid', function(Am_Event_Grid $e) {
$e->getGrid()->setFilter(new Am_Grid_Filter_PaymentsAdv);
});
class Am_Grid_Filter_PaymentsAdv extends Am_Grid_Filter_Payments
{
public function renderInputs()
{
@cgi-caesar
cgi-caesar / site.css
Last active March 22, 2021 14:17
aMember (site.php): align "login with" buttons
.am-google-button-wrapper.am-google-login-form-after::before {
content: none;
}
.am-google-button-wrapper.am-google-login-form-after {
border: none;
margin:0;
padding:0;
}
.am-fb-signup-button-wrapper {
@cgi-caesar
cgi-caesar / site.php
Last active March 31, 2021 07:21
aMember (site.php): Add Open Graph Meta to Login Page
<?php
Am_Di::getInstance()->blocks->add('login/form/before', new Am_Block_Base(null, 'og-login', null, function(Am_View $v) {
$meta = [
'og:image' => '/path/to/image.png',
];
$out = '';
foreach ($meta as $property => $content) {
$out .= sprintf(
@cgi-caesar
cgi-caesar / site.js
Created April 30, 2021 15:03
aMember (site.js): change absolute dates to relative in Active Subscription widget
jQuery(function(){
jQuery('.am-list-subscriptions-date_expires_date, .am-list-subscriptions-date_rebill_date, .am-list-subscriptions-date_future_date').each(function(){
if (jQuery(this).data('date') == '2037-12-31') return;
const today = new Date().toISOString().slice(0, 10)
const diffInDays = 1 + (new Date(jQuery(this).data('date')) - new Date(today)) / (1000 * 60 * 60 * 24);
jQuery(this).attr('title', jQuery(this).html());
jQuery(this).html(`in ${diffInDays} ${diffInDays == 1 ? 'day' : 'days'}`);
});
});