Last active
September 14, 2018 08:14
-
-
Save cgi-caesar/565cd5bf7aa595e2118242a0d9f1b304 to your computer and use it in GitHub Desktop.
aMember (site.php): Add 3 digit unique code to the product price
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 | |
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)); | |
$invoice->calculate(); | |
} | |
unset($GLOBALS['add_fraction']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment