1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Jake......Subscription Conditional?

Discussion in 'XenForo Questions and Support' started by Russ, Sep 17, 2012.

  1. Russ

    Russ Well-Known Member

    Or anyone else :)


    In account_upgrades it has this listed:

    Code:
    <xen:if is="{$purchased}">
        <div class="section">
            <h3 class="subHeading">{xen:phrase purchased_upgrades}</h3>
            <ul>
            <xen:foreach loop="$purchased" value="$upgrade">
    

    What I'm trying to achieve is put custom content in each little listed subscription so I would need something like this:

    Code:
    <xen:if is="{$purchased.upgrade_id} == 1">
        test
    </xen:if>
    
    Hope this makes sense and I hope this is an existing feature
     
  2. Sadik B

    Sadik B Well-Known Member

    Not sure I understood you properly, but you probably need to include {$i} inside the foreach

    HTML:
    <xen:foreach loop="$purchased" value="$upgrade" i="$i" count="$count">
    {$i} increments with each iteration, so you can have a conditional inside the foreach.
     
  3. Russ

    Russ Well-Known Member

    Well I need to show custom content in each subscription.

    So say I have 5 different upgrades avail for my users, I would like to do something like this:

    Code:
    <xen:if is="{$purchased.upgrade_id} == 1">
        shows in upgrade 1
    </xen:if>
    <xen:if is="{$purchased.upgrade_id} == 2">
        shows in upgrade 2
    
    </xen:if>
    <xen:if is="{$purchased.upgrade_id} == 3">
        shows in upgrade 3
    
    </xen:if>
    <xen:if is="{$purchased.upgrade_id} == 4">
        shows in upgrade 4
    
    </xen:if>
    <xen:if is="{$purchased.upgrade_id} == 5">
        shows in upgrade 5
    
    </xen:if>
    
     
  4. Russ

    Russ Well-Known Member

    EDIT: We got it! :)

    Code:
                            <xen:if is="{$upgrade.user_upgrade_id} == 1">
    test1
                            </xen:if>
    
     
  5. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  6. Andy.N

    Andy.N Well-Known Member

    Great timing. I have been waiting to ask if I can use conditionals to show the upgrade 2 for people who already purchased upgrade 1.
    So for everyone who has not purchased, they will only see the Upgrade 1.
    Thanks
     
    Russ likes this.
  7. Andy.N

    Andy.N Well-Known Member

    Hey Jake,
    Just in case you have not seen this, do you think it's possible to use conditionals on which upgrade to show?
    Thanks.
     
  8. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  9. Andy.N

    Andy.N Well-Known Member

  10. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Oh. Probably do a group check:

    Code:
    <xen:if is="{$upgrade.user_upgrade_id} == 1 AND {xen:helper ismemberof, $visitor, 4}">
    
    </xen:if>
    
    So upgrade 1 will only show if the user belongs to group 4.
     
  11. Andy.N

    Andy.N Well-Known Member

    Playing with this for the last hour or so but unable to get this to work. It shows both upgrades (2 and 3) for me. I tried on default template, try to change $visitor to @user, etc.
    When members buy upgrade 2, they will be assigned into secondary usergroup 9 and I want upgrade 3 to show to this group only.
    Here is the current code I have
    Code:
    <xen:foreach loop="$available" value="$upgrade">
    <xen:if is="{$upgrade.user_upgrade_id} == 3 AND {xen:helper ismemberof, $visitor, 9}">
    <li class="primaryContent">
    <div class="upgrade">
    <form action="{$payPalUrl}" method="post" class="upgradeForm">
    <div class="cost">{$upgrade.costPhrase}</div>
    <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
     
    <input type="hidden" name="cmd" value="_xclick-subscriptions" />
    <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
    <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
    <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
    <input type="hidden" name="src" value="1" />
    <input type="hidden" name="sra" value="1" />
     
    <input type="submit" value="{xen:phrase subscribe}" class="button" />
    <xen:else />
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
     
    <input type="submit" value="{xen:phrase purchase}" class="button" />
    </xen:if>
     
    <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
    <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
    <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
     
    <input type="hidden" name="charset" value="utf-8" />
    <input type="hidden" name="email" value="{$visitor.email}" />
     
    <input type="hidden" name="return" value="{$requestPaths.fullBasePath}{xen:link account/upgrade-purchase}" />
    <input type="hidden" name="cancel_return" value="{$requestPaths.fullBasePath}{xen:link index}" />
    <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
    </form>
     
    <div class="upgradeMain">
    <h4 class="title">{$upgrade.title}</h4>
    <xen:if is="{$upgrade.description}">
    <div class="description">{xen:string nl2br, $upgrade.description}</div>
    </xen:if>
    </div>
    </div>
    </li>
    </xen:if>
    </xen:foreach>
     
  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Unfortunately the template syntax doesn't have a "continue" you can use, so you will need to duplicate the entire contents of the foreach for each upgrade and surround each one with a condition to check the qualifications for each individual upgrade.
     
  13. Andy.N

    Andy.N Well-Known Member

    I obviously misunderstood what you try to say, Jake.
    Latest attempt still not working
    Code:
    <xen:if is="{$upgrade.user_upgrade_id} == 2">
    <xen:foreach loop="$available" value="$upgrade">
    <li class="primaryContent">
    <div class="upgrade">
    <form action="{$payPalUrl}" method="post" class="upgradeForm">
    <div class="cost">{$upgrade.costPhrase}</div>
    <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
     
    <input type="hidden" name="cmd" value="_xclick-subscriptions" />
    <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
    <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
    <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
    <input type="hidden" name="src" value="1" />
    <input type="hidden" name="sra" value="1" />
     
    <input type="submit" value="{xen:phrase subscribe}" class="button" />
    <xen:else />
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
     
    <input type="submit" value="{xen:phrase purchase}" class="button" />
    </xen:if>
     
    <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
    <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
    <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
     
    <input type="hidden" name="charset" value="utf-8" />
    <input type="hidden" name="email" value="{$visitor.email}" />
     
    <input type="hidden" name="return" value="{$requestPaths.fullBasePath}{xen:link account/upgrade-purchase}" />
    <input type="hidden" name="cancel_return" value="{$requestPaths.fullBasePath}{xen:link index}" />
    <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
    </form>
     
    <div class="upgradeMain">
    <h4 class="title">{$upgrade.title}</h4>
    <xen:if is="{$upgrade.description}">
    <div class="description">{xen:string nl2br, $upgrade.description}</div>
    </xen:if>
    </div>
    </div>
    </li>
                 </xen:foreach>
    </xen:if>
    <xen:if is="{$upgrade.user_upgrade_id} == 3 AND {xen:helper ismemberof, $visitor, 9}">
            <xen:foreach loop="$available" value="$upgrade">
    <li class="primaryContent">
    <div class="upgrade">
    <form action="{$payPalUrl}" method="post" class="upgradeForm">
    <div class="cost">{$upgrade.costPhrase}</div>
    <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
     
    <input type="hidden" name="cmd" value="_xclick-subscriptions" />
    <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
    <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
    <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
    <input type="hidden" name="src" value="1" />
    <input type="hidden" name="sra" value="1" />
     
    <input type="submit" value="{xen:phrase subscribe}" class="button" />
    <xen:else />
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
     
    <input type="submit" value="{xen:phrase purchase}" class="button" />
    </xen:if>
     
    <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
    <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
    <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
     
    <input type="hidden" name="charset" value="utf-8" />
    <input type="hidden" name="email" value="{$visitor.email}" />
     
    <input type="hidden" name="return" value="{$requestPaths.fullBasePath}{xen:link account/upgrade-purchase}" />
    <input type="hidden" name="cancel_return" value="{$requestPaths.fullBasePath}{xen:link index}" />
    <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
    </form>
     
    <div class="upgradeMain">
    <h4 class="title">{$upgrade.title}</h4>
    <xen:if is="{$upgrade.description}">
    <div class="description">{xen:string nl2br, $upgrade.description}</div>
    </xen:if>
    </div>
    </div>
    </li>
             </xen:foreach>
    </xen:if>
     
  14. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    The condition goes just inside of the foreach. Move the foreach outside so it wraps all of the conditionals. There is only one foreach.
     
  15. Andy.N

    Andy.N Well-Known Member

    Thank you. One more try. Still not working.
    Code:
    <xen:foreach loop="$available" value="$upgrade">
    <xen:if is="{$upgrade.user_upgrade_id} == 2">
    <li class="primaryContent">
    <div class="upgrade">
    <form action="{$payPalUrl}" method="post" class="upgradeForm">
    <div class="cost">{$upgrade.costPhrase}</div>
    <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
     
    <input type="hidden" name="cmd" value="_xclick-subscriptions" />
    <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
    <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
    <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
    <input type="hidden" name="src" value="1" />
    <input type="hidden" name="sra" value="1" />
     
    <input type="submit" value="{xen:phrase subscribe}" class="button" />
    <xen:else />
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
     
    <input type="submit" value="{xen:phrase purchase}" class="button" />
    </xen:if>
     
    <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
    <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
    <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
     
    <input type="hidden" name="charset" value="utf-8" />
    <input type="hidden" name="email" value="{$visitor.email}" />
     
    <input type="hidden" name="return" value="{$requestPaths.fullBasePath}{xen:link account/upgrade-purchase}" />
    <input type="hidden" name="cancel_return" value="{$requestPaths.fullBasePath}{xen:link index}" />
    <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
    </form>
     
    <div class="upgradeMain">
    <h4 class="title">{$upgrade.title}</h4>
    <xen:if is="{$upgrade.description}">
    <div class="description">{xen:string nl2br, $upgrade.description}</div>
    </xen:if>
    </div>
    </div>
    </li>
    </xen:if>
    <xen:if is="{$upgrade.user_upgrade_id} == 3 AND {xen:helper ismemberof, $visitor, 9}">
    <li class="primaryContent">
    <div class="upgrade">
    <form action="{$payPalUrl}" method="post" class="upgradeForm">
    <div class="cost">{$upgrade.costPhrase}</div>
    <xen:if is="{$upgrade.length_unit} AND {$upgrade.recurring}">
     
    <input type="hidden" name="cmd" value="_xclick-subscriptions" />
    <input type="hidden" name="a3" value="{$upgrade.cost_amount}" />
    <input type="hidden" name="p3" value="{$upgrade.length_amount}" />
    <input type="hidden" name="t3" value="{$upgrade.lengthUnitPP}" />
    <input type="hidden" name="src" value="1" />
    <input type="hidden" name="sra" value="1" />
     
    <input type="submit" value="{xen:phrase subscribe}" class="button" />
    <xen:else />
    <input type="hidden" name="cmd" value="_xclick" />
    <input type="hidden" name="amount" value="{$upgrade.cost_amount}" />
     
    <input type="submit" value="{xen:phrase purchase}" class="button" />
    </xen:if>
     
    <input type="hidden" name="business" value="{$xenOptions.payPalPrimaryAccount}" />
    <input type="hidden" name="currency_code" value="{$upgrade.currency}" />
    <input type="hidden" name="item_name" value="{xen:phrase account_upgrade}: {$upgrade.title} ({$visitor.username})" />
    <input type="hidden" name="quantity" value="1" />
    <input type="hidden" name="no_note" value="1" />
    <input type="hidden" name="no_shipping" value="1" />
    <input type="hidden" name="custom" value="{$visitor.user_id},{$upgrade.user_upgrade_id},token,{$visitor.csrf_token_page}" />
     
    <input type="hidden" name="charset" value="utf-8" />
    <input type="hidden" name="email" value="{$visitor.email}" />
     
    <input type="hidden" name="return" value="{$requestPaths.fullBasePath}{xen:link account/upgrade-purchase}" />
    <input type="hidden" name="cancel_return" value="{$requestPaths.fullBasePath}{xen:link index}" />
    <input type="hidden" name="notify_url" value="{$xenOptions.boardUrl}/payment_callback.php" />
    </form>
     
    <div class="upgradeMain">
    <h4 class="title">{$upgrade.title}</h4>
    <xen:if is="{$upgrade.description}">
    <div class="description">{xen:string nl2br, $upgrade.description}</div>
    </xen:if>
    </div>
    </div>
    </li>
                  </xen:if>
             </xen:foreach>
     
  16. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Looks syntactically correct. Are your conditions correct?

    Code:
    <xen:if is="{$upgrade.user_upgrade_id} == 3 AND {xen:helper ismemberof, $visitor, 9}">
    
    <xen:if is="{$upgrade.user_upgrade_id} == 2">
    
    2 will be shown to everyone. 3 will only show to members of group 9.
     

Share This Page