[Skip to main content](#vessel-content)

#   Custom fields value in product listing

##

- **[assun](/forum/user/19855-assun "View assun's Profile")**
- [![assun's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar_2013-06-12.jpg)](/forum/user/19855-assun "View assun's Profile") Topic Author
- [ Offline](/forum/user/19855-assun)

Less More

- Posts: 3
- Thank you received: 0
-
-
-
- [](http://www.BLiDiS.com)
-

6 years 6 months ago [\#317107](#317107) by [assun](/forum/user/19855-assun "View assun's Profile")  *[Custom fields value in product listing](/forum/26-product-category-display/899462-custom-fields-value-in-product-listing#317107 "-- HikaShop version -- : 4.2.3 -- Joomla version -- : 3.9.16 -- PHP version -- : 7.2.24 -- Browser(s) name and version -- : Chrome  Hi, I want to attach a file (zip, pdf…) to the products that the client can download. I know of a built-in HikaShop system that does just that. I upload the file to the product and make it free to download. The problem is that I want to know how many times a file has been downloaded. This is not possible in HikaShop. That's why I'm thinking of using the jDownloads component. It has a plugin that with a specific string / {jd&#95;file file == 1} / previews a download button /  Download  /. And the component provides statistics for downloads.  I created a Custom field - Table-&gt; product, Field type-&gt; text, Column name-&gt; dw&#95;file, Label-&gt; Download, Front-end-&gt; NO. There I enter the string / {jd&#95;file file == 1} / in the product. I found in the forum: $fieldsClass = hikashop&#95;get('class.field'); $fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category'); foreach ($fields as $fieldName =&gt; $oneExtraField) { if ($oneExtraField-&gt;field&#95;namekey == 'dw&#95;file') $myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key); } …  echo $myfile;?&gt;  I put this code in product-&gt; listing&#95;img&#95;title and product-&gt; show&#95;default, but I can't figure out why it doesn't work.  I ask for your assistance.  Best Regards")* was created by *[assun](/forum/user/19855-assun "View assun's Profile")*

-- HikaShop version -- : 4.2.3
-- Joomla version -- : 3.9.16
-- PHP version -- : 7.2.24
-- Browser(s) name and version -- : Chrome

Hi,
I want to attach a file (zip, pdf…) to the products that the client can download. I know of a built-in HikaShop system that does just that. I upload the file to the product and make it free to download. The problem is that I want to know how many times a file has been downloaded. This is not possible in HikaShop.
That's why I'm thinking of using the jDownloads component. It has a plugin that with a specific string / *{jd\_file file == 1}* / previews a download button / *&lt;a href="/component/jdownloads/send/…" alt="Download" class="jdbutton jmedium"&gt; Download &lt;/ a&gt;* /. And the component provides statistics for downloads.

I created a **Custom field** - Table-&gt; **product**, Field type-&gt; **text**, Column name-&gt; **dw\_file**, Label-&gt; **Download**, Front-end-&gt; **NO**. There I enter the string / *{jd\_file file == 1}* / in the product.
I found in the forum:
*$fieldsClass = hikashop\_get('class.field');
$fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category');
foreach ($fields as $fieldName =&gt; $oneExtraField) {
if ($oneExtraField-&gt;field\_namekey == 'dw\_file')
$myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key);
}
…
&lt;div&gt; &lt;?php&gt;echo $myfile;?&gt;&lt;/div&gt;*

I put this code in *product-&gt; listing\_img\_title* and *product-&gt; show\_default*, but I can't figure out why it doesn't work.

I ask for your assistance.

Best Regards

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTk0NjItY3VzdG9tLWZpZWxkcy12YWx1ZS1pbi1wcm9kdWN0LWxpc3Rpbmc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

6 years 6 months ago [\#317109](#317109) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom fields value in product listing](/forum/26-product-category-display/899462-custom-fields-value-in-product-listing#317109 "-- HikaShop version -- : 4.2.3 -- Joomla version -- : 3.9.16 -- PHP version -- : 7.2.24 -- Browser(s) name and version -- : Chrome  Hi, I want to attach a file (zip, pdf…) to the products that the client can download. I know of a built-in HikaShop system that does just that. I upload the file to the product and make it free to download. The problem is that I want to know how many times a file has been downloaded. This is not possible in HikaShop. That's why I'm thinking of using the jDownloads component. It has a plugin that with a specific string / {jd&#95;file file == 1} / previews a download button /  Download  /. And the component provides statistics for downloads.  I created a Custom field - Table-&gt; product, Field type-&gt; text, Column name-&gt; dw&#95;file, Label-&gt; Download, Front-end-&gt; NO. There I enter the string / {jd&#95;file file == 1} / in the product. I found in the forum: $fieldsClass = hikashop&#95;get('class.field'); $fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category'); foreach ($fields as $fieldName =&gt; $oneExtraField) { if ($oneExtraField-&gt;field&#95;namekey == 'dw&#95;file') $myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key); } …  echo $myfile;?&gt;  I put this code in product-&gt; listing&#95;img&#95;title and product-&gt; show&#95;default, but I can't figure out why it doesn't work.  I ask for your assistance.  Best Regards")*

Hi,

The main reason this doesn't work is because the line :
$fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category');
should be:
$fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'product');
if you want to get the custom fields of the table "product" and not the custom fields of the table "category".
Change that and it should hopefully work.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTk0NjItY3VzdG9tLWZpZWxkcy12YWx1ZS1pbi1wcm9kdWN0LWxpc3Rpbmc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[assun](/forum/user/19855-assun "View assun's Profile")**
- [![assun's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar_2013-06-12.jpg)](/forum/user/19855-assun "View assun's Profile") Topic Author
- [ Offline](/forum/user/19855-assun)

Less More

- Posts: 3
- Thank you received: 0
-
-
-
- [](http://www.BLiDiS.com)
-

6 years 6 months ago [\#317135](#317135) by [assun](/forum/user/19855-assun "View assun's Profile")  Replied by *[assun](/forum/user/19855-assun "View assun's Profile")* on topic *[Custom fields value in product listing](/forum/26-product-category-display/899462-custom-fields-value-in-product-listing#317135 "-- HikaShop version -- : 4.2.3 -- Joomla version -- : 3.9.16 -- PHP version -- : 7.2.24 -- Browser(s) name and version -- : Chrome  Hi, I want to attach a file (zip, pdf…) to the products that the client can download. I know of a built-in HikaShop system that does just that. I upload the file to the product and make it free to download. The problem is that I want to know how many times a file has been downloaded. This is not possible in HikaShop. That's why I'm thinking of using the jDownloads component. It has a plugin that with a specific string / {jd&#95;file file == 1} / previews a download button /  Download  /. And the component provides statistics for downloads.  I created a Custom field - Table-&gt; product, Field type-&gt; text, Column name-&gt; dw&#95;file, Label-&gt; Download, Front-end-&gt; NO. There I enter the string / {jd&#95;file file == 1} / in the product. I found in the forum: $fieldsClass = hikashop&#95;get('class.field'); $fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category'); foreach ($fields as $fieldName =&gt; $oneExtraField) { if ($oneExtraField-&gt;field&#95;namekey == 'dw&#95;file') $myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key); } …  echo $myfile;?&gt;  I put this code in product-&gt; listing&#95;img&#95;title and product-&gt; show&#95;default, but I can't figure out why it doesn't work.  I ask for your assistance.  Best Regards")*

This is obvious… how could I have missed it. ![:)](/media/kunena/emoticons/3.png ":)")
I replaced Category with Product
and the following error has appeared:
*Call to undefined method hikashop::show()*

So I did the following:
*$fieldsClass = hikashop\_get('class.field');
$fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'product');
foreach ($fields as $fieldName =&gt; $oneExtraField) {
if ($oneExtraField-&gt;field\_namekey == 'dw\_file')
$myfile = $oneExtraField-&gt;field\_type;
}*
But $ myfile remains empty.

I looked:
*echo '&lt;pre&gt;';
print\_r ($fields);
echo '&lt;/pre&gt;';*

and found that only when the Custom fields is “text”, [field_value] =&gt; is empty.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTk0NjItY3VzdG9tLWZpZWxkcy12YWx1ZS1pbi1wcm9kdWN0LWxpc3Rpbmc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

6 years 6 months ago [\#317155](#317155) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Custom fields value in product listing](/forum/26-product-category-display/899462-custom-fields-value-in-product-listing#317155 "-- HikaShop version -- : 4.2.3 -- Joomla version -- : 3.9.16 -- PHP version -- : 7.2.24 -- Browser(s) name and version -- : Chrome  Hi, I want to attach a file (zip, pdf…) to the products that the client can download. I know of a built-in HikaShop system that does just that. I upload the file to the product and make it free to download. The problem is that I want to know how many times a file has been downloaded. This is not possible in HikaShop. That's why I'm thinking of using the jDownloads component. It has a plugin that with a specific string / {jd&#95;file file == 1} / previews a download button /  Download  /. And the component provides statistics for downloads.  I created a Custom field - Table-&gt; product, Field type-&gt; text, Column name-&gt; dw&#95;file, Label-&gt; Download, Front-end-&gt; NO. There I enter the string / {jd&#95;file file == 1} / in the product. I found in the forum: $fieldsClass = hikashop&#95;get('class.field'); $fields = $fieldsClass-&gt;getFields('frontcomp', $this-&gt;row, 'category'); foreach ($fields as $fieldName =&gt; $oneExtraField) { if ($oneExtraField-&gt;field&#95;namekey == 'dw&#95;file') $myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key); } …  echo $myfile;?&gt;  I put this code in product-&gt; listing&#95;img&#95;title and product-&gt; show&#95;default, but I can't figure out why it doesn't work.  I ask for your assistance.  Best Regards")*

Hi,

The line:
$myfile = $fieldsClass-&gt;show($val,$this-&gt;row-&gt;$key);
should be:
$myfile = $fieldsClass-&gt;show($oneExtraField,$this-&gt;row-&gt;$fieldName);
in your previous code.

Now, the error "Call to undefined method hikashop::show()" cannot happen with your previous code.
That would indicate that $fieldsClass is of the class "hikashop" which is not possible. So you must have changed something else.

And it's normal that $field-&gt;field_value is empty as this variable contains the list of values to choose from in dropdowns, radio / checkbox lists, etc.
If you don't want to use the show function, you can directly do:
$myfile = $this-&gt;row-&gt;$fieldName;
This should display the same thing as with the call to the show function for custom fields of the type "text".

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84OTk0NjItY3VzdG9tLWZpZWxkcy12YWx1ZS1pbi1wcm9kdWN0LWxpc3Rpbmc/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.082 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
