@masdika Do you mean you want to add some unique fraction to price for each invoice? You can use the following code in site.php file http://www.amember.com/docs/Site.php_file PHP: Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT_SIGNUP, function(Am_Event $e) { $invoice = $e->getInvoice(); $item = $invoice->getItem(0); $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + ($invoice->pk() % 100)); $invoice->calculate(); $invoice->save();});
Ok, thank's... it work... but how to edit email sending to client. because invoice on email still fix rate... not use unique .
@bikinwebsitemudah Do you mind to contact us in helpdesk? https://www.amember.com/support I will help you to setup it proper way. Best Regards.
Here is code that will work better for such case: 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->data()->get('add_fraction')) { $item->data()->set('add_fraction', 1); $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + ($id % 100)); $invoice->calculate(); } unset($GLOBALS['add_fraction']);});
Hi, I'm sorry for bumping this old issue. The code above works fine for me. However, this become problem when I want only selected payment method to implement this. I.e, keep paypal payment as is, where offline payment, using fraction. What I need is a code to detect payment method for current invoice. Would you like to help me achieve that?
Code: Am_Di::getInstance()->hook->add(Am_Event::INVOICE_CALCULATE, function(Am_Event $e) { if ($invoice->paysys_id == 'offline') { 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->data()->get('add_fraction')) { $item->data()->set('add_fraction', 1); $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + ($id % 100)); $invoice->calculate(); } }else{ 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->data()->get('add_fraction')) { $item->data()->set('add_fraction', 1); $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') - ($id % 100)); $invoice->calculate(); } } unset($GLOBALS['add_fraction']); });
@caesar when there is an offline sign up or not it always falls to else. so when there is a signup using offline payment it doesn't work ,no error messages or error codes. and for example I want to use if else if using currency USD and IDR is also not working.For example, I add a unique number after a (,) or (.), for example like above but behind a (,) or (.) : $10.01 or $10.02. like this . for code I use this code 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;"); $es = $invoice->pk() ?: $e->getDi()->db->selectCell("SELECT MAX(invoice_id)+1 FROM ?_invoice;"); if ($invoice->currency=='USD') { 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') + '0.'.($es % 100)); $invoice->calculate(); } } elseif ($invoice->currency=='IDR'){ 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 % 100)); $invoice->calculate(); } } unset($GLOBALS['add_fraction']);});
Do you use these both code snippets (with offline and currency) in same time? Please contact us in helpdesk: https://www.amember.com/support We will check it. Best Regards.
Do you mean you have incorrect amount in case of USD? You need to replace line: PHP: $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + '0.'.($es % 100)); with PHP: $item->data()->set('orig_first_price', $item->data()->get('orig_first_price') + ('0.'.($es % 100))); In order to help you I need to know what you want to achieve and what you get incorrectly with your code.