Custom fields in downloads section?

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188093

-- url of the page with the problem -- : www.spinboom.com
-- 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?

Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
9 years 2 months ago #188095

Hi,

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.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188159

Hey Nicolas!

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:

$select = 'o.order_id, o.order_created, f.*, p.* ';
		$selectSum = ', MIN(o.order_created) as min_order_created, MAX(o.order_created) as max_order_created, SUM(p.order_product_quantity) as file_quantity ';
		$selectUniq = ', IF( REPLACE(LEFT(f.file_path, 1) , \'#\', \'@\') = \'@\', CONCAT(f.file_id, \'@\', o.order_id), f.file_id ) as uniq_id';
		$query = ' FROM '.hikashop_table('order').' AS o ' .
			' INNER JOIN '.hikashop_table('order_product').' AS p ON p.order_id = o.order_id ' .
			' INNER JOIN '.hikashop_table('file').' AS f ON p.product_id = f.file_ref_id ' .
			' WHERE ' . $filters;
		$groupBy = ' GROUP BY uniq_id ';

Unfortunately your suggestion breaks the code and I get an error 1151:
Error: 1051

Unknown table 'op' SQL=SELECT o.order_id, o.order_created, p.*, f.*, op.* , MIN(o.order_created) as min_order_created, MAX(o.order_created) as max_order_created, SUM(p.order_product_quantity) as file_quantity , IF( REPLACE(LEFT(f.file_path, 1) , '#', '@') = '@', CONCAT(f.file_id, '@', o.order_id), f.file_id ) as uniq_id FROM dcbs1_hikashop_order AS o INNER JOIN dcbs1_hikashop_order_product AS p ON p.order_id = o.order_id INNER JOIN dcbs1_hikashop_file AS f ON p.product_id = f.file_ref_id WHERE o.order_type = 'sale' AND o.order_status IN ('shipped','confirmed') AND f.file_ref_id > 0 AND f.file_type = 'file' AND o.order_user_id = 5 GROUP BY uniq_id ORDER BY max_order_created desc LIMIT 0, 20

Any suggestions?

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 2 months ago #188205

Hi,

Please try to just remove ", op.*"

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188262

Hey,

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.

  • Posts: 26000
  • Thank you received: 4004
  • MODERATOR
9 years 2 months ago #188270

Hi,

That's right, there wasn't ; but regarding the error you got, you added it

Unknown table 'op' SQL=SELECT o.order_id, o.order_created, p.*, f.*, op.* , MIN(o.order_created) as min_order_created,

So please leave that line like it was before.

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.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188319

Hi Jerome,

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:

$select = 'o.order_id, o.order_created, f.*, p.* ';
		$selectSum = ', MIN(o.order_created) as min_order_created, MAX(o.order_created) as max_order_created, SUM(p.order_product_quantity) as file_quantity ';
		$selectUniq = ', IF( REPLACE(LEFT(f.file_path, 1) , \'#\', \'@\') = \'@\', CONCAT(f.file_id, \'@\', o.order_id), f.file_id ) as uniq_id';
		$query = ' FROM '.hikashop_table('order').' AS o ' .
			' INNER JOIN '.hikashop_table('order_product').' AS p ON p.order_id = o.order_id ' .
			' INNER JOIN '.hikashop_table('file').' AS f ON p.product_id = f.file_ref_id ' .
			' WHERE ' . $filters;
		$groupBy = ' GROUP BY uniq_id ';

Please help!

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
9 years 2 months ago #188344

Hi,

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.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188434

If I remove the ", op.*" from my current code which I guess you mean the code Nicolas suggested I end up with the same thing I started with.

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.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
9 years 2 months ago #188459

Hi,

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; ?>

The following user(s) said Thank You: Superpsychics

Please Log in or Create an account to join the conversation.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188521

Hey!

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.

  • Posts: 18
  • Thank you received: 0
9 years 2 months ago #188531

Hey again,

All good. I managed to do it like that:

<?php
				$class = hikashop_get('class.product');
				$prod = $class->get($downloadFile->product_id);
				
				$class = hikashop_get('class.product');
				$mainprod = $class->get($prod->product_parent_id);
				echo $mainprod->preview; ?>

What do you think? Is there a better way?

Please Log in or Create an account to join the conversation.

  • Posts: 81515
  • Thank you received: 13069
  • MODERATOR
9 years 2 months ago #188586

Hi,

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 :)

The following user(s) said Thank You: Superpsychics

Please Log in or Create an account to join the conversation.

Time to create page: 0.088 seconds
Powered by Kunena Forum