3

I am working with Magento 2.1.0. I have enabled 'Terms and conditions' on site and added 2 conditions one for 'Terms and conditions' and other for 'Replacement Policy'. It displayed both in checkout page correctly, but validation is done only for the first check-box. Not considering the second one. If first check-box is checked. We will be able to place the order.

I have found out that it is the issue with the Magento 2. How can I fix this issue? Please help.

4

We have face the same issue(terms and conditions not validating) in our system, and change the below mentioned code. Now working properly.

File Path:

vendor/magento/module-checkout-agreements/view/frontend/web/js/model/agreement-validator.js

Change the below code:

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
/*jshint browser:true jquery:true*/
/*global alert*/
define(
    [
        'jquery',
        'mage/validation'
    ],
    function ($) {
        'use strict';
        var checkoutConfig = window.checkoutConfig,
            agreementsConfig = checkoutConfig ? checkoutConfig.checkoutAgreements : {};

        var agreementsInputPath = '.payment-method._active div.checkout-agreements input';

        return {
            /**
             * Validate checkout agreements
             *
             * @returns {boolean}
             */
            validate: function() {
                var noError = true;
                if (!agreementsConfig.isEnabled || $(agreementsInputPath).length == 0) {
                    return noError;
                }

                $('.payment-method:not(._active) div.checkout-agreements input')
                    .prop('checked', false)
                    .removeClass('mage-error')
                    .siblings('.mage-error[generated="true"]').remove();

                $(agreementsInputPath).each(function() {
                    var name = $(this).attr('name');

                    var result = $('#co-payment-form').validate({
                        errorClass: 'mage-error',
                        errorElement: 'div',
                        meta: 'validate',
                        errorPlacement: function (error, element) {
                            var errorPlacement = element;
                            if (element.is(':checkbox') || element.is(':radio')) {
                                errorPlacement = element.siblings('label').last();
                            }
                            errorPlacement.after(error);
                        }
                    }).element(agreementsInputPath + '[name="' + name + '"]');

                    if (!result) {
                        noError = false;
                    }
                });

                return noError;
            }
        }
    }
);

After changed the code you will following command:

php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento cache:flush
  • hey @Sankar_k, which magento version did you use? we face the same problem with M2.1.5 - tried your solution but doesn't work. I Created the Magento_CheckoutAgreements module in our theme and applied the mentioned edits. Any idear? – Florin P. May 19 '17 at 14:57
  • Hi @Florin P. We have used the M2.1.4 shop system. But We have checked same in M2.1.5 and M2.1.6, and found that everything working properly. Please check the below mentioned file path: (<root>/pub/static/frontend/Magento/{themes}/{language}/Magento_CheckoutAgreements/js/model/agreement-validator.js. ). In this files also updated. And clear the shop cache and browser cache. – Sankar_k May 23 '17 at 6:57
  • nope, the file is not updated, i can do it manually but its not the right way. what i dont understand is why its not generated from the new file edited in app/design/frontend/Theme/default/Magento_CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js – Florin P. May 23 '17 at 14:11
  • Before run the php bin/magento setup:static-content:deploy comment in terminal, rewrite the folder name. Example: you have same update the frontend files. Rewrite the below folder: pub/static/frontend/Magento/luma/en_US to pub/static/frontend/Magento/luma/en_US_backup – Sankar_k May 23 '17 at 14:53
  • 1
    @RaviDudhara Please use the above code – Sankar_k May 2 '19 at 7:49
2

You stumbled upon a bug in Magento 2.1.x. There's currently a bug report on Github regarding it: https://github.com/magento/magento2/issues/5632

1

Bug Reported for the same on git hub for 2.1.X.

Refer this link - https://github.com/magento/magento2/issues/5632

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.