Skip to content

Instantly share code, notes, and snippets.

@cgi-caesar
Last active September 14, 2018 08:14
Show Gist options
  • Save cgi-caesar/565cd5bf7aa595e2118242a0d9f1b304 to your computer and use it in GitHub Desktop.
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
<?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