| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
How to add extra field values to the product list page | ||||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
How to add extra field values to the product list page
Thought I would share this since the older answers do not really work...in XCart 4.7, if you want to have extra fields on the product listing page, you must add the fields to the product loop in products.php...i struggled with this for a few days, but with xcart support's help, i was able to craft this very simple code for my extra fields to show on the product listing page...
In products.php just before the line $smarty->assign('cat_products', isset($products) ? $products : array()); add this code and be sure to change the values to match your extra fields... foreach($products as $c => $v) { $products[$c]['calories'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '2'"); $products[$c]['protein'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '3'"); $products[$c]['fat'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '5'"); $products[$c]['carbs'] = func_query_first_cell("SELECT value FROM $sql_tbl[extra_field_values] WHERE productid='$v[productid]' AND fieldid = '4'"); } $smarty->assign('calories', $calories); $smarty->assign('protein', $protein); $smarty->assign('fat', $fat); $smarty->assign('carbs', $carbs); pay attention to the 'fieldid' in the script...it is at the end of each line and you must figure out which fieldid in the database you want to have the value from...look in the table 'xcart_extra_field_values' and look at the 'fieldid' column and match that to the extra field you are trying to show[/b] in my example, i have some food stuff... Calories, Fat, Protein, Carbs...they are all extra fields and i went into the aforementioned tabled and got their 'fieldid's and then i put them into this script... THEN in products_t.tpl add these smarty tags wherever you want to show the extra field values...be sure to add these tags inside the {foreach}{/foreach} loop {$product.calories} {$product.protein} {$product.fat} {$product.carbs}
__________________
rs |
|||||||
#2
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
I am getting a sql error, can you tell why?
Quote:
Quote:
|
|||||||||
#3
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
Change:
FROM $sql_tbl[xcart_extra_field_values] to: FROM $sql_tbl[extra_field_values] |
|||||||||
#4
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
I've tried all of the below, same syntax error message, same line. Verified it is fieldid 16.
Code:
Code:
Code:
Code:
|
|||||||||
#5
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
$sql_tbl must be present (did you check?). Try adding this before the foreach:
PHP Code:
|
|||||||||
#6
|
|||||||
|
|||||||
Re: How to add extra field values to the product list page
can you post all the relevant code you created for products.php and products_t.tpl?
__________________
Equivox |
|||||||
#7
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
If the data is available, can you tell why this is not returning any values:
Code:
|
|||||||||
#8
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
Print the array to see if the data is there:
<pre>{$products|@print_r}</pre> Make sure you are using .value and not .field_value (as in one of your loops). You could try removing some of the extra code and experiment with the raw loop. Here is a sample I have used: Code:
|
|||||||||
#9
|
|||||||
|
|||||||
try getting the example to code to work EXACTLY as it is presented with only one field first...i would suggest you make your extra field names simpler, they do not have to be capitalized or have underscores, they are for your reference, they do not display anywhere but in admin, so try to make them one word, lowercase...
do not add any other loops outside the main product loop...use my example as is and then go from there once it works... if you are simply inside the main products loop you do not need to add other loops...the extra fields values will already be available in the main loop because of the code added to products.php...you only need the extra field smarty tag for each field you set up... {$product.WHEEL_MATERIAL} just drop that into the template, you do not need extra loops anywhere and you certainly can't use this outside of the main loop and you did not post your code for products.php, so i cannot see if there is a problem there...just try to follow my example exactly as i have made it...
__________________
Equivox Last edited by qualiteam : 03-31-2016 at 03:24 AM. |
|||||||
#10
|
|||||||||
|
|||||||||
Re: How to add extra field values to the product list page
print_r "not allowed by security settings". But looking in webmaster mode/Show variables it appears to now be $cat_products (it works the same as $products too), but there are no extra fields.
this returns only productid: Code:
So does this: Code:
It appears the data has been removed...again? Maybe they removed it because like you said database queries shouldn't be in a loop? So are we back to the original question - how to query the data from the extra_field_values table? Or do you think there is something else to try? Does this apply: http://stackoverflow.com/questions/15262082/add-sql-php-array-to-an-already-existing-array Why do you suppose in rob's solution they did the extra fields individually? I forgot to mention, thank you for helping out Cherie. |
|||||||||
|
|||
X-Cart forums © 2001-2020
|