Page 1 of 1

Shop: Alert box when no option is selected

Posted: Sat 4. Apr 2015, 14:14
by update
Wenn ich im Shop einen Artikel mit Optionen habe und einfach auf "in den Warenkorb" klicke, ohne eine Option ausgewählt zu haben, dann wird der Artikel ohne weitere Ansage nicht in den Korb gelegt.
Da wäre es natürlich schön, einen Hinweis zu bekommen, dass noch die Auswahl fehlt...
Wie könnte man das erreichen? Jemand ne Idee?

Re: Shop: Alert box when no option is selected

Posted: Sun 5. Apr 2015, 10:37
by Oliver Georgi
per JavaScript abfangen, benötigt sinnvollerweise aktuellen Commit (https://github.com/slackero/phpwcms/commits/dev-1.x)

Code: Select all

$(function() {
    $('form.product-cart-option').submit(function(event) {
        event.preventDefault();
        var $this = $(this);
        var opt1 = $('select.product-option-1', $this);
        var opt2 = $('select.product-option-2', $this);
        if(opt1.length && opt2.length) {
            var opt1_value = opt1.val();
            var opt2_value = opt2.val();
            if(!opt1_value || opt1_value == '0' || !opt2_value || opt2_value == '0') {
                alert('Select product options');
                return false;
            }
        } else if(opt1.length) {
            var opt1_value = opt1.val();
            if(!opt1_value || opt1_value == '0') {
                alert('Select product option 1');
                return false;
            }
        }  else if(opt2.length) {
           var opt2_value = opt2.val();
            if(!opt2_value || opt2_value == '0') {
                alert('Select product option 2');
                return false;
            }
        }

        $this.submit();
    });
});

Re: Shop: Alert box when no option is selected

Posted: Tue 7. Apr 2015, 20:56
by update
hab's leider nicht hinbekommen. Wo genau gehört das JS denn hin?

Re: Shop: Alert box when no option is selected

Posted: Wed 8. Apr 2015, 06:48
by Oliver Georgi
egal wo, gebraucht in Produktliste/-detail.