How to read additional product fields in my php?

Discussion in 'aMember Pro v.4' started by menspsy, Feb 17, 2014.

  1. menspsy

    menspsy New Member

    Joined:
    Aug 4, 2010
    Messages:
    24
    Hi guys, have been trying to get this working a while now and have searched extensively but can't find what I need.

    The set up - we have a number of different products, some of which give you access to a special area on our site. If a logged in user has an active subscription to one of these products then the .php will let them see the extra content (the product list constantly changes and evolves so I don't want to hardcode it).

    I have added a custom field (a checkbox) and this is displayed in amember admin. I can tick it for the products I wish and leave it blank for the others.

    Code:
    Am_Di::getInstance()->productTable->customFields()->add(new Am_CustomFieldCheckbox('vip_access', 'VIP Access'));
    The first problem: When I call Am_Lite::getInstance()->getProducts() the additional custom fields are not listed in what is returned. Do I have to also add that line of code to my php code on my website?

    If I do the above, then it appears in the products data, but I can't figure out how to read the status of that additional property in my php code. Nothing in that data suggests whether the box is checked or not.

    So the question is - if I add an additional field check box to my products, given a logged in user - how do I check if he/she has any products with that check box ticked?

    Thanks for any help, going a bit crazy on this on :)
  2. menspsy

    menspsy New Member

    Joined:
    Aug 4, 2010
    Messages:
    24
    After a lot of hunting around, trial and error and peeking in the mysql database to find where the data is stored, I've finally found a solution.

    Code:
    $query = 'SELECT * FROM `am_data` WHERE `id` IN ('1,2,3,4,5') AND `key`="vip_access_on"';
    $results = Am_Di::getInstance()->db->query($query);
    
    1,2,3,4,5 are a list of product id's to check against
    vip_access_on is the name of my check box in aMember

    returns a nice php array I can then parse through.

    Not sure if that's the best way but it's the only way I could find :)

Share This Page