add dropdown list with data from database

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #216958

-- HikaShop version -- : 2.2.2
-- Joomla version -- : 2.5.9

Hello,
I would like to create a custom field in the product view in a form of a dropdown list bu with choice of values coming from the database depending on different conditions and the choice being recorded in the order.
I can build myself the query and php code to define the relevant choice data, but i don't know how/where to insert it in Hikashop code. Can you help?

to explain a bit further:
my site would sell online-services; if someone buys several services (e.g. "service A", "service B",.. and uses them, he may later want to add an 'option' to one of the previously purchased service. So he would go to the product list, choose the relevant option (e.g. "Option 1"). In the product view i would like to display the drowpdown list of the services he already purchased, so that we can "associate/link" the 'option1" to the right product.

I hope my explanation helps.
-

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #216965

Hi,

What you want to do is to create a new hikashop plugin and implement the Fields API:
www.hikashop.com/support/support/documen...entation.html#fields
That way you can create a new type of custom field and you can even extend the normal dropdown type class so that you just add the code to load the data from the database.
You can look at the folder plugins/hikashop/datepickerfield/ for an example of how to create such new custom field type.
Then, you will just be able to create a new custom field of the table "item" and of the type of your plugin like you can do with the advanced date picker type plugin.

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #216989

Hi Nicolas,
after several investigations, it appears i may do it in a very different way, so I won't need to create a specific API in the way you described.

However, i have other questions now/

what I would like to do now is :
when a user is in my web site, using a "on line service", if he wishes to add a option, or to change the variant of the service", then he wold click to a link redirecting him to the product page and chose the appropriate "variant" or add an option.
that means that i would need to do the following:
- pass a variable to the product page: How is that possible?
- display some custom fields based on that condition: how is that possible?
- change the price calculation: by reading at some posts, it seems that i build an override of the price calculation. So far no question on this.

Can you help on my two questions ("pass a variable" and "display custom fields based on that variable")?

Last edit: 9 years 11 months ago by rfonta. Reason: new way of achieving desired result

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #217019

Hi,

No, you're wrong. There is no need to modify types/fields.php thanks to the onFieldsLoad trigger you can implement in your plugin in order to add your new type in the list of field types.

You don't need a language file. You don't need that code in your plugin. This plugin is a bit complex as it does a lot of things to handle a lot of cases that you don't care for your custom plugin.

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #217059

Hi Nicolas,
Thanks for your answer.
I am sorry, but in the meantime I figured out that the solution I was looking for was not ideal, so I modified my post to ask you different questions; but unfortunately it seems the changes have been effective too late and you answered to the previous, outdated question.
Could you please answer the new ones; sorry again get about that.

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #217077

Hi,

The non-SEF URL of a product page is like that:
index.php?option=com_hikashop&ctrl=product&task=show&cid=XXX&alias=YYY
where XXX is the id of the product and YYY the alias of the product.
Preselecting a characteristic on the product page can be done by changing XXX to the id of the variant you want to select.
Filling/preselecting a custom item field with something can be done by adding a new parameter to the URL:
&item_data_XXX=YYY
where XXX is the column name of the custom item field and YYY the value you want for it.
There is no system to change the selection of options. That would have to be customized in the file "option" of the view "product".
If you want to display custom item fields based on specific conditions, you can edit the file "show_block_custom_item" via the menu Display>Views and add your condition in there. Note however that if the field is required and you completely remove its HTML, the system will still nag you that the value of the field is missing when you add the product to the cart, so instead, you want to display a hidden input with the value you want for it.

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #217155

Hi Nicolas,
thanks, this seems to go in the right direction.
I believe I may have now to know if i can "restrict" the values of custom field, rather than the custom field itself.
example:
my customer is using a "Product A" (which is a on-line service, such as a questionnaire to fill) with a given option (see example below)
- I want that when he clicks to a "upgrade" option button he is redirect to the product A page (I now know how to do this)
- when in the product page, he can see the different variants but he can only "select" the variants that are higher than his current option
- the new price will be calcutated according to the choice he makes (i understood i will change the price calculation plugin, so I should be ok, using the initial "option" status thanks to passing the variable as you explained in you prior answer)

MY QUESTION IS : how to disable the values of the custom field "option" (i intend to use custom fields rather than characteristics t oselec the option; I hope this is the best way) ? also, if you believe there is a better way of achieving my results I am welcoming other suggestion.
MY EXAMPLE :
the customer is using "product A", with option "category analysis" among the following options :
- "basic" : user can see the results of the questionnaire only in a synthetic way
- "category analysis" : user can see the results of the questionnaire detailed by subcategory of questions
- "full analysis" : user can see full details, up to individual answers

what i want is that the customer can only select the "full analysis" level, not the other ones (he already has them). Actually, the real case is a bit more complicated because I may want him to be able to also "add" more questionnaire answers keeping the same level of analysis (so there will be a second custom field for that.

I actually have a SECOND question, so I am editing my own post to add it.

I realised that i need to change the values and the text of a"Dropdown list" custom field. You explained me before that i can pass variables to change a custom field, but how can I do that for a "Dropdown list" custom field? isn't there a better way then (refer to a specific data base, or a session array, or else?

Last edit: 9 years 11 months ago by rfonta.

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #217165

Hi,

Custom fields are indeed more adapted to what you want to do.
Removing some choices from your dropdown shouldn't be a problem. When you create your plugin implementing the Fields API, you actually can define the display function of the field type class and add whatever HTML/javascript you want for the display of the custom field. If you don't want to add some values, then just don't add it. If you want to disable it, then disable it in the HTML, etc.
If you want to have custom input fields to appear based on the value selected in another field, you can use the "display limited to" setting of the custom fields.

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #217225

Thanks Nicolas,
sorry I am not familiar with this API, could you guide me a bit : where are the files, folders of this API, where can I find detail of what the onFieldsLoad trigger does, what key functions, part of the API to lokk for?

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #217269

After a few hours of educating myself on the API, i can ask more specific questions:
1/ where I load the custom fields to be displayed in the show_block_custom_field?
2/ what is the field I need to put to "disable status" to disable some of the values of my dropdown list?

to explain:
1/ I want load these "item" fields with the values coming from a similar custom field built in the product view (i believe i can do that with simple programming looking at the right place in the database. So I can have my "item" custom fields populated with "product" custom fields
2/ i want to disable some of the values depending on the context

I hope i am not nothering you too much with all my questions; sorry I am not expert in joomla plugins, classes,....

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #217387

Hi,

1. Regarding the onFieldsLoad trigger, if you look at the file types/fields.php which define the available types, you'll see that this trigger is called in order to add the types from the plugins. And if you look at the advanced date picker plugin, you'll see how that is done in such plugin. So you can just copy/paste the function in your own plugin and adapt it to your needs.

2. The key functions to implement are listed in the link I gave you before:
www.hikashop.com/support/support/documen...entation.html#fields
And the best is to look at the advanced date picker custom field type plugin to see how to construct your own plugin.
As I said before, if you redefine the display function in your own custom field type plugin, you can display whatever you want for your HTML. If you want to have a select with disabled values, just echo the dropdown with the values like you want yourself with the name of the select corresponding to what is necessary and that's it.

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

  • Posts: 105
  • Thank you received: 2
9 years 11 months ago #217414

HI thanks,

you are damn right; it took me time to realize that I can do that as you said; but I didn't fully understood until i got more knolwedge about Hikahop structure and Joompla plugins.
I believe I can do that now. Sorry about all these questions.

By the way are you French canadian (I am French but I live with a French canadian girlfriend)?

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

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 11 months ago #217418

Hi,

Don't worry.

I'm French French, like you ;)

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

Time to create page: 0.078 seconds
Powered by Kunena Forum