-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUGFIX product availability doesn’t check product options (#380)
* BUGFIX product availability doesn’t check product options * REMOVE console.log()
- Loading branch information
Showing
4 changed files
with
106 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
;(function ($) { | ||
|
||
var trigger = 'select.product-options', | ||
formName = "#$FormName", | ||
shownPrice = '[id*="_submitPrice"]', | ||
selects = '#$FormName select', | ||
initialPrice = $(shownPrice).html().replace('$', ''); | ||
|
||
$(trigger).change(function () { | ||
refreshCartPrice(); | ||
}); | ||
|
||
var refreshCartPrice = function refreshAddToCartPrice() | ||
{ | ||
var price = $(shownPrice).html(); | ||
var newProductPrice = parseFloat(initialPrice); | ||
|
||
$(selects).each(function () { | ||
|
||
if ($(this).attr('id') == 'qty') { | ||
// todo: modify newProductPrice by Quantity? | ||
} else { | ||
var currentOption = $(this).val(); | ||
//get an array of the modifiers | ||
currentOption = currentOption.substring(currentOption.lastIndexOf('{') + 1, currentOption.lastIndexOf('}')).split('|'); | ||
|
||
//build a different array of key-value pairs, options[p,c,w] = value | ||
//more reliable than hoping price is the first array index of currentOption.. | ||
var options = []; | ||
for (i = 0; i < currentOption.length; i++) { | ||
var k = currentOption[i].substr(0, 1); | ||
var val = currentOption[i].substr(1); | ||
options[k] = val; | ||
} | ||
|
||
if (typeof options['p'] != 'undefined') { | ||
var pricemodifier = options['p'].substr(0, 1); // return +,-,: | ||
if (pricemodifier == ':') { | ||
newProductPrice = parseFloat(options['p'].substr(1)); | ||
} else { | ||
newProductPrice = newProductPrice + parseFloat(options['p']); | ||
} | ||
} | ||
} | ||
}); | ||
$(shownPrice).html('$' + newProductPrice.toFixed(2)); | ||
}; | ||
|
||
if ($(trigger).length > 0) { | ||
refreshCartPrice(); | ||
} | ||
var shownPrice = $('[id*="_submitPrice"]'), | ||
trigger = $('.product-options'), | ||
isAvailable = $('[name="action_x:submit"]').length ? true : false, | ||
unavailable = trigger.closest('form').find('[id*="_unavailableText"]'); | ||
|
||
$('option:disabled').each(function () { | ||
if ($(this).prop('disabled')) { | ||
$(this).addClass('outOfStock').append(document.createTextNode(" (out of stock)")); | ||
} | ||
}); | ||
|
||
trigger.on('change', function () { | ||
var options = [], | ||
selected = $(this).val(); | ||
|
||
if (selected.length > 0) { | ||
selected = selected.substring(selected.lastIndexOf('{') + 1, selected.lastIndexOf('}')).split('|')[0].split(':')[1]; | ||
} | ||
|
||
$(this).each(function () { | ||
var currentOption = $(this).val(); | ||
currentOption = currentOption.substring(currentOption.lastIndexOf('{') + 1, currentOption.lastIndexOf('}')).split('|'); | ||
|
||
if (currentOption.length) { | ||
$.each(currentOption, function (k, v) { | ||
if (v !== '') { | ||
console.log(v.split(':')[1]); | ||
options[v.split(':')[1]] = v.split(':')[1]; | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
if (selected in options) { | ||
shownPrice.html('$' + Number.parseFloat(options[selected]).toFixed(2)); | ||
} | ||
}); | ||
|
||
if (isAvailable === false) { | ||
shownPrice.addClass('hidden'); | ||
unavailable.removeClass('hidden'); | ||
} else { | ||
if (trigger.length > 0) { | ||
trigger.change(); | ||
} | ||
|
||
} | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters