Commit f7fa27ea authored by Malcolm Blaney's avatar Malcolm Blaney

Add packing unavailable options to Cart module. When set, a message

about the shutdown period will be displayed and the start and end
options will be used by the datepicker when displaying available
packing days.
parent a5a11b97
Pipeline #40662938 passed with stage
in 1 minute and 14 seconds
...@@ -259,8 +259,32 @@ class Cart extends Base { ...@@ -259,8 +259,32 @@ class Cart extends Base {
$edit = '<button id="cart-edit-button"></button>' . $edit = '<button id="cart-edit-button"></button>' .
'<div id="cart-editor"></div>'; '<div id="cart-editor"></div>';
} }
$unavailable = '';
$start_unavailable = $this->Substitute('cart-start-unavailable');
$end_unavailable = $this->Substitute('cart-end-unavailable');
if ($start_unavailable !== '' && $end_unavailable !== '') {
$start_timestamp = strtotime($start_unavailable);
$end_timestamp = strtotime($end_unavailable);
if ($start_timestamp && $end_timestamp) {
$start = '<data id="cart-start-unavailable" ' .
'value="' . $start_timestamp . '">' . $start_unavailable . '</data>';
$end = '<data id="cart-end-unavailable" ' .
'value="' . $end_timestamp . '">' . $end_unavailable . '</data>';
$unavailable = '<div class="ui-state-highlight ui-corner-all">';
$unavailable .= $this->Substitute('cart-unavailable',
['/!start/', '/!end/'],
[$start, $end]);
$unavailable .= '</div>';
}
else {
$unavailable = '<div class="ui-state-highlight ui-corner-all">' .
'The start and end dates for shutdown are not valid. ' .
'Please check the format used for <b>cart-start-unavailable</b> ' .
'<b>cart-end-unavailable</b> templates.</div>';
}
}
$cart_title = $this->Substitute('cart-title'); $cart_title = $this->Substitute('cart-title');
return '<div id="cart-welcome-message">' . $welcome_message . return $unavailable . '<div id="cart-welcome-message">' . $welcome_message .
'</div><div id="cart-title">' . $cart_title . $edit . '</div>' . $content; '</div><div id="cart-title">' . $cart_title . $edit . '</div>' . $content;
} }
...@@ -475,7 +499,18 @@ class Cart extends Base { ...@@ -475,7 +499,18 @@ class Cart extends Base {
'option set in the \'cart-description-input\' template.', 'option set in the \'cart-description-input\' template.',
'cart-description-input' => 'A configurable input option ' . 'cart-description-input' => 'A configurable input option ' .
'added to \'cart-customer-details-form\' to request ' . 'added to \'cart-customer-details-form\' to request ' .
'custom details.']; 'custom details.',
'cart-start-unavailable' => 'The date packing will be ' .
'unavailable from during a shutdown period. This will ' .
'be used when calculating available dates for packing ' .
'in the checkout date picker.',
'cart-end-unavailable' => 'The date packing will be ' .
'available again after a shutdown period. This will ' .
'be used when calculating available dates for packing ' .
'in the checkout date picker.',
'cart-unavailable' => 'A message to display when dates ' .
'set for a shutdown period. Substitutes !start and ' .
'!end dates.'];
$this->AddTemplateDescription($description); $this->AddTemplateDescription($description);
$site_style = ['"","#cart-summary","margin-bottom","20px"', $site_style = ['"","#cart-summary","margin-bottom","20px"',
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
// for the JavaScript code in this page. // for the JavaScript code in this page.
if(!this.dobrado.cart){dobrado.cart={};} if(!this.dobrado.cart){dobrado.cart={};}
(function(){'use strict';var cart={};var settings=null;var editor=null;var itemIndex=0;var shippingIndex=0;var browserTarget='';var previousScroll=0;var oldName='';var showUnavailable=false;var showTab='All tabs';var itemChanged=false;var cartIds={};var searchTerm='';var cartTabs=[];var position=0;var itemMoved=false;$(function(){if(dobrado.localStorage){if(localStorage.cart){cart=JSON.parse(localStorage.cart);cartMiniTotal();}} (function(){'use strict';var cart={};var settings=null;var editor=null;var itemIndex=0;var shippingIndex=0;var browserTarget='';var previousScroll=0;var oldName='';var showUnavailable=false;var showTab='All tabs';var itemChanged=false;var cartIds={};var searchTerm='';var cartTabs=[];var position=0;var itemMoved=false;var startUnavailable='';var endUnavailable='';$(function(){if(dobrado.localStorage){if(localStorage.cart){cart=JSON.parse(localStorage.cart);cartMiniTotal();}}
if($('.cart').length===0){return;} if($('.cart').length===0){return;}
if($('.cart').is(':hidden')){setTimeout(init,500);} if($('.cart').is(':hidden')){setTimeout(init,500);}
else{init();}});function decimalString(value){return(value+0.0001).toFixed(2);} else{init();}});function decimalString(value){return(value+0.0001).toFixed(2);}
...@@ -33,7 +33,7 @@ function init(){function resetHash(){if(history.pushState){history.pushState(nul ...@@ -33,7 +33,7 @@ function init(){function resetHash(){if(history.pushState){history.pushState(nul
else{window.location.hash='#';}} else{window.location.hash='#';}}
function startMove(event,ui){itemMoved=true;position=ui.item.prevAll().length;} function startMove(event,ui){itemMoved=true;position=ui.item.prevAll().length;}
checkDownloads();$('.cart-item .item-add').button().click(cartAdd);$('.cart-item .item-quantity').val('0');$('.cart-item .item-quantity').spinner({min:0,spin:cartQuantity,change:cartQuantity});$('#cart-checkout').button({disabled:true}).click(checkout);$('#anchor-cart-checkout-link').click(checkout);$('#cart-tabs').tabs();$('#cart-confirm-button').button().click(confirmPurchase);$('#cart-continue-button').button().click(function(){$('#cart-checkout-dialog').dialog('close');});$('#customer-detail-method').change(toggleCustomInput);if($('#customer-detail-method').val()==='pickup'){$('#customer-detail-description').parent().show();} checkDownloads();$('.cart-item .item-add').button().click(cartAdd);$('.cart-item .item-quantity').val('0');$('.cart-item .item-quantity').spinner({min:0,spin:cartQuantity,change:cartQuantity});$('#cart-checkout').button({disabled:true}).click(checkout);$('#anchor-cart-checkout-link').click(checkout);$('#cart-tabs').tabs();$('#cart-confirm-button').button().click(confirmPurchase);$('#cart-continue-button').button().click(function(){$('#cart-checkout-dialog').dialog('close');});$('#customer-detail-method').change(toggleCustomInput);if($('#customer-detail-method').val()==='pickup'){$('#customer-detail-description').parent().show();}
$('#customer-detail-submit').button().click(customerDetail);$('.cart-item .item-name > a').click(cartItem);$('.cart-item a .item-image').click(cartItem);$(window).scroll(fixMiniTotal);fixMiniTotal();$('.cart').show();if($('.cart-payment-message').html()!==''){$('.cart-payment-message button').button().click(paymentDone);$('.cart-payment-message').dialog({show:true,modal:true,width:450,height:200,position:{my:'top',at:'top+50',of:window},title:'Payment',close:paymentDone,create:dobrado.fixedDialog});} $('#customer-detail-submit').button().click(customerDetail);$('.cart-item .item-name > a').click(cartItem);$('.cart-item a .item-image').click(cartItem);startUnavailable=$('#cart-start-unavailable').val();endUnavailable=$('#cart-end-unavailable').val();$(window).scroll(fixMiniTotal);fixMiniTotal();$('.cart').show();if($('.cart-payment-message').html()!==''){$('.cart-payment-message button').button().click(paymentDone);$('.cart-payment-message').dialog({show:true,modal:true,width:450,height:200,position:{my:'top',at:'top+50',of:window},title:'Payment',close:paymentDone,create:dobrado.fixedDialog});}
$('#cart-checkout-dialog').dialog({show:true,autoOpen:false,modal:true,width:550,height:550,position:{my:'top',at:'top+50',of:window},title:'Checkout',create:dobrado.fixedDialog});$('#cart-editor').dialog({show:true,autoOpen:false,close:close,width:760,height:500,position:{my:'top',at:'top+50',of:window},title:'Cart Editor',create:dobrado.fixedDialog});$('#cart-item-dialog').dialog({show:true,autoOpen:false,close:resetHash,width:700,height:500,position:{my:'top',at:'top+50',of:window},title:'Cart Item',create:dobrado.fixedDialog});$('#cart-edit-button').button({icon:'ui-icon-pencil',showLabel:false}).click(cartEditor);cartTotal();$.each(cart,function(name,item){var id=item.id;if(id){var cssName=id.match(/^cart-item-id-(.+)$/);if(item.selected&&cssName&&cssName.length===2){$('#'+id+' .item-add').button({label:'Remove from cart'});$('#item-quantity-'+cssName[1]).spinner('value',item.quantity);}}});var cartNames=[];$('.cart-item').each(function(index){var name=$(this).children('.item-name').children('a').text();cartNames.push(name);var cssName=$(this).attr('id').match(/^cart-item-id-(.+)$/);if(cssName.length===2){cartIds[name]=cssName[1];}});if(window.location.hash){displayItem($(window.location.hash));} $('#cart-checkout-dialog').dialog({show:true,autoOpen:false,modal:true,width:550,height:550,position:{my:'top',at:'top+50',of:window},title:'Checkout',create:dobrado.fixedDialog});$('#cart-editor').dialog({show:true,autoOpen:false,close:close,width:760,height:500,position:{my:'top',at:'top+50',of:window},title:'Cart Editor',create:dobrado.fixedDialog});$('#cart-item-dialog').dialog({show:true,autoOpen:false,close:resetHash,width:700,height:500,position:{my:'top',at:'top+50',of:window},title:'Cart Item',create:dobrado.fixedDialog});$('#cart-edit-button').button({icon:'ui-icon-pencil',showLabel:false}).click(cartEditor);cartTotal();$.each(cart,function(name,item){var id=item.id;if(id){var cssName=id.match(/^cart-item-id-(.+)$/);if(item.selected&&cssName&&cssName.length===2){$('#'+id+' .item-add').button({label:'Remove from cart'});$('#item-quantity-'+cssName[1]).spinner('value',item.quantity);}}});var cartNames=[];$('.cart-item').each(function(index){var name=$(this).children('.item-name').children('a').text();cartNames.push(name);var cssName=$(this).attr('id').match(/^cart-item-id-(.+)$/);if(cssName.length===2){cartIds[name]=cssName[1];}});if(window.location.hash){displayItem($(window.location.hash));}
$('#cart-search').autocomplete({minLength:1,search:dobrado.fixAutoCompleteMemoryLeak,source:cartNames,select:cartDisplay});$('#cart-search').val('').keyup(cartSearch);$('#cart-clear-search').button().click(function(){$('#cart-search').val('');$('.cart-item').show();});$('#cart-tabs > ul > li').children('a').map(function(){cartTabs.push($(this).attr('href'));});if($('#cart-editor').length===1){$('#cart-tabs > div').sortable({start:startMove,update:updatePosition});}} $('#cart-search').autocomplete({minLength:1,search:dobrado.fixAutoCompleteMemoryLeak,source:cartNames,select:cartDisplay});$('#cart-search').val('').keyup(cartSearch);$('#cart-clear-search').button().click(function(){$('#cart-search').val('');$('.cart-item').show();});$('#cart-tabs > ul > li').children('a').map(function(){cartTabs.push($(this).attr('href'));});if($('#cart-editor').length===1){$('#cart-tabs > div').sortable({start:startMove,update:updatePosition});}}
function checkDownloads(){$('.cart-download-list li').each(function(i){var file=$(this).html();setTimeout(function(){location.href='/php/download.php?file='+file;},i*10000);});} function checkDownloads(){$('.cart-download-list li').each(function(i){var file=$(this).html();setTimeout(function(){location.href='/php/download.php?file='+file;},i*10000);});}
...@@ -76,9 +76,13 @@ function cartSummary(shipping,processing,completed){var itemTotal=0;var total=0; ...@@ -76,9 +76,13 @@ function cartSummary(shipping,processing,completed){var itemTotal=0;var total=0;
table+='<tr>'+emptyHeader+'<th class="item">Item Name</th>'+'<th class="quantity">Quantity</th><th class="price">Price</th></tr>';$.each(cart,function(name,item){if(item.selected&&item.price!==0){itemTotal=decimalString(item.price*item.quantity);total+=parseFloat(itemTotal);quantity+=item.quantity;table+='<tr>'+remove+'<td class="item">'+name+'</td><td class="quantity">'+item.quantity+'</td><td class="price">$'+itemTotal+'</td></tr>';}});$('.cart-total .number').html('$'+decimalString(total));if(shipping){total+=shipping;table+='<tr><td class="item">Shipping Cost</td><td></td>'+'<td class="price">$'+decimalString(shipping)+'</td></tr>';} table+='<tr>'+emptyHeader+'<th class="item">Item Name</th>'+'<th class="quantity">Quantity</th><th class="price">Price</th></tr>';$.each(cart,function(name,item){if(item.selected&&item.price!==0){itemTotal=decimalString(item.price*item.quantity);total+=parseFloat(itemTotal);quantity+=item.quantity;table+='<tr>'+remove+'<td class="item">'+name+'</td><td class="quantity">'+item.quantity+'</td><td class="price">$'+itemTotal+'</td></tr>';}});$('.cart-total .number').html('$'+decimalString(total));if(shipping){total+=shipping;table+='<tr><td class="item">Shipping Cost</td><td></td>'+'<td class="price">$'+decimalString(shipping)+'</td></tr>';}
if(processing){total+=processing;table+='<tr><td class="item">Processing Fee</td><td></td>'+'<td class="price">$'+decimalString(processing)+'</td></tr>';} if(processing){total+=processing;table+='<tr><td class="item">Processing Fee</td><td></td>'+'<td class="price">$'+decimalString(processing)+'</td></tr>';}
if(total===0){$('#cart-checkout').button('option','disabled',true);$('#cart-confirm-button').hide();$('#cart-summary').show().html('<i>Your shopping cart is empty.</i>');return;} if(total===0){$('#cart-checkout').button('option','disabled',true);$('#cart-confirm-button').hide();$('#cart-summary').show().html('<i>Your shopping cart is empty.</i>');return;}
$('#cart-checkout').button('option','disabled',false);table+='<tr>'+emptyCell+'<td class="item">Total</td>'+'<td class="quantity">'+quantity+'</td>'+'<td class="price">$'+decimalString(total)+'</td></tr></table>';var dispatch='';if(!completed){dispatch='<hr><p id="cart-dispatch-info">You can choose the day your '+'order will be packed for dispatch or pickup, otherwise it will be '+'packed by the second business day after your order is placed.</p>'+'<div class="form-spacing">'+'<label for="cart-dispatch">Pack on:</label>'+'<input id="cart-dispatch" type="text"></div>';} $('#cart-checkout').button('option','disabled',false);table+='<tr>'+emptyCell+'<td class="item">Total</td>'+'<td class="quantity">'+quantity+'</td>'+'<td class="price">$'+decimalString(total)+'</td></tr></table>';let dispatch='';if(!completed){dispatch='<hr><p id="cart-dispatch-info">You can choose the day your '+'order will be packed for dispatch or pickup, otherwise it will be '+'packed by the second business day after your order is placed.</p>'+'<div class="form-spacing">'+'<label for="cart-dispatch">Pack on:</label>'+'<input id="cart-dispatch" type="text"></div>';}
$('#cart-summary').show().html('<p>You have selected the following items:</p>'+table+dispatch);if(!completed){$('.cart-checkout-remove').button({icon:'ui-icon-closethick',showLabel:false}).click(cartRemove);$('#cart-dispatch').datepicker({dateFormat:dobrado.dateFormat,minDate:'+2d',beforeShowDay:function(date){var day=date.getDay();return[day!==6&&day!==0,''];}});var defaultDate='+2d';var today=new Date().getDay();if(today===4){defaultDate='+4d';} $('#cart-summary').show().html('<p>You have selected the following items:</p>'+table+dispatch);if(!completed){$('.cart-checkout-remove').button({icon:'ui-icon-closethick',showLabel:false}).click(cartRemove);$('#cart-dispatch').datepicker({dateFormat:dobrado.dateFormat,minDate:'+2d',beforeShowDay:function(date){if(startUnavailable&&endUnavailable){let start=startUnavailable*1000;let end=endUnavailable*1000;let time=date.getTime();if(time>=start&&time<end){return[false,''];}}
let day=date.getDay();return[day!==6&&day!==0,''];}});let defaultDate='+2d';let today=new Date().getDay();if(today===4){defaultDate='+4d';}
else if(today===5){defaultDate='+3d';} else if(today===5){defaultDate='+3d';}
if(startUnavailable&&endUnavailable){let minimum=2;if(defaultDate==='+3d'){minimum=3;}
else if(defaultDate==='+4d'){minimum=4;}
minimum*=86400;let start=(startUnavailable-minimum)*1000;let end=endUnavailable*1000;let time=new Date().getTime();if(time>=start&&time<end){defaultDate=new Date();defaultDate.setTime(end);}}
$('#cart-dispatch').datepicker('setDate',defaultDate);}} $('#cart-dispatch').datepicker('setDate',defaultDate);}}
function cartItem(){if(itemMoved){itemMoved=false;return;} function cartItem(){if(itemMoved){itemMoved=false;return;}
displayItem($(this).parents('.cart-item'));} displayItem($(this).parents('.cart-item'));}
......
...@@ -62,6 +62,9 @@ if (!this.dobrado.cart) { ...@@ -62,6 +62,9 @@ if (!this.dobrado.cart) {
var position = 0; var position = 0;
// Remember if an item has just been moved to avoid calling displayItem. // Remember if an item has just been moved to avoid calling displayItem.
var itemMoved = false; var itemMoved = false;
// Store unavailable start and end dates used by the datepicker.
var startUnavailable = '';
var endUnavailable = '';
$(function() { $(function() {
// Some pages display the cart total without the cart module on the page. // Some pages display the cart total without the cart module on the page.
...@@ -133,6 +136,8 @@ if (!this.dobrado.cart) { ...@@ -133,6 +136,8 @@ if (!this.dobrado.cart) {
$('#customer-detail-submit').button().click(customerDetail); $('#customer-detail-submit').button().click(customerDetail);
$('.cart-item .item-name > a').click(cartItem); $('.cart-item .item-name > a').click(cartItem);
$('.cart-item a .item-image').click(cartItem); $('.cart-item a .item-image').click(cartItem);
startUnavailable = $('#cart-start-unavailable').val();
endUnavailable = $('#cart-end-unavailable').val();
$(window).scroll(fixMiniTotal); $(window).scroll(fixMiniTotal);
// Also call fixMiniTotal in case the window is already scrolled. // Also call fixMiniTotal in case the window is already scrolled.
fixMiniTotal(); fixMiniTotal();
...@@ -525,7 +530,7 @@ if (!this.dobrado.cart) { ...@@ -525,7 +530,7 @@ if (!this.dobrado.cart) {
table += '<tr>' + emptyCell + '<td class="item">Total</td>' + table += '<tr>' + emptyCell + '<td class="item">Total</td>' +
'<td class="quantity">' + quantity + '</td>' + '<td class="quantity">' + quantity + '</td>' +
'<td class="price">$' + decimalString(total) + '</td></tr></table>'; '<td class="price">$' + decimalString(total) + '</td></tr></table>';
var dispatch = ''; let dispatch = '';
if (!completed) { if (!completed) {
dispatch = '<hr><p id="cart-dispatch-info">You can choose the day your ' + dispatch = '<hr><p id="cart-dispatch-info">You can choose the day your ' +
'order will be packed for dispatch or pickup, otherwise it will be ' + 'order will be packed for dispatch or pickup, otherwise it will be ' +
...@@ -548,19 +553,49 @@ if (!this.dobrado.cart) { ...@@ -548,19 +553,49 @@ if (!this.dobrado.cart) {
dateFormat: dobrado.dateFormat, dateFormat: dobrado.dateFormat,
minDate: '+2d', minDate: '+2d',
beforeShowDay: function(date) { beforeShowDay: function(date) {
var day = date.getDay(); if (startUnavailable && endUnavailable) {
let start = startUnavailable * 1000;
let end = endUnavailable * 1000;
let time = date.getTime();
// For dates outside shutdown period, fall through to week day
// check below.
if (time >= start && time < end) {
return [false, ''];
}
}
let day = date.getDay();
return [day !== 6 && day !== 0, '']; return [day !== 6 && day !== 0, ''];
} }
}); });
var defaultDate = '+2d'; let defaultDate = '+2d';
// If the current day is Thursday or Friday set the default to Monday. // If the current day is Thursday or Friday set the default to Monday.
var today = new Date().getDay(); let today = new Date().getDay();
if (today === 4) { if (today === 4) {
defaultDate = '+4d'; defaultDate = '+4d';
} }
else if (today === 5) { else if (today === 5) {
defaultDate = '+3d'; defaultDate = '+3d';
} }
if (startUnavailable && endUnavailable) {
// Also set the start time back to allow for the defaultDate minimum
// that was just calculated.
let minimum = 2;
if (defaultDate === '+3d') {
minimum = 3;
}
else if (defaultDate === '+4d') {
minimum = 4;
}
minimum *= 86400;
let start = (startUnavailable - minimum) * 1000;
let end = endUnavailable * 1000;
let time = new Date().getTime();
if (time >= start && time < end) {
// datepicker.setDate can take Date object or string as a parameter.
defaultDate = new Date();
defaultDate.setTime(end);
}
}
$('#cart-dispatch').datepicker('setDate', defaultDate); $('#cart-dispatch').datepicker('setDate', defaultDate);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment