2

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

  • Remove this class validation-passed in your Add to cart button – Magento 2 Mar 28 '17 at 6:44
  • @Kothari i am not getting, can you tell what line of code i need to remove ? – Baby in Magento Mar 28 '17 at 6:55
  • I don't know line number open you site inspect element your Add to cart there you add one more class validation-passed so you need to remove that – Magento 2 Mar 28 '17 at 6:57
  • @Kothari i found that class in file app/design/frontend/base/default/template/catalog/product/view/options.phtml i renamed the class to validation-passed1 still its not working for me...... – Baby in Magento Mar 28 '17 at 7:04
  • On click Add to cart this class is adding so you have to find how this class added and then remove – Magento 2 Mar 28 '17 at 7:08
1
+50

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.