Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Created March 27, 2020 09:54
Show Gist options
  • Select an option

  • Save cgi-caesar/ed6c1df4b31889a49a8a3bfed3b8308b to your computer and use it in GitHub Desktop.

Select an option

Save cgi-caesar/ed6c1df4b31889a49a8a3bfed3b8308b to your computer and use it in GitHub Desktop.
aMember (site.php): Show qty within Active Subscriptions widget
<?php
Am_Di::getInstance()->blocks->add('member/main/bottom', new Am_Block_Base(null, 'item-qty', null, function(Am_View $v) {
$di = Am_Di::getInstance();
$user = $di->user;
$_ = $user->getActiveProductIds();
$out = [];
foreach ($_ as $pid) {
$qty = $di->db->selectCell(<<<CUT
SELECT SUM(qty)
FROM ?_access
WHERE user_id = ?
AND product_id = ?
AND begin_date<=?
AND expire_date>=?
CUT
,
$user->pk(),
$pid,
sqlDate('now'),
sqlDate('now')
);
if ($qty > 1) {
$out[] = " jQuery('#member-subscriptions #product-item-{$pid} .am-list-subscriptions-title strong').after(' ({$qty})');";
}
}
if ($out) {
$out = implode("\n", $out);
return <<<CUT
<script>
jQuery(function(){
{$out}
});
</script>
CUT;
}
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment