Get order data

Discussion in 'Customization & add-ons' started by fabio_pagano, Oct 19, 2016.

  1. fabio_pagano

    fabio_pagano New Member

    Joined:
    Sep 9, 2013
    Messages:
    5
    Hello everybody,

    I have this function:

    function onUserAfterInsert(Am_Event $contact_data){
    [...]
    $user = $contact_data->getUser();
    [...]
    }

    I gather user info to monitor them with a third party software. I would like to be able to gather also the product that has been bought, and the price that has been paid.

    I looked around internet but I wasn't able to find what kind of data is available within $contact_data or if I need to do something else to track my new customer.

    Does anyone have some tips?
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    User has not any subscription at this point. I suggest to use another event for your code:
    PHP:
    Am_Event::PAYMENT_AFTER_INSERT
    Here is example of usage:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::PAYMENT_AFTER_INSERT, function(Am_Event $e) {
        
    /* @var $user User */
        
    $user $e->getUser();
        
    /* @var $payment InvoicePayment */
        
    $payment $e->getPayment();
        
    /* @var $invoice Invoice */
        
    $invoice $e->getInvoice();
    });
    Reference:
    http://www.amember.com/docs/Site.php_file
    http://www.amember.com/docs/API/HookManager
  3. fabio_pagano

    fabio_pagano New Member

    Joined:
    Sep 9, 2013
    Messages:
    5
    Hi Caesar,

    thank you for your tips. I am looking at amember documetnation to understand what can I expect from getPayment() and getInvoice() but I can't find anyhting useful. I need to recover the name of the product and the price that has been paid. What should I expect from those methods? Where can I see an explanation on the structure that will be returned in both cases?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    It return InvoicePayment and Invoice objects as mentioned in comments. It is object that represent entity from database (invoice_payment and invoice) and have same property as column in database.

    You can check datbase structure in file
    amember/application/default/db.xml

    You can check code of clasess in files
    amember/appliaction/default/models/InvoicePayment.php
    amember/appliaction/default/models/Invoice.php


    http://www.amember.com/api/Am_Invoice/InvoicePaymentTable.html
    http://www.amember.com/api/Am_Record/InvoiceTable.html

    Here is example how to retrive amount of payment:
    Code:
    $amountPaid = $payment->amount;

Share This Page