Author Topic: using shopper fields datepicker in the cart view  (Read 5033 times)

GJC Web Design

  • 3rd party VirtueMart Developer
  • Super Hero
  • *
  • Posts: 10689
  • Virtuemart, Joomla & php developer
    • GJC Web Design
  • VirtueMart Version: 3.8.8
using shopper fields datepicker in the cart view
« on: December 29, 2015, 21:16:45 pm »
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

1. language of date picker:
this is broken

needs in vmjsapi.php

Code: [Select]
$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)){
   $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)){
     $lang = 'en-GB';

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


Code: [Select]
$doc = JFactory::getDocument();

you can store locally the fields for refresh, address etc


Code: [Select]
jQuery(document).on( "focus",".datepicker", function() {

if( == 'vm_deliver_date_field_text'){
//console.log(' 0 ',;
jQuery( this ).datepicker({
beforeShowDay: unavailable,
firstDay: 1,
changeFirstDay: false,
minDate: +3,
changeMonth: true,
changeYear: true,
yearRange: yearRange,
altField: $(this).prev(),
defaultDate: +2,
onSelect: function(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
jQuery('#vm_deliver_time option[value="VM_DELIVER_NACHMORGEN"]').remove();
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.

Code: [Select]
$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


}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) {

Code: [Select]
$this->_redirect = false;

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:

Code: [Select]
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:


Code: [Select]
//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" />
}else{ //continue

Translations are needed in the admin lang over rides
GJC Web Design
VirtueMart and Joomla Developers - php developers
VM3 AusPost Shipping Plugin - e-go Shipping Plugin - VM3 Postcode Shipping Plugin - Radius Shipping Plugin - VM3 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
Contact for any VirtueMart or Joomla development & customisation