Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Extra Field Search From product.tpl

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 06-26-2009, 09:23 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Lightbulb 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.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #2  
Old 06-28-2009, 12:19 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default Re: Extra Field Search From product.tpl

Does this help as far as the extra fields code?

To create search links - try this
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #3  
Old 06-28-2009, 12:40 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default 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?
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #4  
Old 06-28-2009, 12:49 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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.
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #5  
Old 06-30-2009, 08:10 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default 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.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #6  
Old 07-01-2009, 12:24 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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)) { foreach ($extra_fields as $ef_k=>$ef_v) { if ($ef_v['field'] == "stars") { echo "explode stars: "; $explode_stars = explode(',', $ef_v['field_value']); print_r($explode_stars); } $smarty->assign("explode_stars", $explode_stars); }


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} {if $extra_fields[field].field eq "stars" && $extra_fields[field].field_value ne ""} <p>{$extra_fields[field].field_value}</p> <p>exploded: <br /> {section name=star_name loop=$explode_stars} {$smarty.section.star_name.index} : {$explode_stars[star_name]} <br /> {/section} </p> {/if} {/section}

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)
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #7  
Old 07-02-2009, 10:30 AM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default 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.
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #8  
Old 07-02-2009, 02:20 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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>
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #9  
Old 07-02-2009, 05:52 PM
 
mrerotic mrerotic is offline
 

eXpert
  
Join Date: Feb 2009
Posts: 264
 

Default 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
__________________
x-cart 4.2.3
AlteredCart Smart Search
Auto Featured Products Mod (Personal Mod)
BCSE Product Importer Pro & Drop Shipper Pro
CDSEO Pro
CMS EZRecommends
EE slider login (Personal Mod)
Next Prev Link Mod (Customized)
ShadowBox Detailed Images (Personal Mod)
Shop By Price (Customized)
Social Media (Personal Mod)
Switch Layout View (Personal Mod)
Special Offers
Testimonials (Personal Mod)
Whats New (Customized)
Reply With Quote
  #10  
Old 07-02-2009, 09:53 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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>
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:04 AM.

   

 
X-Cart forums © 2001-2020