![]() |
If statement for specific option class?
Here's a tricky one - have a client who we are displaying the price on the category page with 'Starting at' in front of it for products with options using this:
{if $products[product].is_product_options} However, he would only like this to display for products that are variants with a specific option class - in this case 'size'. So products that have an option with the class of 'size' will show 'starting at' while products that have an option class of 'flavor' will not. Version 4.1.10. Any ideas? |
Re: If statement for specific option class?
It's quite simple
find in your skin1/customer/main/product.tpl Code:
<tr><td class="ProductPriceConverting" valign="top">{$lng.lbl_price}: Code:
<tr><td class="ProductPriceConverting" valign="top">{$lng.lbl_price} {foreach from=$product_options item=v}{if $v.class|lower eq 'size'}starting at{/if}{/foreach}: |
Re: If statement for specific option class?
Sorry I have missed that you need this in category.
add in your products.php before the line Code:
$smarty->assign("products",$products); this: Code:
foreach($products as &$pp){ and every product from your $products array will contain additional array with product options so you just need to edit skin1/customer/main/products.tpl and skin1/customer/main/products_t.tpl as it was figured in my previous post |
Re: If statement for specific option class?
No luck with that Victor. There's an extra & in your php (before $pp) but even removing that doesn't do anything. Any other ideas?
|
Re: If statement for specific option class?
This & is necessary to pass the element of array by reference so it should present because $products array won't be modified without it.
But I have found another bug (error message for the categories with no products in it) so try with Code:
if (count($products)) and Code:
{foreach from=$products[product].product_options item=v}{if $v.class|lower eq 'size'}starting at{/if}{/foreach} |
Re: If statement for specific option class?
Well that causes a smarty error :)
|
Re: If statement for specific option class?
Parse error: syntax error, unexpected '&', expecting T_VARIABLE or '$' in /public_html/new/products.php on line 106
|
Re: If statement for specific option class?
Try this php:
PHP Code:
|
Re: If statement for specific option class?
Thanks Ralph - no smarty error from that, but no 'starting at' showing either. Other ideas?
|
Re: If statement for specific option class?
http://www.phpbuilder.com/manual/en/language.references.pass.php
also I should mention that this is working for me ;) |
Re: If statement for specific option class?
Thanks Victor, but it isn't for me. What version is it working for you on? This is a 4.1.10 cart.
|
Re: If statement for specific option class?
Quote:
|
Re: If statement for specific option class?
Its possible you might need to use $v.classtext instead of $v.class in the smarty. classtext is what is displayed on the page. If that doesn't work add {$products|print_r} to the top of your products.tpl and take a look at the [class] and [classtext] values for the products to see whats up.
|
Re: If statement for specific option class?
Yep both class and classtext are 'size'. Now some of these products have both a size and flavor class - will this work when a product has both? Meaning I want it to display if size class is present by itself or in combo with another class.
|
Re: If statement for specific option class?
It scans all options for the product and if it finds one with the name size it adds the text. So it works like you want it to. Tested and working fine for me.
Did you add it to the right .tpl? Sometimes I dig around in products.tpl for a while before I notice things don't look right and remember my site uses products_t.tpl. Other than that I can only suggest some basic troubleshooting. Replace the whole smarty {foreach} stuff that was added with some plain text to be sure its in the right spot. If that's OK replace it with {$products[product].product_options|print_r} to see if you've got the [class] variable there. If that shows the proper [class] stuff, scratch head and post back. |
Re: If statement for specific option class?
Yep, did that, spit out the correct variable. So I backed up and started from scratch. This time I got rid of the |lower and it is now working. Thanks for the help guys, really appreciate it!
|
Re: If statement for specific option class?
I have really stuck with 4.1.10 till found that products_t.tpl is used for 1-column format (in admin there was 1 for number of columns to display products). :D
For 4.1.11 it is working perfect. |
All times are GMT -8. The time now is 12:03 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.