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

Display HTML in Extra fields

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 05-22-2006, 07:03 AM
 
Grant Grant is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 171
 

Default Display HTML in Extra fields

I would love to say I wrote this but alas I didn't.
It cost me a whole bunch of support points to get this coded by X-cart and seeing as.....

a) I see this mod/fix asked for quite a bit by newbs like myself
b) This should be a standard feature of X-Cart - not a required mod and
c) I have received lots of invaluable help from peeps here like Balinor, Zaja et al.....

I thought I would share this with the group

--------------

This MOD is for those that want to display extra fields containing HTML anywhere on your site (almost)..
One of the ways I used this mod was to enable small clickable images that linked to audio previews.

1. Create the following file and name it modifier.extrafield.php then upload it to the include/templater/plugins directory :

Quote:
<?php
if (!defined('XCART_START')) { header("Location: ../../../"); die("Access denied"); }

function smarty_modifier_extrafield($value, $mode) {
global $config, $sql_tbl;

$return = func_query_first_cell("SELECT value FROM ".$sql_tbl["extra_field_values"]." WHERE productid = $value AND fieldid= $mode");

if ($return)
return $return;
else
return "";
}

?>

2. Modify skin1/customer/main/products.tpl by adding the following wherever you want it to display :

Note : You must replace the following parts of this code with your own field variables....

NEWFIELD - replace this with the name of the field you wish to display - ie 'Size'
# - replace this with the field number of the field you wish to display - ie '2'

