X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   If statement for specific option class? (https://forum.x-cart.com/showthread.php?t=45774)

balinor 02-23-2009 04:33 AM

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?

Victor D 02-24-2009 12:16 AM

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}:
and replace with
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}:

Victor D 02-24-2009 01:20 AM

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){
$pp['product_options'] = func_get_product_classes($pp['productid'], false);
}


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

balinor 02-24-2009 04:12 AM

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?

Victor D 02-24-2009 04:19 AM

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))
    foreach($products as &$pp){
        $pp['product_options'] = func_get_product_classes($pp['productid'], false);
    }

in products.php

and
Code:

{foreach from=$products[product].product_options item=v}{if $v.class|lower eq 'size'}starting at{/if}{/foreach}
for skin1/customer/main/products.tpl

balinor 02-24-2009 04:20 AM

Re: If statement for specific option class?
 
Well that causes a smarty error :)

balinor 02-24-2009 04:23 AM

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

geckoday 02-24-2009 06:00 AM

Re: If statement for specific option class?
 
Try this php:
PHP Code:

foreach($products as $k=>$v){
     
$products[$k]['product_options'] = func_get_product_classes($products[$k]['productid'], false);



balinor 02-24-2009 06:08 AM

Re: If statement for specific option class?
 
Thanks Ralph - no smarty error from that, but no 'starting at' showing either. Other ideas?

Victor D 02-24-2009 06:20 AM

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 ;)

balinor 02-24-2009 06:26 AM

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.

geckoday 02-24-2009 06:49 AM

Re: If statement for specific option class?
 
Quote:

Originally Posted by Victor D
http://www.phpbuilder.com/manual/en/language.references.pass.php
also I should mention that this is working for me ;)

That page discusses pass by reference for function calls by using the & in the function definition. The correct page reference is http://us3.php.net/foreach which does discuss the *PHP 5 only* reference within the foreach construct. This will not work in PHP 4.

geckoday 02-24-2009 06:54 AM

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.

balinor 02-24-2009 07:01 AM

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.

geckoday 02-24-2009 07:39 AM

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.

balinor 02-24-2009 07:51 AM

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!

Victor D 02-24-2009 08:03 AM

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.