Custom fields value in product listing
6 years 6 months ago #317107
by assun
Custom fields value in product listing was created by assun
-- 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 / <a href="/component/jdownloads/send/…" alt="Download" class="jdbutton jmedium"> Download </ a> /. And the component provides statistics for downloads.
I created a Custom field - Table-> product, Field type-> text, Column name-> dw_file, Label-> Download, Front-end-> 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->getFields('frontcomp', $this->row, 'category');
foreach ($fields as $fieldName => $oneExtraField) {
if ($oneExtraField->field_namekey == 'dw_file')
$myfile = $fieldsClass->show($val,$this->row->$key);
}
…
<div> <?php>echo $myfile;?></div>
I put this code in product-> listing_img_title and product-> show_default, but I can't figure out why it doesn't work.
I ask for your assistance.
Best Regards
-- 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 / <a href="/component/jdownloads/send/…" alt="Download" class="jdbutton jmedium"> Download </ a> /. And the component provides statistics for downloads.
I created a Custom field - Table-> product, Field type-> text, Column name-> dw_file, Label-> Download, Front-end-> 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->getFields('frontcomp', $this->row, 'category');
foreach ($fields as $fieldName => $oneExtraField) {
if ($oneExtraField->field_namekey == 'dw_file')
$myfile = $fieldsClass->show($val,$this->row->$key);
}
…
<div> <?php>echo $myfile;?></div>
I put this code in product-> listing_img_title and product-> show_default, but I can't figure out why it doesn't work.
I ask for your assistance.
Best Regards
Please Log in or Create an account to join the conversation.
6 years 6 months ago #317109
by nicolas
Replied by nicolas on topic Custom fields value in product listing
Hi,
The main reason this doesn't work is because the line :
$fields = $fieldsClass->getFields('frontcomp', $this->row, 'category');
should be:
$fields = $fieldsClass->getFields('frontcomp', $this->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.
The main reason this doesn't work is because the line :
$fields = $fieldsClass->getFields('frontcomp', $this->row, 'category');
should be:
$fields = $fieldsClass->getFields('frontcomp', $this->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 or Create an account to join the conversation.
6 years 6 months ago #317135
by assun
Replied by assun on topic Custom fields value in product listing
This is obvious… how could I have missed it. 
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->getFields('frontcomp', $this->row, 'product');
foreach ($fields as $fieldName => $oneExtraField) {
if ($oneExtraField->field_namekey == 'dw_file')
$myfile = $oneExtraField->field_type;
}
But $ myfile remains empty.
I looked:
echo '<pre>';
print_r ($fields);
echo '</pre>';
and found that only when the Custom fields is “text”, [field_value] => is empty.
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->getFields('frontcomp', $this->row, 'product');
foreach ($fields as $fieldName => $oneExtraField) {
if ($oneExtraField->field_namekey == 'dw_file')
$myfile = $oneExtraField->field_type;
}
But $ myfile remains empty.
I looked:
echo '<pre>';
print_r ($fields);
echo '</pre>';
and found that only when the Custom fields is “text”, [field_value] => is empty.
Please Log in or Create an account to join the conversation.
6 years 5 months ago #317155
by nicolas
Replied by nicolas on topic Custom fields value in product listing
Hi,
The line:
$myfile = $fieldsClass->show($val,$this->row->$key);
should be:
$myfile = $fieldsClass->show($oneExtraField,$this->row->$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->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->row->$fieldName;
This should display the same thing as with the call to the show function for custom fields of the type "text".
The line:
$myfile = $fieldsClass->show($val,$this->row->$key);
should be:
$myfile = $fieldsClass->show($oneExtraField,$this->row->$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->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->row->$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 or Create an account to join the conversation.
Time to create page: 0.185 seconds