Custom product listing

I’d like to modify the product listing.
So far, I’ve found a template file which is being used to generate the products.


{% from "erpnext/templates/includes/macros.html" import product_image_square %}

    <a class="product-link" href="{{ route|abs_url }}">
	<div class="col-sm-4 col-xs-4 product-image-wrapper">
		<div class="product-image-img">
			{{ product_image_square(thumbnail or website_image) }}
			<div class="product-text" itemprop="name">{{ item_name }}</div>
			{% if in_stock or not is_stock_item %}
			<div style='color: green'>
				<i class='fa fa-check'></i> {{ _("In stock") }}</div>
			{% else %}
			<div style='color: red'>
				<i class='fa fa-close'></i> {{ _("Not in stock") }}</div>
			{% endif %}

I tried to add a new line to also show the product price on the listing page.

  	<div class="product-price" itemprop="price">{{ price }}</div>


  	<div class="product-price" itemprop="standard_rate">{{ standard_rate }}</div>

but they don’t seem to work. All I get returned is:

{{ undefined value printed: parameter ‘standard_rate’ was not provided }}

Where should I add the extra field so it would get asked from the database during page creation?

1 Like

I found a way to get it working.

The trick was to call frappe.db.get_value( ) with proper parameters to query the price from the database.
I added this line, so now it returns the data I need. (The euro sign is just to make it look currency.)

`<div class="product-price" itemprop="price">
{{ frappe.db.get_value("Item", {'item_code': item_code}, "standard_rate") }} €

I still wonder how could I format the number/string that gets returned by frappe.db.getvalue().
Now it returns a number like 100.5 but it looks weird as the decimal separator at our location is a comma not a period. What I would like to do next is to format the number/string so it would use a comma as as decimal separator, for example 100,5 not 100.5
Any ideas?


Did you try configuring the Number Format in System settings?

Yes, I have changed it in System settings. That seems to only affect numbers “inside” ERPNext not through the public website. Maybe I should try to use either the locale settings in Python or just have Jinja templating round filter take care of the extra decimals.
{{ frappe.db.get_value("Item", {'item_code': item_code}, "standard_rate")|round }}

I was able to format the output with Jinja round filter. The trick was to also add int filter after round filter.

{{ frappe.db.get_value("Item", {'item_code': item_code}, "standard_rate")|round|int }}

Apparently it seems that only Jinja templating functions are available to use here, as Python built-in function int() causes undefined error.

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 39, in render
    data = render_page_by_language(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 133, in render_page_by_language
    return render_page(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 149, in render_page
    return build(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 156, in build
    return build_page(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 169, in build_page
    context = get_context(path)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 28, in get_context
    context = build_context(context)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/website/", line 89, in build_context
    ret = context.doc.get_context(context)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/item_group/", line 69, in get_context
    limit=context.page_length + 1, search=frappe.form_dict.get("search")),
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/item_group/", line 111, in get_product_list_for_group
    return [get_item_for_list_in_html(r) for r in data]
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/setup/doctype/item_group/", line 145, in get_item_for_list_in_html
    return frappe.get_template(products_template).render(context)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/frappe/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/./templates/includes/products_as_grid.html", line 8, in top-level template code
    <div class="product-price" itemprop="price">{{ int( frappe.db.get_value("Item", {'item_code': item_code}, "standard_rate") ) }} €</div>
UndefinedError: 'int' is undefined

this issue seems to be similar, please have a look

Hi @tatu ,
Are you modifying the original html file or are you making a copy in your app?
Because when I try to make mod in a copy it doesn’t work.