Just starting this thread to report on things I found while trying this and perhaps some things could be improved
This is mainly the datepicker being used as a delivery date (and in my case a collection date as well)
example cart http://www.nicotransport.nl/cart
1. language of date picker:
this is broken
needs in vmjsapi.php
$lg = JFactory::getLanguage();
$lang = $lg->getTag();
$vlePath = vmJsApi::setPath('i18n/jquery.ui.datepicker-'.$lang, FALSE , '' ,$minified = NULL , 'js', true);
if(!file_exists($vlePath) or is_dir($vlePath)){
//GJC
$lang = substr($lang, 0, 2);
$vlePath = vmJsApi::setPath('i18n/jquery.ui.datepicker-'.$lang, FALSE , '' ,$minified = NULL , 'js', true);
if(!file_exists($vlePath) or is_dir($vlePath)){
//GJC
$lang = 'en-GB';
//GJC
}
//GJC
2: over riding the datepicker display. this is very easy in this case in \templates\xxxx\html\com_virtuemart\cart\default_cartfields.php
will accept and over ride the vmjsapi JS with all or any of the std. Jq datepicker code and if you load js.cookies
e.g.
$doc = JFactory::getDocument();
$doc->addScript("templates/xxxx/html/com_virtuemart/js/js.cookie.js");
you can store locally the fields for refresh, address etc
e.g.
jQuery(document).on( "focus",".datepicker", function() {
if(this.id == 'vm_deliver_date_field_text'){
//console.log('this.id 0 ',this.id);
jQuery( this ).datepicker({
beforeShowDay: unavailable,
firstDay: 1,
changeFirstDay: false,
minDate: +3,
changeMonth: true,
changeYear: true,
yearRange: yearRange,
dateFormat:"dd-mm-yy",
altField: $(this).prev(),
defaultDate: +2,
onSelect: function(dateText) {
Cookies.set('delivery_date',dateText);
var currentDate = jQuery( this ).datepicker( "getDate" );
var weekday = currentDate.getDay();
console.log('currentDate ',currentDate);
console.log('weekday ',weekday);
if(weekday == 6) {//remove Sat afternoon
Cookies.set('delivery_time','');
jQuery("#vm_deliver_time").find('option').removeAttr("selected");
jQuery('#vm_deliver_time option[value="VM_DELIVER_NACHMORGEN"]').remove();
jQuery('#vm_deliver_time').trigger("liszt:updated");
}
console.log('weekday ',weekday);
location.reload(); // to set deliver date in collect
}
});
}else{//collection date.. cont for other datepicker
3: the display in the BT dialogue
this can be prevented in templates\xxxx\html\com_virtuemart\user\edit_address_userfields.php with e.g.
$ignore = array('vm_deliver_date', 'vm_deliver_time', 'vm_collection_date', 'vm_collection_time', 'afval');
//and in the loop
} elseif (in_array($field['name'], $ignore)) { //drop delivery fields
// ignore
continue;
}else {//......
4: the validation is a problem if they are required as it redirects u to the BT address
quick fix hack was: components\com_virtuemart\helpers\cart.php ~ line 935
public function checkoutData($redirect = true) {
//GJC
$this->_redirect = false;
//GJC
then stays on cart page
4: datepicker readonly .. this setting in the shopper fields is ignored.. just needs incl. in the vmjsapi rendering
quick fix:
jQuery('#vm_deliver_date_field_text, #vm_collection_date_field_text').prop('readonly', true);
5. DB storage .. the field is made as "DATE" so only accepts yyyy-mm-dd ... if you change your datepicker display to e.g. dd-mm-yyy it doesn't store.. so u either need to change its type or reformat to store and reformat again to re-display
6: I other oddity.. am using field ids in my script but have noticed that this flips back and forth between
e.g. vm_deliver_date_field_text & vm_deliver_date_field1_text
I realise this is the $id = VmHtml::ensureUniqueId($id); doing it but can't understand why....
7: to get the fields to appear in the emails and invoices they must be enabled for the address pages.. this means they appear in the visitors user management and even in e.g. the shop vendor page and admin.. :(
8: the fields in the emails etc
over ride templates\xxxx\html\com_virtuemart\invoice\mail_html_shopperaddresses.php to provide titles and translations:
e.g
//GJC add delivery field names here
$del = array('vm_deliver_date', 'vm_deliver_time', 'vm_collection_date', 'vm_collection_time', 'afval');
foreach ($this->userfields['fields'] as $field) {
if (!empty($field['value'])) {
if (in_array($field['name'], $del)) { // delivery fields
?><span class="titles"><?php echo vmText::_($field['title']) ?>: </span>
<span class="values vm2<?php echo '-' . $field['name'] ?>" ><?php echo $field['value'] ?></span>
<br class="clear" />
<?php
}else{ //continue
Translations are needed in the admin lang over rides