how to enter a db query into a custom field

  • Posts: 114
  • Thank you received: 4
7 years 6 months ago #269241

-- HikaShop version -- : 3.0.1
-- Joomla version -- : 3.7.0
-- PHP version -- : 5

I could not find a hint in the docs how to enter my db query into a custom field. I need to fill a single select dropdown with values from a my custom table.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
7 years 6 months ago #269251

Hi,

There is no easy way.
The best would be to write your own type of custom field plugin thanks to the custom field API:
www.hikashop.com/support/documentation/6...entation.html#fields
You would have to extend the singledropdown type class and override the display function in order to load the values of the field before calling the parent display function for the display of the dropdown.
As to how to build such custom field type plugin, you can look at how we did it for the advanced datepicker custom field type, which is also done by a plugin in the folder plugins/hikashop/datepickerfield of your website.

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

  • Posts: 114
  • Thank you received: 4
7 years 6 months ago #269431

Thanks. I made that select field but although there are 5 values the product page displayes only the default value in a div with class "hikashop_product_custom_listing_id_line" instead of a dropdown where the buyer can choose what option he wants to have on the product. What setting of that field do I have to change to display all available values in a dropdown?

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
7 years 6 months ago #269454

Hi,

That's because you've created a custom field of the table "product" and not a custom field of the table "item".
Delete the one you have and recreate it with the correct table and it should display like you want.

The following user(s) said Thank You: peteo

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

  • Posts: 114
  • Thank you received: 4
7 years 6 months ago #269458

Thank you for the quick reply. That was it, works now as expected.

problem A: I set all switches to Yes in the Display section of that field yet in the checkout list that field does not show up in the product. Is there an additional option for that?

problem B: The workflow is a bit cluttered. Sometimes my dynamic select field contains only one option meaning the user cannot choose since only one option is available but in the product container the button "Choose options" is still displayed which doesn't make much sense. Is there an option in backend to not display that "Choose options" button when only one option is available?

Last edit: 7 years 6 months ago by peteo.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
7 years 6 months ago #269464

Hi,

No.
The custom field will only display if you have selected/entered something in it. If you leave it empty and add the product to cart, the product will display in the cart without the custom field value listed below the name.
Also, it's possible that you have some view override of an old version of HikaShop which doesn't display the cart properly and check an old display option of the custom field. Try switching to the template template of Joomla and see if you see a change with it. If so, then the problem is that and you'll have to remove the customized code in the view file of the cart in the checkout and add the modifications to the new version of the view file.

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

  • Posts: 114
  • Thank you received: 4
7 years 6 months ago #269663

I tried to code the plugin but cant find the right trigger I tried onBeforeProductListingLoad(&$filters,&$order,&$parent, &$select, &$select2, &$a, &$b, &$on) but that does not seem to get me anywhere. What do you mean by "extend the singledropdown type class and override the display function". I cant find "singledropdown" in the docs. Would you be able to point me to the correct docs page or give a quickly drawn raw example with which I could start? Thanks.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
7 years 6 months ago #269743

Hi,

I already gave you all that.
The link I gave ( www.hikashop.com/support/documentation/6...entation.html#fields ) points to the fields API that you should implement in your plugin in order to do that.
And as an example, you can look at the folder plugins/hikashop/datepickerfield of your website which implements a custom field type "advanced date picker".
When I'm talking about extending the singledropdown class, I'm talking about the class named hikashopFieldSingledropdown that you can find in administrator/components/com_hikashop/classes/field.php

The following user(s) said Thank You: peteo

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

Time to create page: 0.064 seconds
Powered by Kunena Forum