Welcome to mirror list, hosted at ThFree Co, Russian Federation.

main.js « js « static - github.com/kishaningithub/hugo-shopping-product-catalogue-simple.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e2feeafe970f9b2f09b31171d6d9074671e5a659 (plain)
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
$(function() {
    initializeLazyLoadOfImages();
    $("select").change(function() {
        selectPriceBasedOnVariant();
    })
    if (!_(productVariants).isEmpty()) {
        selectPriceBasedOnVariant();
    }
})

function initializeLazyLoadOfImages() {
    var bLazy = new Blazy();
}

function getSelectedVariant(productVariants, selectedProductOptions) {
    var sortedSelectedProductOptions = _.sortBy(selectedProductOptions)
    return _(productVariants).filter(function(productVariant) {
        var sortedOptionCombination=_.sortBy(productVariant.optionCombination)
        return _(sortedOptionCombination).isEqual(sortedSelectedProductOptions)
    }).first()
}

function selectPriceBasedOnVariant() {
    var selectedProductOptions = $.map($("select:visible"), function(n, i) {
        return $(n).val();
    });
    var selectedVariant = getSelectedVariant(productVariants, selectedProductOptions);
    if (selectedVariant) {
        $(".product-actual-price").text(selectedVariant.actualPrice);
        $(".product-compare-price").text(selectedVariant.comparePrice);
        $(".product-not-in-stock").toggle(!selectedVariant.inStock);
    } else {
        $(".product-not-in-stock").toggle(true);     
    }
}