- Posts: 18
- Thank you received: 0
Custom fields in downloads section?
- Superpsychics
-
Topic Author
- Offline
-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.1
-- PHP version -- : 5.4.34
Hey,
I'm trying for a while to add some custom fields from my products into the downloads section.
I was successful in customizing the product tables with custom fields, see example below:
www.spinboom.com/index.php/en/categories/category/film
But I can't get the same result on the Downloads page through the downloads.php I have altered the section a little but I can't add new product fields successfully. (In order to view the downloads page, you have to sign up, so I included a screenshot.)
I would like to add Images and some of my custom product fields like "Preview" to the Downloads section. I'm having trouble echo-ing them through php from the downloads.php file.
Any help?
Please Log in or Create an account to join the conversation.
It's normal that you have a hard time since the product data is not loaded on the downloads listing.
Change the line:
$select = 'o.order_id, o.order_created, f.*, op.* ';
to:
$select = 'o.order_id, o.order_created, p.*, f.*, op.* ';
in the file components/com_hikashop/views/user/view.html.php and that will add the product data in the rows of data.
So you'll be able to display your custom product fields data easily with something like that:
<?php echo $downloadFile->custom_field; ?>
like on the products listing.
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
Thank you for your quick response and for pointing me in the right direction.
My components/com_hikashop/views/user/view.html.php file looks like that before changing anything:
Unfortunately your suggestion breaks the code and I get an error 1151:
Any suggestions?
Please Log in or Create an account to join the conversation.
Please try to just remove ", op.*"
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
There was no op in my file, just:
$select = 'o.order_id, o.order_created, f.*, p.* ';
Please Log in or Create an account to join the conversation.
That's right, there wasn't ; but regarding the error you got, you added it
So please leave that line like it was before.Unknown table 'op' SQL=SELECT o.order_id, o.order_created, p.*, f.*, op.* , MIN(o.order_created) as min_order_created,
Nicolas gave you a line to replace ; and it was a line from HikaShop 2.3.5.
But you are not using HikaShop 2.3.5 so you don't have the same line to replace ; that's why it is introducing you an error.
So you have to add the "p.*" but not the "op.*" !
Regards,
Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
As I stated in my first post I'm using -- HikaShop version -- : 2.3.2
The components/com_hikashop/views/user/view.html.php file before I changed anything suggested by Nicolas was:
$select = 'o.order_id, o.order_created, f.*, p.* ';
So "p.*" was already there. And still is. But it's not working. You can see the rest of the original code following $suggest here:
Please help!
Please Log in or Create an account to join the conversation.
I think we were not clear enough, in the original file, there is no "op" present, but in the code given by Nicolas it is present and has to be removed. Because this "op" data has been added in a more recent version than yours.
So in your current code, juste remove ", op.*" because it should not be there.
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
My original code was
$select = 'o.order_id, o.order_created, f.*, p.* ';
and you are telling me to remove op from NIcolas' suggestion so I get again
$select = 'o.order_id, o.order_created, f.*, p.* ';
You are asking me to not change anything in the code I already had and wasn't working anyway...
Could you please look into the question again from the beginning of the thread?
I am trying to load the product data on the downloads listing...
Please Log in or Create an account to join the conversation.
Sorry for that. I had assumed that you had the latest version.
With HikaShop 2.3.2, it's more complex to do that as the query to load the data is not made to catter for the loading of the product data.
The simplest would be to use such code in your downloads view file:
<?php
$class = hikashop_get('class.product');
$prod = $class->get($downloadFile->product_id);
echo $prod->custom_field; ?>
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
Thank you Nicolas! We are getting there. That works but now my problem is that this now links to the characteristic variant product.
I use characteristic variants to link multiple files to each product (an mp3 and a wav file) so that users have the option to select what file they want to buy from a characteristic dropdown (Filetype Select) for example: www.spinboom.com/index.php/en/categories/product/clear
So the order product ID is linked to the characteristic variant and not the main product. All the custom fields have information in the main product unfortunately. Is there a way to point to the main product?
I tried searching through my sql database and find where the link is happening between the variant and the main product but no luck yet.
Please Log in or Create an account to join the conversation.
- Superpsychics
-
Topic Author
- Offline
- Posts: 18
- Thank you received: 0
All good. I managed to do it like that:
What do you think? Is there a better way?
Please Log in or Create an account to join the conversation.
The better way would be to update your HikaShop and that would allow you to load the product parent with the get function directly from the product_parent_id in $downloadFile. That would reduce the MySQL queries on the page.
Other than that, it's ok like that
Please Log in or Create an account to join the conversation.