Printing user details and products on page

Discussion in 'Customization & add-ons' started by bennyuk1, Feb 20, 2017.

  1. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    Hi, I am trying to create or modify some code I had working on ameber v4 site but now want to work on v5 site.

    It basically printed out (just on screen) vi php script
    User Name
    Products purcahsed (active) and products purchased (expired), ptogether with info on how mush they paid.

    Is there any any documentation for v5 and the variable I can retrieve (asuming the details are for the current logged in user)


    I used to use code like

    $user = $this->getDi()->user;
    $products = $user->getActiveProductIds();
  2. caesar

    caesar aMember Pro Developer Staff Member

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

    You can use same code in version 5 as well.

    Best Regards.
  3. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    I was hoping it would work but I seem to having difficulties. Basically I'm trying to do some checks on what products (both expired and active) the current user has, and then set some variables.
    eg
    Code:
     
        $user = $this->getDi()->user;
        $ticketlist1 = $user->getExpiredProductIds();   
        $ticketlist2 = $user->getActiveProductIds();
        $ticketlist = array_merge($ticketlist1, $ticketlist2);
        if (in_array('119', $ticketlist) || in_array('120', $ticketlist) || in_array('127', $ticketlist))
        {
                $printtype = "Info type 1";
        }
         if (in_array('121', $ticketlist) || in_array('141', $ticketlist) || in_array('122', $ticketlist))
        {
                $printtype = "Info type 2";
        }
    
    but it doesnt seem to be work (it did work in v4)

    Any ideas why?
  4. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Your code looks correct. What is file where you use it?

    Did you get any error with it? If so what is error message?
  5. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    I get error
    Code:
    Static method [noCache] does not exists in Am_Mvc_Controller
    when I try to use my old code.
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
  7. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    Thanks for the help. I got it working in the end, by adding new methods and constants.

    Next question, If I have the ID of a products, how can I retrieve the price of it (in a php script)?
  8. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Here you are:
    PHP:
    //I assume Id of your product is 1
    $price  Am_Di::getInstance()->productTable->load(1)->getBillingPlan()->first_price;
  9. bennyuk1

    bennyuk1 aMember Pro Customer

    Joined:
    Jan 12, 2012
    Messages:
    200
    thats is perfect, many thanks
    I also used the following to get the product title from the id
    Am_Di::getInstance()->productTable->load($idnumber)->title;
  10. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Yes, it is correct code to get title.

Share This Page