dvp Posted March 11, 2015 Share Posted March 11, 2015 Hello WHMCS community, I am currently looking for a template syntax or a method to add specific images to my cart table (viewcart.tpl) based upon the ID of the specific product. Since I just have a few basic products available i would like to do this manually e.g. if product xy show img a, else if product xx show image b etc... However I have searched the forum and other resources and could not find a proper method to get this done. Some expert advise would be truly appreciated. Thank you very much and best regards, dvp 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 12, 2015 Share Posted March 12, 2015 the basic way would be to do this... {if $product.pid eq "46"}<img src="images/hosting1.png">{elseif $product.pid eq "42"}<img src="images/hosting2.png">{/if} remember that this will only work for products - for domains, you would need to play with the $domain array. the more advanced way, would first check if an image exists for the product in the cart, and if it does display it - if no product image exists, it won't attempt to display any image. the advantage of this method is that if you add new products which have images, you won't need to modify the template each time... {assign var="prodimage" value="images/"|cat:$product.pid|cat:'.png'}{if "$prodimage"|file_exists}<img src="{$prodimage}">{/if} the images should be in the same directory - in the above example, the "images" folder within your WHMCS installation. each image should be given the same filename as the product ID - so if your productID (PID) = 34, then name the image "34.png" - if you would prefer to use .jpg, then alter the above code and replace .png with .jpg the above code should go in the {foreach key=num item=product from=$products} loop of viewcart.tpl 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 8, 2020 Share Posted March 8, 2020 On 3/12/2015 at 6:44 PM, brian! said: the basic way would be to do this... {if $product.pid eq "46"}<img src="images/hosting1.png">{elseif $product.pid eq "42"}<img src="images/hosting2.png">{/if} Hi brian! I'm trying to do something like op in viewcart but $product.pid is not a variable there I use in configureproductdomain.tpl this "{if $templatefile == 'configureproductdomain' && in_array($productinfo.pid, $prodID)}" and is working because is a simple array, but in viewcard is a multidimensional array and in_array is not working here. How can I get the product pid from viewcart so I cand create an if condition? thanks 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 9, 2020 Share Posted March 9, 2020 Hi @mihai666g 19 hours ago, mihai666g said: I'm trying to do something like op in viewcart but $product.pid is not a variable there are you sure ? 19 hours ago, mihai666g said: use in configureproductdomain.tpl this "{if $templatefile == 'configureproductdomain' && in_array($productinfo.pid, $prodID)}" and is working because is a simple array, but in viewcard is a multidimensional array and in_array is not working here. then if you want to do this in the template, the simple solution is to loop though the array... 19 hours ago, mihai666g said: How can I get the product pid from viewcart so I cand create an if condition? would help to know what you wanted to output and where, but i'm assuming either it's something you want to do multiple times (if there are multiple conditions net) or you only want to do it once (regardless of how many times you find x in viewcart)... if it's the first, then you do it within the $products loop (assuming that's where the output is going to be)... {foreach $products as $num => $product} {if in_array($product.pid, array('123'))}it's in there!!{/if} {/foreach} if it's the second and you only want it displayed once, then you would assign a counter as per the code in the thread below... 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 9, 2020 Share Posted March 9, 2020 50 minutes ago, brian! said: if it's the first, then you do it within the $products loop (assuming that's where the output is going to be)... {foreach $products as $num => $product} {if in_array($product.pid, array('23,32,45'))}it's in there!!{/if} {/foreach} I tried and it breaks my page, css + js gone. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 10, 2020 Share Posted March 10, 2020 16 hours ago, mihai666g said: I tried and it breaks my page, css + js gone. {foreach $products as $num => $product} {if in_array($product.pid, array(23,32,45))}it's in there!!{/if} {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 10, 2020 Share Posted March 10, 2020 5 hours ago, brian! said: {foreach $products as $num => $product} {if in_array($product.pid, array(23,32,45))}it's in there!!{/if} {/foreach} ? i was saying it is not working 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 10, 2020 Share Posted March 10, 2020 7 minutes ago, mihai666g said: i was saying it is not working did you try it ? the way you had your array list was wrong - either each value can be in quotes, or if you know they're numbers, you won't need any single quotes. 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 10, 2020 Share Posted March 10, 2020 46 minutes ago, brian! said: did you try it ? the way you had your array list was wrong - either each value can be in quotes, or if you know they're numbers, you won't need any single quotes. Yes, I tried and is not working. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted March 10, 2020 Share Posted March 10, 2020 @mihai666g I think you misunderstood @brian!. Your code was wrong. By wrapping all of your numbers in one single quote, it's treated as one number - either wrap each number in their own single quote (array('23','32','45')) or don't do it at all (array(23,32,45)). Did you try using the code he pasted? It's not the same as the code you posted. 1 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 11, 2020 Share Posted March 11, 2020 ️ 6 12 hours ago, DennisHermannsen said: @mihai666g I think you misunderstood @brian!. Your code was wrong. By wrapping all of your numbers in one single quote, it's treated as one number - either wrap each number in their own single quote (array('23','32','45')) or don't do it at all (array(23,32,45)). Did you try using the code he pasted? It's not the same as the code you posted. I tried every scenario, the code is not working and is breaking the page. Normal page, https://prnt.sc/repaxo, added the code https://prnt.sc/repbgb and this is the output https://prnt.sc/repbs7 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted March 11, 2020 Share Posted March 11, 2020 What does your activity log say? Normally, and error would be output in the logs. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 11, 2020 Share Posted March 11, 2020 6 minutes ago, mihai666g said: I tried every scenario, the code is not working and is breaking the page. this is what i'm seeing in Six & Standard cart Dennis is absolutely correct - the activity log should give you a clue to what it doesn't like. 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 11, 2020 Share Posted March 11, 2020 (edited) 7 minutes ago, brian! said: this is what i'm seeing in Six & Standard cart Dennis is absolutely correct - the activity log should give you a clue to what it doesn't like. Thi is the error:Smarty Error: Syntax error in template "file:/home/xxxxxxxxxxx/public_html/mi.xxxxxxxx.com/templates/lagom/core/pages/viewcart/xxxxxx/viewcart.tpl" on line 2 "{foreach $products as $num => $product}" missing 'item' attribute Edited March 11, 2020 by mihai666g 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted March 11, 2020 Share Posted March 11, 2020 Could you paste your entire viewcart.tpl? I've just inserted this: {foreach $products as $num => $product} {if in_array($product.pid, array(1,2))}it's in there!!{/if} {/foreach} And I get the exact same as @brian! 0 Quote Link to comment Share on other sites More sharing options...
mihai666g Posted March 11, 2020 Share Posted March 11, 2020 8 minutes ago, DennisHermannsen said: Could you paste your entire viewcart.tpl? I've just inserted this: {foreach $products as $num => $product} {if in_array($product.pid, array(1,2))}it's in there!!{/if} {/foreach} And I get the exact same as @brian! .... somehow now is working, I just deactivated my custom theme file and reactivated it.... my brain hurts Thanks guys for patience. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.