Last active
July 1, 2019 09:46
-
-
Save cgi-caesar/9b128c3ddcf0d36a68b20dcc8a9119cc to your computer and use it in GitHub Desktop.
aMember (site.php): change access period based on purchased quantity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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