Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Last active July 1, 2019 09:46
Show Gist options
  • Save cgi-caesar/9b128c3ddcf0d36a68b20dcc8a9119cc to your computer and use it in GitHub Desktop.
Save cgi-caesar/9b128c3ddcf0d36a68b20dcc8a9119cc to your computer and use it in GitHub Desktop.
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);
$p = new Am_Period($item->first_period);
for ($i=1; $i<$item->qty; $i++) {
$access->expire_date = $p->addTo($access->expire_date);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment