X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Coding With Product's Extra Fields (https://forum.x-cart.com/showthread.php?t=9146)

willirl 08-30-2004 03:28 AM

Coding With Product's Extra Fields
 
In 4.x how do you use the product's extra_fields in code? Before we used paramxx but this now seems not to work. An small code example would help.

Emerson 09-02-2004 02:52 PM

I am having this problem too.

I understand they moved the extra fields into it's own tables so how do we get this going?

Also, where the heck do you add more extra fields in 4.x ? 8O

Emerson 09-02-2004 03:01 PM

Ok, I found were they are.
I am using a Pro version and in 4.x the extrafields option only show for the provider now.

willirl 09-02-2004 04:14 PM

You can reference the extra fields in the product.tpl template like this:

$extra_fields[x].field_value

Where x is the field index - 0 is the first.

However my problem is I need the extra fields on the products.tpl also and I cannot figure out how to get to them. There a set of files in modules/extra_fields/ that are used for something but I can't figure out how.

Isn't there anyone out there who knows how this works?

TelaFirma 09-02-2004 04:25 PM

{$extra_fields[X].field_value} where X = the field ID. Field ID's start at 0.

{$extra_fields[0].field_value}
{$extra_fields[1].field_value}
{$extra_fields[2].field_value}
{$extra_fields[3].field_value}
{$extra_fields[4].field_value}
...

This will display the field value. To display the field name:

{$extra_fields[X].field} where X = the field ID. Field ID's start at 0.

{$extra_fields[0].field}
{$extra_fields[1].field}
{$extra_fields[2].field}
{$extra_fields[3].field}
{$extra_fields[4].field}
...

Emerson 09-02-2004 08:33 PM

Quote:

Originally Posted by TelaFirma
{$extra_fields[X].field_value} where X = the field ID. Field ID's start at 0.

{$extra_fields[0].field_value}
{$extra_fields[1].field_value}
{$extra_fields[2].field_value}
{$extra_fields[3].field_value}
{$extra_fields[4].field_value}
...

This will display the field value. To display the field name:

{$extra_fields[X].field} where X = the field ID. Field ID's start at 0.

{$extra_fields[0].field}
{$extra_fields[1].field}
{$extra_fields[2].field}
{$extra_fields[3].field}
{$extra_fields[4].field}
...


Awesome, thanks a lot ;)

mizzlewillz 09-15-2004 08:21 AM

How would you go about calling the extra fields in the products.tpl. I was trying some stuff, but I am assuming you need to edit some php files. Has anyone had any success with adding extra fields to the products.tpl?


Thanks in advance,

Mike

sportruck 09-15-2004 03:38 PM

I got it to work, you may have coded something wrong.

Here is an exmaple of what I did. I have many parts that drop ship, so instead of showing stock for these I show the paramater in an extra field, such as "Ships within 2-3 days" or "Custom order, 4-6 week build time". Make an extra field titled "Availability" and check the Show box to show this field on products. For products with nothing in that field it is not shown by default.

Then to turn off the regular stock level display for items that do have something in that field, search for the following code in /customer/main/product.tpl

Code:

{if $config.Appearance.show_in_stock eq "Y" and $config.General.unlimited_products ne "Y" and $product.distribution eq ""}
<TR><TD width="30%">{$lng.lbl_quantity}</TD><TD nowrap><SPAN id="product_avail_txt">{if $product.avail gt 0}{$product.avail}</SPAN>{else}{$lng.txt_no}{/if} {$lng.txt_items_available}</TD></TR>
{/if}


Simply surround that code with an if statement as shown:

Code:

{if $extra_fields[0].field_value eq null}

{if $config.Appearance.show_in_stock eq "Y" and $config.General.unlimited_products ne "Y" and $product.distribution eq ""}
<TR><TD width="30%">{$lng.lbl_quantity}</TD><TD nowrap><SPAN id="product_avail_txt">{if $product.avail gt 0}{$product.avail}</SPAN>{else}{$lng.txt_no}{/if} {$lng.txt_items_available}</TD></TR>
{/if}

