Quick Question

Discussion in 'Customization & add-ons' started by joaquin_delasierra, Apr 14, 2014.

  1. joaquin_delasierra

    joaquin_delasierra New Member

    Joined:
    Oct 8, 2012
    Messages:
    5
    I'm trying to modify Amember to show all the products that a user hasn't purchased on a left-side navigation I created. It works great on the Main page, but it doesn't work on any other page. Here's the code I'm using:

    $categoryProducts = Am_Di::getInstance()->productCategoryTable->getCategoryProducts();

    It returns the categories only on the Main page, but not on any other page. Does anyone know why this behavior occurs and how I can fix it?

    Thank you,
    Joaquin
  2. joaquin_delasierra

    joaquin_delasierra New Member

    Joined:
    Oct 8, 2012
    Messages:
    5
    Sorry, I actually use the $member_products variable, but like I said it's not returning results on any page other than Main. Thanks.
  3. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    I guess you modify templates. $member_products variable is defined only for dashboard. In aMember templates for logged in user you can retrieve same info the following way:
    Code:
    <?php $di->user->getActiveProducts() ?>
    $di is instance of Am_Di and it always exists in template scope. You may want to check that user already logged in before use this code:
    Code:
    <?php if ($di->auth->getUserId()) : ?>
    ..some html or php code if user is already logged in..
    <?php endif; ?>
  4. joaquin_delasierra

    joaquin_delasierra New Member

    Joined:
    Oct 8, 2012
    Messages:
    5
    Thank you so much for your answer, it worked perfectly. Now I'm having the same issue with the $resources variable. What's the code for getting $resources in the template scope?
  5. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You can use this code to retrieve it
    Code:
    <?php
    $resources = $di->resourceAccessTable->getAllowedResources($di->user, ResourceAccess::USER_VISIBLE_TYPES);
    ?>

Share This Page