Quote:
{assign var="NEWFIELD" value=$products[product].productid|extrafield:#} {if $NEWFIELD ne ""}

NEWFIELD: {$NEWFIELD} {/if}

3. Modify skin1/customer/main/products_t.tpl exactly the same way as described in step 2.

4. Open admin/product_modify.php & provider/product_modify.php and look for the following :

Quote:
define('USE_TRUSTED_POST_VARIABLES',1);
$trusted_post_variables = array("product_lng","product_new_descr","product_n ew_full_descr","descr","fulldescr","posted_data"," js_code","javascript_code");

Replace with :

Quote:
define('USE_TRUSTED_POST_VARIABLES',1);
$trusted_post_variables = array("product_lng","product_new_descr","product_n ew_full_descr","descr","fulldescr","posted_data"," js_code","javascript_code", "efields");

Do the same for both files.

5. To make it a bit easier to enter and edit all your lovely HTML code on the Admin backend do the following...

Open modules/Extra/product_modify.tpl and find :

Quote:
<INPUT type="text" name="efields[{$extra_fields[field].fieldid}]" size="24" value="{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape: "html"}{else}{$extra_fields[field].value|escape:"html"}{/if}">

Replace with :

Note. Make sure you change the following part of this code with your own field name.

NEWFIELD - Change this to the name of YOUR field. ie 'Size'

Quote:
{if $extra_fields[field].field eq "NEWFIELD"}
<TEXTAREA name="efields[{$extra_fields[field].fieldid}]" rows="10" cols="45">{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape: "html"}{else}{$extra_fields[field].value|escape:"html"}{/if}</TEXTAREA>
{else}
<INPUT type="text" name="efields[{$extra_fields[field].fieldid}]" size="24" value="{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape: "html"}{else}{$extra_fields[field].value|escape:"html"}{/if}">
{/if}

And thats it

This works a charm and is a doddle to install.

Enjoy,

G
__________________
X-Cart version : 4.0.18
Mod : Customer Also Bought
Mod : Custom catergory Templates
Mod : Custon Product Templates
Reply With Quote
  #2  
Old 05-22-2006, 07:18 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Nice...finally, one complete set of instructions. Thanks for posting it Grant!
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 05-22-2006, 08:22 AM
 
Grant Grant is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 171
 

Default

The least I can do to say thanks for all the help I've had here
__________________
X-Cart version : 4.0.18
Mod : Customer Also Bought
Mod : Custom catergory Templates
Mod : Custon Product Templates
Reply With Quote
  #4  
Old 05-23-2006, 09:54 PM
 
Chris B Chris B is offline
 

eXpert
  
Join Date: Oct 2002
Posts: 226
 

Default I can't get this mode to work...

I keep getting the following error:

Quote:
INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND fieldid= 2' at line 1
SQL QUERY FAILURE: SELECT value FROM xcart_extra_field_values WHERE productid = AND fieldid= 2


I'm probably not doing something right in the display code. (I just arbitrarily used the number 2 as the field I wanted displayed.)


Code:
{assign var="shirtcolors" value=$products[product].productid|extrafield:2} {if $shirtcolors ne ""} Shirt Colors : {$shirtcolors} {/if}

Thanks,
Chris

Version 4.0.18
__________________
4.0x - 4.5x
Reply With Quote
  #5  
Old 05-30-2006, 02:02 PM
 
Grant Grant is offline
 

Senior Member
  
Join Date: Apr 2006
Posts: 171
 

Default Re: I can't get this mode to work...

Quote:
Originally Posted by Chris B
I keep getting the following error:

Quote:
INVALID SQL: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND fieldid= 2' at line 1
SQL QUERY FAILURE: SELECT value FROM xcart_extra_field_values WHERE productid = AND fieldid= 2


I'm probably not doing something right in the display code. (I just arbitrarily used the number 2 as the field I wanted displayed.)


Code:
{assign var="shirtcolors" value=$products[product].productid|extrafield:2} {if $shirtcolors ne ""} Shirt Colors : {$shirtcolors} {/if}

Thanks,
Chris

Version 4.0.18

Is 2 the correct field number for the shirtcolors field?

Every field you create has it's own number starting with 1 being the first field that you created.

Go into your admin backend and open Products > Extra fields.
The field right at the top will be number 1 and then they go down in numerical order.

Really to make things easier there should be a field number display next to each field name - this is probably quite a simple mod if one of the experts fancies having a go at knocking it up
__________________
X-Cart version : 4.0.18
Mod : Customer Also Bought
Mod : Custom catergory Templates
Mod : Custon Product Templates
Reply With Quote
  #6  
Old 06-07-2006, 08:30 AM
 
alru111 alru111 is offline
 

eXpert
  
Join Date: Dec 2005
Posts: 244
 

Default

In the following block of text delete space before "html" in both cases.
It was causing an error.


Quote:
{if $extra_fields[field].field eq "NEWFIELD"}
<TEXTAREA name="efields[{$extra_fields[field].fieldid}]" rows="10" cols="45">{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape: "html"}{else}{$extra_fields[field].value|escape:"html"}{/if}</TEXTAREA>
{else}
<INPUT type="text" name="efields[{$extra_fields[field].fieldid}]" size="24" value="{if $extra_fields[field].is_value eq 'Y'}{$extra_fields[field].field_value|escape: "html"}{else}{$extra_fields[field].value|escape:"html"}{/if}">
{/if}
__________________
X-Cart version 4.0.19
Reply With Quote
  #7  
Old 06-07-2006, 07:54 PM
 
alru111 alru111 is offline
 

eXpert
  
Join Date: Dec 2005
Posts: 244
 

Default

html code gets truncated to about 150 chars, how can I get rid of it?
__________________
X-Cart version 4.0.19
Reply With Quote
  #8  
Old 06-07-2006, 08:11 PM
 
alru111 alru111 is offline
 

eXpert
  
Join Date: Dec 2005
Posts: 244
 

Default

ok, found it
it's in the DB
it the extra_filed_values changed type of the value from CHAR255 to TEXT
__________________
X-Cart version 4.0.19
Reply With Quote
  #9  
Old 08-02-2006, 09:10 AM
 
ecommerce ecommerce is offline
 

eXpert
  
Join Date: Jul 2006
Posts: 267
 

Default

this is going to make a lot of people happy.

sure makes me
__________________
X-Cart 4.0.18 DBest
Reply With Quote
  #10  
Old 10-15-2006, 11:51 AM
 
fogelka fogelka is offline
 

Advanced Member
  
Join Date: Jun 2006
Posts: 83
 

Unhappy Re: HTML in Extra fields - Not working for .gif icons - Pls. Help!

This is a very helpful mod. I was looking for a way to add icons to the products page.

I have only been half way successful. I am able to show HTML text in the field, but I can't get images to show. I keep getting the red X of misery. I have checked, and there are no htaccess files in the image directories, so that can't be the problem. I also have the files set to 777. I have even tried different locations for the .gif image, including the location for my product pics (which do work) but it just won't play.

Here is one variation of the several I've tried putting in the extra field:

<IMG src="{ImagesDir}/"icon.gif">

I also went to the DB and changed it from CHAR255 to TEXT. No difference.

Help! Thanks.
__________________
xcart v4.0.18 [linux]

Loyalty Points, DSEFU, Easy Checkout, Featured Product Manager, Remember Me, Relevant Search, Vertical Flyouts, Multiple Category Templates. Loads of other tweaks and mods learned in forums.
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 11:50 AM.

   

 
X-Cart forums © 2001-2020