Date Custom fields

  • Posts: 61
  • Thank you received: 3
1 year 4 months ago #360484

-- HikaShop version -- : 5.0.4
-- 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.

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
1 year 4 months ago #360486

Hi,

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:

SELECT CONCAT('Tomorrow (',DATE_FORMAT(CURDATE() + INTERVAL 1 DAY, '%d/%m/%Y'),')') as value UNION SELECT CONCAT('The day after tomorrow (',DATE_FORMAT(CURDATE() + INTERVAL 2 DAY, '%d/%m/%Y'),')') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 3 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 4 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 5 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 6 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 7 DAY, '%d/%m/%Y') UNION SELECT DATE_FORMAT(CURDATE() + INTERVAL 8 DAY, '%d/%m/%Y');
References:
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

Last edit: 1 year 4 months ago by nicolas.
The following user(s) said Thank You: demoisellegol

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

  • Posts: 61
  • Thank you received: 3
1 month 3 days ago #368039

is there any solution to display this dates with JDATE ?

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

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
1 month 3 days ago #368040

Hi,

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.

The following user(s) said Thank You: demoisellegol

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

  • Posts: 61
  • Thank you received: 3
4 days 14 hours ago #368291

is that possible to clone that calnedar plugin and rename files and functions to create a new one ?
i tried but didnt managed to create a new plugin :(

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

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
4 days 9 hours ago #368292

Hi,

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.

  • Posts: 61
  • Thank you received: 3
4 days 8 hours ago #368293

can i send you the ZIP file of the plugin i've created, so that you may take a a look at it ? maybe there is small mistake which can solve the problem ?

Attachments:

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

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
4 days 1 hour ago #368294

Hi,

In the main PHP file of the plugin, you removed this code:

	public function onFieldsLoad(&$fields, &$options) {
		$me = new stdClass();
		$me->name = 'datepickerfield';
		$me->text = JText::_('DATE_PICKER');
		$me->options = array('required', 'default', 'columnname', 'format', 'allow', 'datepicker_options');

		$fields[] = $me;

		$opt = new stdClass();
		$opt->name = 'datepicker_options';
		$opt->text = JText::_('DATE_PICKER_OPTIONS');
		$opt->own_block = true;
		$opt->obj = 'fieldOpt_datepicker_options';

		$options[$opt->name] = $opt;
	}
This is the code which adds the custom field type defined in your plugin to HikaShop.
You just need to change "datepickerfield" to the new name of your plugin.

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

  • Posts: 61
  • Thank you received: 3
3 days 15 hours ago #368297

thank you

i simplified the function like this :

public function onFieldsLoad(&$fields, &$options) {
		$me = new stdClass();
		$me->name = 'next7daysfield';
		$me->text = JText::_('DATE_DROPDOWN');
		$me->options = array('required', 'default', 'columnname');

		$fields[] = $me;
	}

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 :

Attachments:
Last edit: 3 days 15 hours ago by demoisellegol.

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

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
3 days 10 hours ago #368301

Hi,

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.

  • Posts: 61
  • Thank you received: 3
3 days 10 hours ago #368302

i didnt made any changes to class file ...
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.

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
3 days 7 hours ago #368303

That's not what I'm talking about.
In the main PHP file, you have this code:

		if (!class_exists('hikashopNext7daysfield')) {
			require_once __DIR__ . '/next7daysfield_class.php';
		}
You've added it in the __construct method of the main class plgHikashopNext7daysfield

However, if you check the file plugins/hikashop/datepickerfield/datepickerfield.php you can see the corresponding code
if(defined('HIKASHOP_COMPONENT')) {
	require_once( dirname(__FILE__).DS.'datepickerfield_class.php' );
}
outside of the class definition. I think it's probably why the system can't find the class definition, because the class file is not yet loaded.

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.

  • Posts: 61
  • Thank you received: 3
3 days 7 hours ago #368305

please forget about datepicker field ... in previous posts i said i want to copy that field, however I ended up writing code using chatGPT
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.

  • Posts: 61
  • Thank you received: 3
2 days 15 hours ago #368312

i did'nt managed to achive my field ... would you please tell how much does it cost if you fix this for me ?

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

  • Posts: 84248
  • Thank you received: 13691
  • MODERATOR
2 days 13 hours ago #368315

Hi,

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.

Time to create page: 0.089 seconds
Powered by Kunena Forum