- Posts: 61
- Thank you received: 3
Date Custom fields
- demoisellegol
-
Topic Author
- Offline
-- Joomla version -- : 5.1.0
-- PHP version -- : 8.1
can you please assist on creating a radio buttons custom field on checkout page with dynamic valuse of 7 days i a row from tomorrow ?
suppose today is 4/22/2024
i need to create a custom field of type radio in checkout page with this values :
Tomorrow (4/23/2024)
The day after tomrrow (4/24/2024)
4/25/2024
4/26/2024
4/27/2024
4/28/2024
4/29/2024
Please Log in or Create an account to join the conversation.
In the data area of your custom field, instead of entering values, you can provide a MySQL query.
There, you can provide a MySQL query to generate the dates.
For example:
www.w3schools.com/sql/func_mysql_curdate.asp
www.w3schools.com/sql/func_mysql_date_format.asp
dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html
www.w3schools.com/sql/func_mysql_concat.asp
dev.mysql.com/doc/refman/8.0/en/union.html
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
Please Log in or Create an account to join the conversation.
Are you talking about JDate ?
docs.joomla.org/How_to_use_JDate
If so, I understand you're saying that you want to be able to use PHP code to generate the values selectable by the custom field. Is that so ?
It is possible but it's not as easy as the MySQL query solution I provided in my previous message. With the MySQL query, you just test the query you need via PHPMyAdmin or an online MySQL query testing website. Once you have the query, you can just copy / paste it in your field settings.
With PHP, you need to develop a plugin of the group "hikashop" and implement the "Field API" :
www.hikashop.com/support/documentation/6...entation.html#fields
With it, you can add your own type of custom field, have it extend the normal radio field class, and manually generate the values with your own PHP code and / or with JDate. An example of a plugin using this API to add a custom field type is in the folder plugins/hikashop/datepickerfield/
It adds the "Advanced Date Picker" custom field type to HikaShop.
As you probably understand, doing what you asked for as a custom plugin with the Field API and JDate is more complex and will take more time than the MySQL query, so I still recommand you to use the MySQL query solution.
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
i tried but didnt managed to create a new plugin
Please Log in or Create an account to join the conversation.
Yes, it's totally possible.
Just make sure you unpublish the original plugin so that your plugin can take over its place.
Besides changing the filenames and folder name, you also need to change the class name in the main PHP file, and the element in the XML file.
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
Please Log in or Create an account to join the conversation.
In the main PHP file of the plugin, you removed this code:
You just need to change "datepickerfield" to the new name of your plugin.
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
i simplified the function like this :
the field type of DATE_DROPDOWM appeared in creating new field in backend. in frontend i get this :
"Plugin plg.hikashopNext7daysfield missing or deactivated"
but the plugin is installed and actived as you can see :
Please Log in or Create an account to join the conversation.
It's probably because you moved the require_once of the class file to put it inside the constructor of the plugin. I would recommend you do like in the default date picker field plugin and have it outside of the class definition in the main PHP file of the plugin.
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
I'm very close to what i was looking for ... could you please assit me little more to achive this fields ..
thanks in advance
Please Log in or Create an account to join the conversation.
In the main PHP file, you have this code:
However, if you check the file plugins/hikashop/datepickerfield/datepickerfield.php you can see the corresponding code
Also, you're saying that you didn't make any change to the class file, but as far as I can see, the class file in your zip is quite different from what is in the default date picker field. When you're doing something like this, the best is to make a copy of the plugin, change only the filenames and classnames so that you can get the same result as the default one. And once that's working, you can go from there and start modifying things around for your needs. At least, that's how I do it.
For example, another issue you'll have is that you deleted the "show" method in your hikashopNext7daysfield class.
This method is used to display the entered value to the user. It is essential to have one, like in the default date picker field plugin.
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
i did not used datepicker field at all
I will try this last modifications you sent to see if it works or not
Please Log in or Create an account to join the conversation.
- demoisellegol
-
Topic Author
- Offline
- Posts: 61
- Thank you received: 3
Please Log in or Create an account to join the conversation.
It depends how long it takes for me to fix everything.
Code generated with ChatGPT is usually filled with bugs.
I will charge 60€ per hour of work.
Please go through our contact form :
www.hikashop.com/support/contact-us.html
Please Log in or Create an account to join the conversation.