![]() |
Extra Field Search From product.tpl
Ok I have an extra field called 'Stars' the value of this field example is: "mark gregory, shanna more, debra smorton". I'm wondering how can I use smarty or whatever to give each name a seperate link and their value to perform a search for each one? I know how to do this in php, just not in smarty. Any help would be great.
|
Re: Extra Field Search From product.tpl
|
Re: Extra Field Search From product.tpl
Thanks it does cover alot of info that I already read, but does'nt touch how to make each result in an extra field that is comma seperated have its own search link. Any ideas?
|
Re: Extra Field Search From product.tpl
I would probably want to do that in the php file with "explode". Is there a reason why you want to do it in smarty in the template? I've not done this - but here is what I found from google that may help.
|
Re: Extra Field Search From product.tpl
I hate to act like I need a babysitter, I know php. I would prefer to do it in php, but I don't know how to make a smarty template pull the php file. Or where to even include that php file for this. If you dont mind or have time to explain I would appreciate it. I do appreciate that link as well.
Sorry it took me soo long to reply. I never received an email that you responded. |
Re: Extra Field Search From product.tpl
Assuming you want to do this on the product page, try something like this:
The smarty of extra fields are assigned in this file: /modules/Extra_Fields/extra_fields.php There is already a loop at the bottom of that file that assigns the extra_fields array to the smarty variables. You can add your explode inside that loop, or you can create another one - depending on the conditions you want to do this, or you can add a new loop if you want it always to read the extra field. There are some print/echo statements in the code to help you debug Code:
if (!empty($extra_fields)) { Now - the array should be available to your product.tpl. If you use this tip - you should see the $explode_stars array, and the values in the array as you expect. Now - in your product template - you need to cycle through the extra fields array and then the $explode_stars array, and set the links that you want based on the values. If you are already looping through extra fields, you can put this inside that loop instead of creating another. Code:
{section name=field loop=$extra_fields} Use the smarty variable console while you are debugging to see the variables and what their values (In case I have a code error - you should be able to fix it) |
Re: Extra Field Search From product.tpl
Awesome thank you. One last thing though. How can I keep each comma for each star so each star is still on one line rather than seperated by a "<br>" so basically I want each star broken down seperately so I can add a <a href> to them, but keep them all on one line seperated by a comma?
Thanks a million for your help. I'm almost there. |
Re: Extra Field Search From product.tpl
You can do what ever you want with html/css around the smarty variables. The slight complication is that you don't want a comma after your last star, so you need an if to only put the comma before the star if it is not the first star. Something like:
{if $smarty.section.star_name.index ne 0}, {/if}<a href="search.php?mode=search&by_title=on&by_shortd escr=on&by_fulldescr=on&by_sku=on&category_main=on &category_extra=on&search_in_subcategories=on&subs tring={$explode_stars[star_name]}">{$explode_stars[star_name]}</a> |
Re: Extra Field Search From product.tpl
Ok this works, but it does show a , for the last one. Any ideas? Also you might know so I'm gonna ask. If I'm using clean urls how can I know what category id I'm in for each category? I have a search by price mod I modified to work by using (if ($_GET['cat']) { show this } else { do that }) but now that clean urls are on im not able to use the $_GET in php for the catid. THANKS MAN :)
|
Re: Extra Field Search From product.tpl
Are you sure you used the code as I wrote it? I'll have to make a test case and try it when I have time, because looking at it, I can't see how you would have a comma after the last array element. If you want to debug it, just try printing out the variable I am using in the if statement: {$smarty.section.star_name.index} - it should only be equal to 0 the first time through the loop, then increment. And, I intend for it to print every time through the loop except the first time.
If the list does not begin with a comma, then it should have worked. The only reason I can think of where a comma would end the list is if there was a blank element at the end of the array. When you entered the extra field, did you end the list with a comma? If you want to test for stuff like that - I would do it in the php and pass the array to smarty after it is cleaned up. You can always see the category id in the database. An easier way might be to bring up the category in the administration. There are no clean urls in the admin, so you can look at the URL there and see the cat id. One other issue I just thought of - your star names have a blank space in between the first and last name - so the link I gave you won't work as the search URL. You need to replace the blank with a "+" - this should do it: Code:
{if $smarty.section.star_name.index ne 0}, {/if}<a href="search.php?mode=search&by_title=on&by_shortdescr=on&by_fulldescr=on&by_sku=on&category_main=on &category_extra=on&search_in_subcategories=on&substring={$explode_stars[star_name]}">{$explode_stars[star_name]|replace:' ':'+'}</a> |
Re: Extra Field Search From product.tpl
Thanks man the problem is that there is a blank one being created after the last one. So if there are actually 3 stars its showing a 4th that is blank.
|
Re: Extra Field Search From product.tpl
Also is there anyway to make this actually just search for the exact stars in the extra fields for stars?
|
Re: Extra Field Search From product.tpl
That is odd. I'm not sure why there would be an extra array element like that. You should see it using the print_r and echo statements in the original php code I gave you. You can always fall back on your php knowledge and add a test for that in the php when creating the $explode_stars array. I would do it in the php if you expect you might have to do more programming for other cases later. You can look at example 2 here to see how to filter the array in php for blanks.
Or. just add another condition in the smarty that won't let anything print if the value is empty - maybe this will work: Code:
{if $explode_stars[star_name] ne ""} If you can do the search you want on your advanced search page - just use the tip I gave you earlier to get the URL for the link. In advanced search, you can set up the criteria over which you want to search, and it will provide the URL. |
Re: Extra Field Search From product.tpl
awesome thanks man, but in regards to the search now, im trying to search only the extra field "Stars". And I can't select that in my advanced search. Any ideas?
|
Re: Extra Field Search From product.tpl
Nevermind got it.. I didnt realize you can turn on extra field searches from the admin area. THX for all your help man.. AWESOME SUPPORT. THX A MILLION
|
Re: Extra Field Search From product.tpl
you are welcome
|
Re: Extra Field Search From product.tpl
gb2world - one last questions totally different. If I want to change how each page title is displayed, I know you can choose from two options in the admin area, but what if I want to make my own custom one for each page? Is there a simple fix for this? Or any ideas?
|
Re: Extra Field Search From product.tpl
You can search the forum to find answers.
First, make sure you use this tip Next, select the advanced search under the search in the top menu next enter: page AND title AND modify in the search box narrow your search by selecting Storefront Design & Template Editing in 4.2.x and select Search Now |
Re: Extra Field Search From product.tpl
Thanks gb2world any ideas on how to show all categories that a product is listed in? Same as we did here for the stars, but now I want to show each category.
Thanks in advance :) |
Re: Extra Field Search From product.tpl
I doubt that the category information is available to the product page in the default installation. You can use the tip I told you about in post #6 to see the smarty variables that are available to you. If it is there, you can update the template to display the categories.
If the categories are not there - you are going to have to write your own query to get the information and add that to the product.php file. I think you need to query the _products_categories table and find all categories for the productid. If you understand the code in this thread (the sql query and the php), the concept is similar to what you want to do. You should be able to add an array with the categories to the $products array. |
Re: Extra Field Search From product.tpl
ok the following is what I added to product.php
PHP Code:
And in product.tpl I added: ------------------------------ <div> {foreach from=$explode_cats item=c} <a href="search.php?mode=search&including=any&categor yid=1" title="{$c}">{$c}</a> | {/foreach} </div> How can I pass the category id's to product.tpl in above so each href is correct for each categoryid? I have the categories passing correctly, I just can't figure out how to get the id's. Thanks :) |
Re: Extra Field Search From product.tpl
OK I got this to work:
In product.php I have: PHP Code:
Then in product.tpl I have the following: --------------------------------------- <div> {foreach from=$explode_cats item=c} {assign var=Pcatid value=$c.categoryid} {assign var=Pcatname value=$c.category} <a href="search.php?mode=search&including=any&categor yid={$Pcatid}" title="{$Pcatname}">{$Pcatname}</a> | {/foreach} </div> I HOPE THIS HELPS SOMEONE... THANKS FOR ALL THE HELP :) |
Re: Extra Field Search From product.tpl
Hi mrerotic, I also want to explode extra field items (a performer list, exactly the same as your initial query on this thread) but I am having a little difficulty following the code changes needed. Could you possibly post the coding changes that you carried out to make a hyperlink for each performer name?
Thanks in advance. |
All times are GMT -8. The time now is 04:55 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.