running custom script

Discussion in 'Integration' started by csongor_simsay, Dec 16, 2013.

  1. csongor_simsay

    csongor_simsay New Member

    Joined:
    Dec 10, 2013
    Messages:
    26
  2. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use site.php file to put code for such customization (http://www.amember.com/docs/Site.php_file)
    so it will not be overwritten during upgrade.

    Here is complete example of code to achieve your needs:
    Code:
    Am_Di::getInstance()->hook->add(Am_Event::ACCESS_AFTER_INSERT, 'myAccessHandler');
     
    function myAccessHandler(Am_Event $event) {
        /* @var $access Access */
        $access = $event->getAccess();
        /* @var $user User */
        $user = $event->getUser();
     
        $request = new Am_HttpRequest('http://www.mysite.com/myscript.php?' . http_build_query(array(
            'username' => $user->login,
            'product_id' => $access->product_id,
            'product_quantity' => $access->qty
        )), Am_HttpRequest::METHOD_GET);
     
        $request->send();
    }
  3. csongor_simsay

    csongor_simsay New Member

    Joined:
    Dec 10, 2013
    Messages:
    26
    Hi Caesar,

    I get along with this well, just a quick question...
    what am I missing in this short code in order to echo the id of the product what the user has?


    <p>product: <?php $myCode = Am_Di::getInstance()->user->getActiveProducts(); echo $myCode[product_id];?> </p>

    <p>product: <?php $myCode = Am_Di::getInstance()->user->getActiveProductIds(); echo $myCode[product_id];?> </p>

    Thanks for your support!
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hey,

    In your case $myCode will be array of product ids. So in case you want to output first element you can use
    Code:
    echo $myCode[0];
  5. csongor_simsay

    csongor_simsay New Member

    Joined:
    Dec 10, 2013
    Messages:
    26
    Thanks works fine!
    I also need direction for a similar one because it returns nothing:
    Is this line correct?

    my_invoice: "<?php $myInvoice = Am_Lite::getInstance()->getPayments(); echo $myInvoice[invoice]; ?>
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    This code Am_Lite::getInstance()->getPayments() return array of user's payments (of currently logged in user). I recommend you to debug output of this function to understand how it works. So please use print_r(Am_Lite::getInstance()->getPayments()). You will see result of this method call and will be able to retrieve necessary info from it.
  7. csongor_simsay

    csongor_simsay New Member

    Joined:
    Dec 10, 2013
    Messages:
    26
    All right it makes sense, but as far as I can see it returns nothing but the product_id and quantity, nothing user related infos (using FastSpring
    payments made on payment system side
    ) Am I right?
    Your answer may save my whole day :)
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Am_Lite::getInstance()->getPayments() return array of payments associated with currently logged in user. Each item in this array is array too with info for payment.

Share This Page