{/if}


mizzlewillz 09-15-2004 05:34 PM

Has anyone been successful with adding extra fields to the products.tpl? So far I have not found a solution.

Any comments are welcome

Thanks in advance!

-Mike

Emerson 09-15-2004 05:54 PM

You have the define the section:

Code:

{section name=field loop=$extra_fields}
{if $extra_fields[field].active eq "Y" && $extra_fields[field].field_value}
{$extra_fields[0].field_value}
{$extra_fields[0].field}
{/if}
{/section}


You'll just need to adjust/add/remove the
Code:

{$extra_fields[0].field_value}
{$extra_fields[0].field}

part to show the extra field you want to display ;)

willirl 09-15-2004 07:14 PM

I don't think that will work on the products.tpl page. I think you will have to do some SQL there to get the $extra_fields from the database for the "current product".

mizzlewillz 09-15-2004 07:21 PM

I don't know SQL that well or I would create a statement. I'll give it a try but I don't think I will be able to do much.

-Mike

Emerson 09-15-2004 07:27 PM

Quote:

Originally Posted by willirl
I don't think that will work on the products.tpl page. I think you will have to do some SQL there to get the $extra_fields from the database for the "current product".


You are right, this would work on the product.tpl, not the products.tpl file :oops:

btomasie 02-26-2006 10:38 AM

Bringing this back to life... has anyone tackled this for the products.tpl page? I am trying to use an Extra Field as a way to group all my products into unofficial subcategories all on one page.

Thanks much,
Brian

Total Hosting 03-04-2006 04:29 PM

So why would this work on product.tpl and not products.tpl?
Code:

{if $active_modules.Extra_Fields ne ""}
{include file="modules/Extra_Fields/product.tpl"}
{/if}


Do I need to call the individual extra fields explicitly? I want to display the extra fields on the home page in featured listings, as well as on the category displays.

Thanks.

dashonice 03-07-2006 08:47 AM

It works on product.tpl because product.php gets the extra fields info from the database. Unfortunately products.php does not do this so the variable is not availble to products.tpl.

Total Hosting 03-07-2006 07:36 PM

Ok.

Does anyone know if this is "does not" or "can not" though?

Can the calls that pull the info into product.tpl be called into productS.tpl? Is there a reason why it isn't or couldn't be?

Should this be a thread for the "program logic" area?

Thanks, dash.

willirl 03-08-2006 05:50 AM

Here is the code that I used to get to the extra fields in products.tpl. This code must go inside the product loop. I put it immediately after this code:


Add this code:

Code:

{* Get the product ID as we loop through the products to be displayed *}

{assign var="productId" value=$products[product].productid}
{php}
global $sql_tbl;

// Get the product id from the smarty var

$productid=$this->get_template_vars('productId');

// Get the rows from the extra_field_values table for this product id

if($productid) {
    $extra_fields = func_query(
          "SELECT productid, fieldid, value as field_value
            FROM $sql_tbl[extra_field_values]
        WHERE productid = $productid"
    );
}
$this->assign("extra_fields",$extra_fields);
{/php}


The extra fields are referenced in your code using $extra_fields[<field number>] like this:

Code:

{$extra_fields[2].field_value}

Have fun.

Total Hosting 03-08-2006 07:00 PM

Thanks Willirl.

Do you have a working example? I put your code in the same spot as you indicated, however I am not able to get the extra fields to display.

I tried calling via
Code:

{if $active_modules.Extra_Fields ne ""}
{include file="modules/Extra_Fields/product.tpl"}
{/if}

which is how I am calling them into the product.tpl, as well as directly with
Code:

{$extra_fields[2].field_value}

Is there any way to see what field numbers are in use? I don't see that info in the admin view.

Thanks for the help.

willirl 03-09-2006 05:46 AM

Oops. I forgot about products_t.tpl. Add the same code following these lines:

Code:

{math equation="floor(100/x)" x=$config.Appearance.products_per_row assign="width"}

