Need to adjust Invoice Item Price on Hook

Discussion in 'Customization & add-ons' started by keithvaughan, Dec 2, 2014.

  1. keithvaughan

    keithvaughan New Member

    Joined:
    Aug 4, 2014
    Messages:
    6
    Hello,

    I'm trying to accomplish this:
    I've been working with the site.php file for my other customizations, and I wonder if I can accomplish this, by doing the same approach, then what hook should I listen to?
    I also still got no clue about updating the Invoice Item price.

    I'd be grateful if anyone can point me out with a working code. Thank you :)
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use event Am_Event::INVOICE_GET_CALCULATORS to add your calculator. Also you will need to implement calculator based on Am_Invoice_Calc class. To get idea how it works please check file amember/library/Am/Invoice/Calc.php
  3. keithvaughan

    keithvaughan New Member

    Joined:
    Aug 4, 2014
    Messages:
    6
    Thanks for pointing out, caesar. But can you elaborate your answer? I'm still new in this.
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    What is exactly you want to implement?
  5. keithvaughan

    keithvaughan New Member

    Joined:
    Aug 4, 2014
    Messages:
    6
    Thank you for still paying attention to this thread, caesar.

    What I want to implement is to handle offline payment method for my customers;
    1. Adjust the invoice.first_total based on my function, which will return a new calculated first_total price
    2. Apply the calculated price on Am_Event::INVOICE_BEFORE_INSERT

    But I still got no clue to work on your suggested Am_Invoice_Calc class. That's why I need more code snippet from you :p

    ------------------ OOT ------------------
    I know my next question is out-of-topic, but is it possible to create two offline payment method options on Signup Form? I want to allow my customer to choose one out of two bank account.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use this code in site.php (http://www.amember.com/docs/Site.php_file)
    HTML:
    Am_Di::getInstance()->hook->add(Am_Event::INVOICE_BEFORE_PAYMENT_SIGNUP, 'myHandler');
    
    function myHandler(Am_Event $e) {
         /* @var $invoice Invoice */
        $invoice = $e->getInvoice();
        $invoice->updateQuick('first_total', 30);
    }
    Regarding second offline plugin. Yes, it is possible. Please copy file amember/application/default/plugins/payment/offline.php to amember/application/default/plugins/payment/offline2.php
    and inside file offline2.php replace Am_Paysystem_Offline with Am_Paysystem_Offline2
    keithvaughan likes this.
  7. keithvaughan

    keithvaughan New Member

    Joined:
    Aug 4, 2014
    Messages:
    6
    I have tried the code, and it works!
    Thank you, caesar.

Share This Page