Magento 1.9 – Remove Validation for Add to Cart

magento-1.9

user can upload image and text on product image, after that user muct click on custom button "save design" , after that only onclick "Add to cart" button will add item to cart. but we want to remove that validation for add to cart button.

What i need is Once user upload image or text and if user click on "Add to cart", it should add item to cart.

We have below code for "save design"

_getControlPanelHtml: function()
    {
        if (this.config.editorEnabled) {
            return '<div id="aitcg-control-panel">' +
                '<button id="submit-editorApply-{{rand}}" >SAVE DESIGN</button>' +
                '<button >Reset</button>' +
                '</div>';
        }
        return '';
    },


    initObservers: function()
    {
        if (this.config.editorEnabled) {
            $('submit-editorApply-' + this.config.rand).observe('click', this.submitApply.bindAsEventListener(this));
            $('submit-editorReset-' + this.config.rand).observe('click', this.submitReset.bindAsEventListener(this));
        }
    },

    submitApply: function(event)
    {
        Event.stop(event);
        this.option.apply();
    },

I tried below code , now "Add to cart" is working without clicking "save design", but after clicking "save design", than "Add to cart" is not working.

<script>

initObservers: function()
    {
        if (this.config.editorEnabled) {
            $('submit-editorApply-' + this.config.rand).observe('click', this.submitApply.bindAsEventListener(this));
            $('submit-editorReset-' + this.config.rand).observe('click', this.submitReset.bindAsEventListener(this));

            var buttonCart = $$('.btn-cart')[0];
            buttonCart.removeAttribute('onclick');
            buttonCart.observe('click', this.addToCart.bindAsEventListener(this));
            console.log(buttonCart);
        }
    },

    addToCart: function(event)
    {
        Event.stop(event);
        this.submitApply(event);

        productAddToCartForm.submit(this)
    },

phtml : https://pastebin.com/xeWKNUs4 , script : https://pastebin.com/p8UU7zQ1

enter image description here

Best Answer

You can check function submit of Add to Cart button in ...\app\design\frontend......\template\catalog\product\view.phtml

Check this script:

productAddToCartForm.submit = function(button, url) {
        if (this.validator.validate()) {
            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }
        }
    }.bind(productAddToCartForm);

Change to

productAddToCartForm.submit = function(button, url) {

            var form = this.form;
            var oldUrl = form.action;

            if (url) {
               form.action = url;
            }
            var e = null;
            try {
                this.form.submit();
            } catch (e) {
            }
            this.form.action = oldUrl;
            if (e) {
                throw e;
            }

            if (button && button != 'undefined') {
                button.disabled = true;
            }

    }.bind(productAddToCartForm);

Hope it helps.

Related Topic