Jump to content

How to : Display a custom field on the product list - 1.6


Recommended Posts

Hi everyone,

 

I'm currently struggling with an issue which is displaying a custom field on my product_list.tpl. The field has already been created in the database, and is correctly displayed in the product.tpl file with the following : 

<h2 class="book-subtitle">{$product->xtd_name2|escape:'html':'UTF-8'}</h2>

I tried to use the same line on my product-list page, however, it doesn't seem to work and I just don't get the reason.

 

 

Thanks for your help !

 

PS : My shop uses Prestashop 1.6

Link to comment
Share on other sites

I'm still struggling with this one issue. Got the same problem with my manufacturer-list.tpl (I tried creating a custom field again and to display it on the list)

 

This is kind of confusing because the previous answer seemed logical to me and I have no clue about where to look at to find the answer  :mellow:

Link to comment
Share on other sites

  • 2 weeks later...

Ok, so the answer for my question was here : https://www.prestashop.com/forums/topic/296666-solved-custom-field-not-reflecting-in-productlist-and-home-featured-need-help/

 

To display a custom field on the product-list page, you have to edit the getProduct() function of the classes/Category.php and add a query for your field. 

 

In my example, I added " pl.`xtd_name2` "

$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, pl.`description`, pl.`description_short`, pl.`available_now`,
					pl.`available_later`, pl.`link_rewrite`, pl.`xtd_name2`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, MAX(image_shop.`id_image`) id_image,
					il.`legend`, m.`name` AS manufacturer_name, cl.`name` AS category_default,
					DATEDIFF(product_shop.`date_add`, DATE_SUB(NOW(),
					INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).'
						DAY)) > 0 AS new, product_shop.price AS orderprice

Thanks to vekia and to his answer from 1 year ago !

  • Like 2
Link to comment
Share on other sites

  • 6 months later...

Hi Nadium,

 

I'm in exactly the same situation as you were, except this solution doesn't seem to be working. In my case, I've added an 'author' field - it's all working fine in the db and the product page but doing the above edit to the classes/Category.php just seems to break it, causing no items to be listed on the home page or when filtering by category. I've just added the following:

 

pl.`author`

 

Is there something else I'm missing?

 

Thanks!

 

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...