Snippets
Revised by
Mike Martel
f206416
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | <!-- Kee Subscriptions pricing -->
[%extra_options id:'[@SKU@]'%]
[%PARAM *select_option%]
[%if 'Auto-delivery Auto-Delivery Auto Delivery Auto delivery' like [@name@]%]
<div class="auto-delivery col-xs-12" style="padding: 10px 0;">
<div class="auto-delivery-wrapper panel panel-default panel-body">
<div class="row">
<div class="col-sm-4 col-xs-9">
<h3><i class="fa fa-undo fa-flip-vertical" style="padding-right:5px;"></i><strong> Auto Delivery</strong></h3>
<span class="hidden-lg hidden-md hidden-sm ad-save label label-success">Save $<span class="ad-discount"></span> every time</span>
</div>
<div class="col-xs-5 hidden-xs">
<span class="ad-save label label-success">Save $<span class="ad-discount"></span> every time</span>
</div>
<div class="col-xs-3 text-right">
<span class="as-low">As low as:<br /></span>
<span class="ad-price h1"></span>
</div>
</div>
<p class="ad-select-sect">
<label for="aproductextra[@count@]">Frequency:</label>
<select name="extra[@count@]" class="form-control ad-select" id="productextra[@count@]" rel="[@SKU@]">
[@choices@]
</select>
</p>
<div class="ad-about">
<a role="button" data-toggle="collapse" href="#ad-explain" aria-expanded="false" aria-controls="ad-explain-heading" class="collapsed">
<span class="fa-stack ">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-info fa-stack-1x fa-inverse"></i>
</span>
<span style="text-decoration: underline;">How auto delivery works.</span>
</a>
<div id="ad-explain" class="panel-collapse collapse" role="tabpanel" aria-labelledby="ad-explain-heading">
<p>Select the frequency and your items will be delivered to you as often as you prefer.</p>
<p>Auto Delivery isn't a contract, you are free to cancel anytime.</p>
</div>
</div>
</div>
</div>
<span id="keesubscriptions-data"
data-rrp="[%trim%][%if [@retail@]%][@retail@][%else%][@store_price@][%/if%][%/trim%]"
data-storeprice="[%trim%][@store_price@][%/trim%]"
data-productprice="[%trim%][%if [@inpromo@]%][@promo_price@][%else%][@store_price@][%/if%][%/trim%]"
/>
[%/if%]
[%END PARAM%]
[%PARAM *choices%]
<option type="text" class="form-control" value="[@option_id@]" data-price="[@price@]">
[%nohtml%][@text@][%end nohtml%]
</option>
[%END PARAM%]
[%END extra_options%]
<script type="text/javascript" language="javascript">
(function(){
var settings = {
autoSelect: false
};
// Don't initialize twice
if (typeof window.keesubscriptions_reload !== 'undefined'){
return;
}
// Don't initialise if we're not needed
if ( !document.querySelector('#keesubscriptions-data') ) {
return;
}
var selectedIndex = false;
function _on_change_option() {
var adSelect = document.querySelector('.ad-select');
// Store the selectedIndex
selectedIndex = adSelect.selectedIndex;
var dataEl = document.getElementById('keesubscriptions-data');
var adDiscount = document.querySelectorAll(".ad-discount");
// Set the savings to the currently selected item
for (i = 0; i < adSelect.options.length; i++) {
if(i > 0 && i === Number(adSelect.options[adSelect.selectedIndex].value)){
adDiscount.forEach((el)=>{
el.innerHTML = adSelect.options[adSelect.selectedIndex].getAttribute('data-price').replace('-', '');
});
}
}
}
function _init_template() {
var dataEl = document.getElementById('keesubscriptions-data');
if (!dataEl || dataEl.getAttribute('data-init')) {
return;
}
dataEl.setAttribute('data-init', true);
//In Neto product dashboard - Default option must be "don't select auto delivery"(wording can be different) and autoSavings must have negative numbers
var rrp = parseFloat(dataEl.getAttribute('data-rrp'));
var storePrice = parseFloat(dataEl.getAttribute('data-storeprice'));
var currentPrice = parseFloat(dataEl.getAttribute('data-productprice'));
var adSelect = document.querySelector('.ad-select');
var choices = Array.prototype.map.call(adSelect.options, (function (node) {
return parseFloat(node.getAttribute('data-price') * -1)||0;
}));
var maxDiscount = Math.max.apply(Math, choices);
var adPrice = (currentPrice - maxDiscount).toFixed(2);
var rrpSave = Math.round(((1 - storePrice/rrp)) * 100);
// Set the prices in the box
var adPriceEl = document.querySelector(".ad-price");
if ( adPriceEl ) {
adPriceEl.innerHTML = '$'+adPrice;
}
// Set the discounts in the select dropdown
var foundMax = false;
for (i = 0; i < choices.length; i++) {
if(i > 0 && choices[i] > 0){
var discountPercent = Number((choices[i]/currentPrice * 100).toFixed(2));
adSelect.options[i].innerHTML += ' (save ' + discountPercent + '%)';
}
if (selectedIndex !== false && selectedIndex == i) {
adSelect.options[i].selected = true;
}
// Select the option with the largest discount by default
if(settings.autoSelect && maxDiscount> 0 && choices[i] === maxDiscount && !foundMax){
if ( selectedIndex === false ) { // Only if we don't have a cached selection
adSelect.options[i].selected = true;
}
foundMax = true;
}
}
// Hide savings if there are no savings
var adSave = document.querySelectorAll(".ad-save");
if(maxDiscount === 0){
for (i = 0; i < adSave.length; i++) {
adSave[i].style.display = 'none';
}
// Select the first option if we have no cached value
if ( settings.autoSelect && selectedIndex === false ) {
adSelect.options[1].selected = true;
}
}
// Show the largest discount where applicable
var adDiscount = document.querySelectorAll(".ad-discount");
for (i = 0; i < adDiscount.length; i++) {
adDiscount[i].innerHTML = maxDiscount;
}
// Init listeners
// Update the discount with the currently selected option
adSelect.addEventListener('change', _on_change_option.bind(this));
}
window.keesubscriptions_reload = _init_template;
_init_template();
document.addEventListener('click', function (event) {
if (!event.target.matches('.addtocart')) {
return;
}
var autodeliveryMsg = document.querySelector('.auto-delivery-msg');
if (autodeliveryMsg === null ) {
autodeliveryMsg = document.createElement('div');
autodeliveryMsg.classList.add('npopup-body', 'auto-delivery-msg');
var npopupDiv = document.querySelector('.npopup');
npopupDiv.appendChild(autodeliveryMsg);
}
var adSelect = document.querySelector('.ad-select');
if(adSelect.options[adSelect.selectedIndex].value !== "0" && autodeliveryMsg.innerHTML === ''){
autodeliveryMsg.innerHTML = 'Please note: you have selected an auto delivery subscription for this item, to review please <a href="/_mycart">click here</a>.';
}
if(adSelect.options[adSelect.selectedIndex].value === "0"){
autodeliveryMsg.innerHTML = '';
}
}, false);
})();
</script>
<!-- END of Kee Subscriptions -->
|
You can clone a snippet to your computer for local editing. Learn more.