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

Jake......Subscription Conditional?

Russ

Well-known member
#1
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
 

Sadik B

Well-known member
#2
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.
 

Russ

Well-known member
#3
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>
 

Andy.N

Well-known member
#6

Andy.N

Well-known member
#7
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.
 

Jake Bunce

XenForo moderator
Staff member
#10
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.
 

Andy.N

Well-known member
#11
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.
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>
 

Jake Bunce

XenForo moderator
Staff member
#12
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.
 

Andy.N

Well-known member
#13
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.
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>
 

Jake Bunce

XenForo moderator
Staff member
#14
The condition goes just inside of the foreach. Move the foreach outside so it wraps all of the conditionals. There is only one foreach.
 

Andy.N

Well-known member
#15
The condition goes just inside of the foreach. Move the foreach outside so it wraps all of the conditionals. There is only one foreach.
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>
 

Jake Bunce

XenForo moderator
Staff member
#16
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.