{section name=product loop=$products}
{assign var="discount" value=0}


The fields are assigned (I think) in the order you specify them in your upload or on your product edit page. The first one is [1] etc..

Total Hosting 03-09-2006 07:29 PM

Not sure why, but I get nothing. I get the extra fields to pull in fine into product.tpl. What am I not seeing?
products.tpl
Code:

<TD valign="top">
<h1 style="margin: 0px; padding-bottom: 5px;"><FONT class="ProductTitle">{$products[product].product}</FONT></h1>

{* Get the product ID as we loop through the products to be displayed *}

{assign var="productId" value=$products[product].productid}
{php}
global $sql_tbl;

// Get the product id from the smarty var

$productid=$this->get_template_vars('productId');

// Get the rows from the extra_field_values table for this product id

if($productid) {
    $extra_fields = func_query(
      "SELECT productid, fieldid, value as field_value
      FROM $sql_tbl[extra_field_values]
        WHERE productid = $productid"
    );
}
$this->assign("extra_fields",$extra_fields);
{/php}



{$extra_fields[2].field_value}

 

{$products[product].descr|truncate:500:"...":true}

products_t.tp
Code:

<TABLE border="0" width="100%" cellpadding="5" cellspacing="1">

{math equation="floor(100/x)" x=$config.Appearance.products_per_row assign="width"}

{section name=product loop=$products}
{assign var="discount" value=0}
{* Get the product ID as we loop through the products to be displayed *}

{assign var="productId" value=$products[product].productid}
{php}
global $sql_tbl;

// Get the product id from the smarty var

$productid=$this->get_template_vars('productId');

// Get the rows from the extra_field_values table for this product id

if($productid) {
    $extra_fields = func_query(
      "SELECT productid, fieldid, value as field_value
      FROM $sql_tbl[extra_field_values]
        WHERE productid = $productid"
    );
}
$this->assign("extra_fields",$extra_fields);
{/php}
{if %product.index% is div by $config.Appearance.products_per_row}
<TR>
{assign var="cell_counter" value=0}
{/if}

{math equation="x+1" x=$cell_counter assign="cell_counter" }

<TD align="center" valign="top" width="{$width}%" class="DialogBox">

{$products[product].product}

<!-- {$lng.lbl_sku}: {$products[product].productcode}
 -->
{$extra_fields[2].field_value}
{if $active_modules.Special_Offers ne "" and $products[product].have_offers}
{include file="modules/Special_Offers/customer/product_offer_thumb.tpl" product=$products[product]}
{else}


here is the page: http://www.empowermentgroup.com/xcart/home.php?cat=26 The products work fine.

Thanks

willirl 03-10-2006 04:47 AM

Peter,

How many extra fields do you have? Which are you trying to show?

If you have only one extra field you should use {$extra_fields[1].field_value} to see the value.

I've double checked the two modules and the changes above are the only ones in the files.

Total Hosting 03-10-2006 11:08 AM

I have a total of 6 extra fields in use at the moment.

You can see them here:
http://www.empowermentgroup.com/xcart/product.php?productid=16134&cat=0&page=1&featured

So I know it's working.

I am just pulling the template to show all extra fields on my product.tpl.

Hmmm. I may have to spend some support points on this one.

Appreciate your help.

Oak1 05-18-2006 10:53 AM

Thank you... it works
 
Hey Guys,

This was on my wish list and it ended up working when plenty of other posts said it would not.

Much appreciated and thanks to the X-Cart-Community.

Oak.

ecommerce 08-04-2006 09:46 PM

im looking to add an extra field but the size of text box, like the description field.

and also want to be able to paste html in that text box.

is that what this is for?

Plug 02-08-2007 12:58 AM

Re: Coding With Product's Extra Fields
 
I seem have got this to partially work. I can get it to display the value of the extra field but not the title of the extra field.

I am using the following code to display this.

{$extra_fields[2].field} {$extra_fields[2].field_value}

Any help would be appreciated.


All times are GMT -8. The time now is 02:55 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.