Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Conditional Logic issue


Go to End


5 Posts   1592 Views

Avatar
cdwilliams

Community Member, 8 Posts

11 August 2015 at 8:04am

On my site, there are products that have:
1. No options
2. Options with color variations
3. Price options
4. Options of both color and price
If a product has no color or price options, it should go directly to the cart. However, if the product has options of either price or color or both, then I am trying to direct a visitor to pages where they can select more options, but the logic in my code only works when there are ONLY Product Options ($ProductOptions). When there are Price options or variations ($ProductPr), the logic breaks down. Any ideas on how to make it work? Here is the code:

<% if $ProductOptions || $ProductPr %>
<a href="$Link"><input type="button" class="cart-button" value="Click for Pricing" /></a>
<% else_if $ProductOptions && $ProductPr %>
<a href="$Link"><input type="button" class="cart-button" value="Click for Pricing" /></a>
<% else %>
<strong>$Price.Nice</strong> <input type="submit" class="cart-button" value="Add to Cart" />
<% end_if %>

Avatar
Pyromanik

Community Member, 419 Posts

12 August 2015 at 12:33am

Edited: 12/08/2015 12:35am

Transfer the logic to the controller or the model (probably the model). If it's not your code, try using an Extension (probably DataExtension).
It's the easiest sure-fire way to deal with such issues, and is arguably where such logic belongs.

Avatar
cdwilliams

Community Member, 8 Posts

12 August 2015 at 4:25am

Thanks, Pyro. I'll find a way to do that. No doubt, It'll be a big a leap in my understanding of Silverstripe!

Avatar
Pyromanik

Community Member, 419 Posts

12 August 2015 at 10:20pm

It's basically just what you've got written there, but in PHP and in a function on the model.
Or applied to the model via: https://docs.silverstripe.org/en/3.1/developer_guides/extending/extensions/
Then you just call $ThatFunction from the template instead.

If it's all new to you, the important thnig is not to be afraid.
Fear leads to anger, anger leads to hate, and hatred leads to suffering
To the dark side that path leads.

Avatar
cdwilliams

Community Member, 8 Posts

14 August 2015 at 2:58am

Pryro,

You've been a HUGE help. Thank you so much on this (and great Yoda quote, by the way). I've been intimidated some aspects of Silverstripe, but this is forcing me to "Boldly go where" I haven't gone before - which is a good thing!

I'll get it done:)