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

5
  • Remove this class validation-passed in your Add to cart button
    – Magento 2
    Mar 28, 2017 at 6:44
  • @Kothari i am not getting, can you tell what line of code i need to remove ? Mar 28, 2017 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, 2017 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...... Mar 28, 2017 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, 2017 at 7:08

1 Answer 1

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.

8
  • Can you please tell what code changes i need to do to get solution..... Apr 5, 2017 at 5:17
  • I have edited the answer. You can try to change like that. Apr 5, 2017 at 6:16
  • Thanks, i updated your code , but still i am facing same issue in link Apr 5, 2017 at 6:18
  • Are you sure you update correct template? prntscr.com/esm8l1 Apr 5, 2017 at 6:39
  • I can see the script not change Apr 5, 2017 at 6:40

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.