eStream/Cart42

Add product to cart fails - please select option

Closed this issue · 1 comments

On this page: http://demo.cart42.com/en-US/Product/22/the-hitchhiker-dark-t-shirt seem to be only two options (size, color).

Steps to reproduce:

  1. go to productpage: http://demo.cart42.com/en-US/Product/22/the-hitchhiker-dark-t-shirt
  2. choose for every available option (as far as i can see only price and color)
  3. click add to cart button

expected result: the item is added to the cart
actual result: an overlay appears that tells me to Please select a product option. As far as i can see there are only two options.

It seems the root cause is inside

 self.addToCart = function () {
    var skus = self.skusFiltered();
    if (self.skus().length > 0 && skus.length == 0) {
        bootbox.alert('This combination is not available!');
        return;
    }
    if (skus.length > 1) {
        bootbox.alert('Please select the product options!');
        return;
    }
    .....

Whatever self.skusFiltered() may be as soos as it is greater then 1 you can not add anything to the cart.

Inside http://demo.cart42.com/Scripts/bootstrap.js?bundleVirtualPath=%7e%2fbundles%2fCommonScripts i found:

 self.skusFiltered = ko.computed(function () {
    var dummy = self.getSelectedOptions();
    var filteredSkus = [];
    for (var i = 0; i < self.skus().length; i++) {
        var passes = true;
        var sku = self.skus()[i];
        var opts = JSON.parse(sku.optionsJson());

        for (var j = 0; j < opts.length; j++) {
            var opt = opts[j];
            var category = $.grep(self.optionCategories(), function (cat) {
                return cat.id() == opt.categoryId;
            });

            if (category.length > 0) {
                category = category[0];
                var selectedOpts = $.grep(category.options(), function (so) {
                    return so.selected();
                });
                if (selectedOpts.length == 0) continue;
                var matches = $.grep(selectedOpts, function (so) {
                    return so.id() == opt.optionId;
                });
                if (matches.length > 0) continue;
            }

            passes = false;
            break;
        }

        if (passes)
            filteredSkus.push(sku);
    }
    return filteredSkus;

The sample product had duplicate SKUs entered in the admin tool. The software was unable to determine which SKU is the proper one given the selected options. The demo site sample data is fixed now. Perhaps it would be a good idea to have better validation in the admin tool so that duplicate SKUs cannot be saved.