![]() |
help with if then statment for detailed description
HI All,
I am trying to add an if then statement to a button I created that I have placed in the detailed description box. I have the button working but I want to limit the pages that this button appears on. This is what I have done. I created a new .tpl called sizing_help.tpl that looks like this. {if $c.order_by gt 4 and $c.order_by lt 41} {/if} <table cellspacing="0" cellpadding="0" onclick="javascript: self.location='http://1090495.nwinetworks.com/xcart/pages.php?pageid=1';" class="ButtonTable"> <tr><td><input type="image" src="{$ImagesDir}/but1.gif" class="ButtonSide_menu" alt="" /></td><td class="Button"><font class="Button"> Click Here For Help With Product Sizing</font> </td><td><img src="{$ImagesDir}/but2.gif" class="ButtonSide_menu" alt="" /></td></tr></table> I placed this in the buttons directory. The button works fine but I want to limit the pages that the button appears on so I thought the way to di that would be with a conditional statement -shown above in red- calling only the pages from 4 to 41 This did not work. The button still worked but it still appears on all the pages. I have also tried {if $c.order_by gt 4 and $c.order_by lt 41} {include file="buttons/sizing_help.tpl"} {/if} and placed this in the customer/main/product.tpl thinking perhaps that the conditional statment needed to be there, but with no luck. I removed the conditional statement from the buttons/sizing_help.tpl when I did this. In theory I would think that this idea should work but now not sure if I am approaching the problem the right way. I am hoping that the conditional statment just needs to be corrected and that someone can look at it and tell me what I need to do to get the button just to appear on the select pages. If there is a better way to do this I am not wed to this idea it just seemed like a good solution so I am open to other suggestions. As always any help here is greatly appreciated from any and all that can reply. Thanks in advance Best Scott V fotodog13 4.1.2 gold 4.1.8 pro Apache |
Re: help with if then statment for detailed description
Print this to the page to see if it the c.order_by variable holds a value (which I suspect it doesn't):
Code:
{if $c.order_by}It exists: {$c.order_by}{else}No it doesn't exist{/if} |
Re: help with if then statment for detailed description
Hi Jon,
Thanks for the reply. I pasted the code you provided above mine ( shown in red above) into the product.tpl. then checked the page. It returned the does not exsist message on the page so I would think that you are correct that the c variable is not being recognized. Is there away to write the statement so that the variable is recognized here and allows for the button to appear only on the pertinent pages? Thanks again I really appreciate the help Best Scott V |
Re: help with if then statment for detailed description
Can you provide a page url where you want this button to appear?
|
Re: help with if then statment for detailed description
HI Jon,
Thanks for the reply. Here is the url for the page where the button should appear. http://1090495.nwinetworks.com/xcart/product.php?productid=33&cat=15&page=1 You can see the does not exist message is there. * This page is on a closed test server. I think you should be ale to get on with the URL I have posted above but if it you get asked to log in let me know and I will private message you the password info Thanks for looking at this Scott |
Re: help with if then statment for detailed description
It's asking me to login, but by default you can't use category order_by variables on a product details page.
|
Re: help with if then statment for detailed description
Hi Jon,
I thought that might be the problem. DO you know If I was to take the button out of the detailed description box and put it up near the breadcrumbs could I call the category pages from there? That button does not necessarily need to be in the detailed description box but I only want the button to come up on pages where sizing information is something the user might need to access. Understand what I am saying. Let me what you think Thanks Scott |
Re: help with if then statment for detailed description
No where on the page can you access the category variables, you can query them from product.php and assign to smarty.
|
Re: help with if then statment for detailed description
Hi Jon,
Thanks again. I think I understand what you are saying but not sure how to write it. would it look like this? $smarty->assign {if $c.order_by gt 4 and $c.order_by lt 41} {include file="buttons/sizing_help.tpl"} {/if}; |
Re: help with if then statment for detailed description
Hi scott ,
Can you explain the condition for the button to display in word.I understand that you want to display that button only to products in certain categories .Am i right if not pls give me your explanation as to based on what condition you want the button to be displayed |
Re: help with if then statment for detailed description
Hi Vetrivel,
Thanks for the rsponse. I am working on a site that sells pet items. On some of the pages the product needs to be ordered by size so the client has and embedded page on the site that shows how to measure the animal correctly in order to make sure that you order the correct size product. I thought that if I put a button in the detailed description box and called it through the product.tpl I could then limit when the button appeared by using and if then statement so that the only time that the button appeared in the detailed description product box was when a relevant page was called . It seems like it makes sense but the if then statement that I tried is not recognizing the variables for the category pages so the button appears on all the pages. I tried to follow Jon's suggestion above but have not been able to figure out how to write the code to put in the product.php and assign it to smarty to see if this would work. Understand ? Let me know. I think the problem is solvable but I am just a few steps away from it. Would appreciate your thoughts Best Scott 4.1.2 gold 4.1.8 pro Apache |
Re: help with if then statment for detailed description
I am still trying to figure this out If I understand you correctly Jon, you are saying to query the categories from the product.php and assign them to smarty.
I have tried a few things here the latest being $smarty->assign('customer/category', 'category'); include ("customer/main/product.tpl"); which I thought would assign the category and include the product.tpl which would then display the button on the correct pages but I am obviously still not doing something correctly as this does not change the response to the page. If anyone can tell me how to do this I would be really grateful. Thanks Scott V |
Re: help with if then statment for detailed description
I can't figure out which pages you want the button to be displayed on?
|
Re: help with if then statment for detailed description
Hi Ashley,
Thanks for the reply. I am definitely over my head a bit here and not exactly sure of what I am doing What I was hoping to do was call the product.tpl and inside that I have placed this {if $c.order_by}It exists: {$c.order_by}{else}No it doesn't exist{/if} {if $c.order_by gt 4 and $c.order_by lt 41}{/if} {include file="buttons/sizing_help.tpl"} so that when the category pages with POS 4 thru 41 were called the button/sizing.tpl would be called and it would then display the button I have made. If I understand Jon ( see above) reply to me I might be able to do this if I query the category variables in the product.php and assign to smarty. The line $smarty->assign('customer/category', 'category'); include ("customer/main/product.tpl"); is my latest failed attempt of things I have placed in the product.php page. Hope you now understand what I am trying to do. I am not wed to this solution if you have a better one I am interested in that Thanks again Best Scott V |
Re: help with if then statment for detailed description
I think the problem is that you need to pull the info from the database in the product.php file. I believe you will need to assign a variable to a SQL query. the assign that variable to smarty. Then the order_by info will be available for the product.tpl.
|
Re: help with if then statment for detailed description
could you add this to product.php?
$order_by = func_query_hash("SELECT order_by FROM xcart_categories"); $smarty->assign("order_by", $order_by); Im not sure if it's this simple? Im not much of a database guy. |
Re: help with if then statment for detailed description
A bit over my head but I think I follow you, and will try to figure that out.
Instead of what I have described above do you know if there is a way to call a duplicate product.tpl from the customer/home_main.tpl ( I think if I duplicated the product.tpl and called it something like product_b.tpl and placed my button in there I would have 2 product.tpl files one with a button one without.) I am not sure if this would be any easier to do, it might require doing the same as you have described above just to a different smarty variable. Thanks again let me know what you think Best Scott V |
Re: help with if then statment for detailed description
Hi Ashley,
Thanks for the attempt. It might be me but it does not seem to work. Unfortunately I am not much of a database person either |
Re: help with if then statment for detailed description
well hopefully someone can shed some light on this. I'd like to know how to do this.
|
Re: help with if then statment for detailed description
{foreach from=$categories item=c}
I don't think $c is defined in product.tpl. It is created in categories.tpl I believe. in the product.tpl you may need to do something like: {if $order_by.order_by gt 4 and $order_by.order_by lt 41}{/if} that's if the SQL is correct. man I now have more questions than answers. not much help here. |
Re: help with if then statment for detailed description
I think you are correct in that $c is not defined in the product.tpl
I tried {if $order_by.order_by gt 4 and $order_by.order_by lt 41}{/if} to the product.tpl with $order_by = func_query_hash("SELECT order_by FROM xcart_categories"); $smarty->assign("order_by", $order_by); added to the product.php with no luck. I also tried the above with $smarty->assign('customer/category', 'category'); include ("customer/main/product.tpl"); added to the product.php with same -no results :( I need to take a break from this right now but really appreciate your help. I am going to take another stab at it in a few hours. If I get it figured out I will post it and let you know ,as I think that it would be something a lot of others would like to know how to do Thanks Again Scott V |
Re: help with if then statment for detailed description
Hi Scott -
If I understand what you are trying to do correctly, maybe this will help. In product.tpl, the variable $cat contains the categoryid of the current product, so you could do if-than statements based on the $cat variable. If you do need the category order_by, you will need to add a query to the product.php file to get it. I think this should work if you add it after you see $cat defined: Code:
$cat_order_by = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '$cat'"); Then, you can do if-than statements based on $cat_order_by You can try printing the variables in product.tpl to make sure they are as expected: PHP Code:
I've not done this before - so hopefully you won't find any unintended consequences. Also - using this tip helps show you what smarty variables are available so that you do not have to guess. |
Re: help with if then statment for detailed description
tried it and only got this. still no order_by
category: 249 parent: 0 order_by: |
Re: help with if then statment for detailed description
I added this to product.php
$cat_order_by = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '$cat'"); $smarty->assign("cat_order_by",$cat_order_by); I tried it first at the beginning of the file right after $cat was defined with no luck, and then again at the end of the file. Does it matter where the code i placed? |
Re: help with if then statment for detailed description
Hi Ashley,
I also tried the same thing this AM and had the same results |
Re: help with if then statment for detailed description
ok I got it working.
I placed this code: $cat_order_by = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '$cat'"); $smarty->assign("cat_order_by",$cat_order_by); just below this code: $main = "product"; $smarty->assign("main",$main); I now get this category: 249 parent: 0 order_by: 10 |
Re: help with if then statment for detailed description
HI Ashley,
What a day I have been running like a chicken with its head cut offI I put the code in as you have above and get the same response but it still does not appear to be getting me closer to my goal of having a button that I made appear only on certain product pages not all of them . I am seeing the code category: 249 parent: 0 order_by: 10 showing up on all of the product pages are you seeing something different. AM i missing something? Thanks Scott |
Re: help with if then statment for detailed description
will it work for you to use the $cat_order_by variable instead of the $c.order_by variable you were trying to use in your if-than statement?
(remove the variables that are printing the category - they were just to help you understand and check that that is what you are after) |
Re: help with if then statment for detailed description
Hi Scott -
Note that I assumed you had set up the categories for which you wanted the button to appear by setting the POS variable in your administration for the categories. So - you had set up the category POS to be 5-40 for those categories. So the code above pulls from the database what that category POS setting for the current category on each product page. If you are seeing order_by: 10 for every product you check no matter what category, that means the POS variable for those product's category are all set to 10. If you have different POS variables set for different categories, and you are looking at products from these different categories, and you always see the same settings for {$cat} and {$cat_order_by}, something is still wrong. I just put all this code in a default XCART to test it, and it appears to work. Maybe you are doing something different with the categories than I see in a default XCART? If you want to send a link for one of your product pages, maybe I will see what is different. |
Re: help with if then statment for detailed description
Hi again Scott -
It just struck me that you might be using the POS associated with the products within a category, and not the POS associated with the category itself. (There are a lot of POS settings - so it can get confusing!) Here is more code for another query that gets that POS for product.tpl. Hopefully this displays the variable that you seek. If you have an individual product in more than one category - the query may need to be adjusted. In product.php: Code:
$cat_order_by = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '$cat'"); In product.tpl: Code:
category: {$cat}<br /> |
Re: help with if then statment for detailed description
HI GB
Thanks for the reply I believe I am using the POS#'s from the category section I made in the ADMIN section. I tried both $cat_order_by variable instead of the $c.order_by variable and get the same results. ( I just PM you a link to the page I am trying to add the button to- it is on a test server so you may need to log in to get to the page ) In the mean time this is what I currently have in the product.php $main = "product"; $smarty->assign("main",$main); $cat_order_by = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '$cat'"); $smarty->assign("cat_order_by",$cat_order_by); and to the product.tpl <td valign="top" width="100%"> <span>{if $product.fulldescr ne ""}{$product.fulldescr}{else}{$product.descr}{ /if}</span> {if $cat.order_by gt 4 and $cat.order_by lt 41} {include file="buttons/sizing_help.tpl"}{/if} As I look at this now I am wondering of this is not working because the statement I have written is not correct ( incomplete) THanks to all for the help Best Scott V |
Re: help with if then statment for detailed description
Adapting previous code slightly, here's how I would do do it.
In product.php FIND: $smarty->assign("product",$product_info); BEFORE add: Code:
$product_info['cat_order_by'] = func_query_first_cell("select order_by from $sql_tbl[categories] where categoryid = '" . (intval($cat) > 0 ? $cat : intval($product_info['categoryid'])) . "'"); In product.tpl Code:
{if $product.cat_order_by gt 4 and $product.cat_order_by lt 41} |
Re: help with if then statment for detailed description
Hi Scott -
If you are using the code that I posted - then the if/than statement you posted is wrong - I did not put the order_by into an array called cat - so instead of {if $cat.order_by gt 4 and $cat.order_by lt 41} use {if $cat_order_by gt 4 and $cat_order_by lt 41} If it still does not work - try Jon's code. It should work as well. If you still have issues - post again - and I can offer more suggestions for how to debug - by checking the smarty variables. |
Re: help with if then statment for detailed description
gb2. Ashley, Jon, Vetrivel, and any others that I have missed here,
Thanks much for all the help you have given me here. I finally go this to work, and it seems to be perfect. The cat pages are calling perfectly and the button I made only appears on the pages that I have indicated by POS in the if then statement. There is no way I would have ever been able to figure this out myself with out the help of you guys. Once again these forums have been my godsend. Many , many thanks again to all you. I really appreciate your help. As I think there are others here that may benefit from this I am going to post the code for how to add a button and call your category pages in the product.tpl to the mod section, with hopes that this helps someone else. Best Scott V aka fotodog13 |
Re: help with if then statment for detailed description
:D/ :D/ :D/
Quote:
|
Re: help with if then statment for detailed description
well I really didn't help much just did some learning. would you post the final solution please? Interested to see what worked.
|
Re: help with if then statment for detailed description
HI Ashley,
Don't kid yourself you were a big help to me. I just pasted the code and solution in the completed mods section. "how to add a button to the detailed description box" I am using this for a site that sells dog accessories. One of the things they sell are dog coats. The owner has a lot of returns due to measuring the dog incorrectly. To solve this problem they made an embedded page and that tells how to measure their dog to get the correct fit. The previous person working on this site then added a button that appeared on every page of the site . Whether you were buying a dog toy, or t shirt the button appeared that took you to the how to measure your dog for the dog coat page. Obviously this was not a good solution because if someone was buying something other than a dog coat there was really no need for the button to be there. Adding this page lets the button appear only on the pages that have been assigned by the POS set in the category admin section. I know I could of added a link to each particular page manually but that would be a pain in the but. I also saw scripts that allowed something like this to happen through the use of a pop up but was not sure that was a good solution here. ( then I would have to ask the potential customer to enable pop ups which they may or may not know how to do) Anyway this works like a charm. This site is under construction on a private ( closed ) server right now. If you want to see how it works I can PM you a link with a user name and password to see it Hope you find this useful too. Best Scott V aka fotodog13 |
Re: help with if then statment for detailed description
Glad it worked for you, Scott. I looked at the page and it is a good improvement over the current site. It was also thoughtful of you to post it as a completed mod to save others time from wading through our discussions!
|
All times are GMT -8. The time now is 05:38 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.