Hide/Show content based on product id

Discussion in 'Customization & add-ons' started by ehassler, Aug 25, 2006.

  1. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    But why do you need any link between?
  2. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    well, I don't... but I don't see how I can authenticate for admins and for users in the same "if" statement without them being linked.

    as I said, I need to check for 2 things - if the user has an active subscription OR if the user is admin before I can display them the content of this page...

    and I figured out the first part of it (active subscription) but I can't figure out the second part (admin check)... and I need to pull those off in the same "if" statement... any ideas?
  3. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Please add your admins as users, and create a special hidden product for them, name it "Admin Access" for example.
    Then you can check - if user has subscription to this product, it is admin.
  4. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    see, that's what I don't get...

    how do I create a user FROM an admin?

    I have no problem with creating a new user, giving him the access to the one and only product that the site has (a subscription), and whatnot...

    but what I do have a problem with is that when an admin logs into the admin panel, and the link to that page that check for active subscription is there in the left navigation menu, he is not logged in through the general members login (that all regular users see) and he will not be validated as someone with an active subscription... unless he goes through the trouble of logging in twice - once through the admin login, and once through the members login - and he's gotta do that every single time (a bit too much work for an admin).

    there is no easy function in smarty that just checks if the user accessing the page is an admin?
  5. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    also (in addition), what is the difference between these two functions (as far as "if" checks are concerned):

    $smarty.session._amember_products

    and

    $smarty.session._amember_user.status==1

    ?
  6. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    still around?
  7. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    No. It is completely separate and it is good from security point of view.
  8. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    it will give you the same results, but
    first is list (array) of active products that user is subscribed to
    second is common user status (if there is one active subscription, it is 1)
  9. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    ok, so if

    if (in_array(5, $smarty.session._amember_product_ids))

    deals with one product, how would I define multiple products in that statement?

    just so I can display certain member content to certain groups...
  10. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Are you wanting an AND statement or an OR statement? (if this group AND this group) (if this group OR this group)

    aside from nesting if statements, something like this might work (untested)

    Code:
    $products=array('1', '2', '3');
    if(array_values_in_array($products, $smarty.session._amember_product_ids)){
    do something
    }else{
       do something
    }
  11. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    nope, that function doesn't exist (array_values_in_array) apparently.

    and I could do this by just adding AND statements, but is there a way to make it a one liner, sort of check if user is a member of either group x,y,z and if not, not show anything?
  12. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Hmm.. just tested that on my sandbox and it is working. Are you running PHP 5?
  13. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    yeah, why? is that a problem with your code/compatibility?
  14. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Yes, I believe array_values_in_array was added in PHP 4.20, but covering my basis.

    Some additional uses of it in this thread:

    http://php.nusa.net.id/in_array
  15. miso

    miso aMember Pro Customer

    Joined:
    Aug 22, 2006
    Messages:
    543
    also, how would you perform this check in php files outside of smarty templates?
  16. ronniead

    ronniead Member

    Joined:
    Dec 20, 2007
    Messages:
    118
    Hi,

    What a great post. I would like to do the same, but instead of searching which product they have already paid for, I would like to have a condition based on what product they are tried to purchase in the past.

    In other words, I have many PENDING / NOT-PAID status customers who return to members.html. At the moment they see ALL products which I don't want. I only want to show them the price_id that they were initially interested in (or the product_id).

    Once I can do that, then I'll be able to hide certain products from them by making custom purchase links like this:

    "http://www.yoursite.com/amember/member.php?product_id=PRODUCT_ID&paysys_id=PAYSYS_ID&action=renew"

    Any ideas?
  17. jimjwright

    jimjwright New Member

    Joined:
    Sep 12, 2007
    Messages:
    162
    Hello,

    This is how I understand it to work. Purchasing a product is a two-step process.

    Step 1. Create membership account in Amember.
    Step 2. Redirected to payment processor to complete payment transaction.

    The user creates an Amember account on the first page of signup. They do this by providing a username/password email address. When they click continue/submit they are taking to the payment processor for the purchased product. At this point Amember will have done the following:

    1. Add a member record to amember_members table.
    2. Add a payment record to amember_payments table.

    The payment record is marked as not completed. It will be marked as completed when payment transaction is completed. If user aborts at this point that will still have member record and an unfinished payment record.

    If you know the members id, you should be able to get this information, then you can query the amember_payment table for that member_id and unfinished payments. The unfinished payment record contains the product_id that the user had started to purchase. So you basically have all the information you need to customize the products displayed if you can do the customization work yourself.

    Jimmy

Share This Page