0

I am trying to set the credit card as pre-selected payment method and is working fine like when i load payment page the credit card payment method is shows selected, but the place order is disabled and not able to place order.

When the payment info page loads, I "Checked" the already "Checked" radio button for the credit card. As soon as I checked it, the "Place Order" button became active. Means, when the page loads, it's showing the options as already checked. But when I click on it, it 'checks it' for real. And then it works.

1
  • Please help, if any one have solution for this. Jun 17 at 10:23

1 Answer 1

0

You didn't specify how you implemented select default payment method

You can try to use following way to select default payment

app/code/Acme/StackExchange/view/frontend/requirejs-config.js

let config = {
    config: {
        mixins: {
            'Magento_Checkout/js/model/checkout-data-resolver': {
                'Acme_StackExchange/js/model/checkout-data-resolver-mixin': true
            }
        }
    }
};

app/code/Acme/StackExchange/view/frontend/web/js/model/checkout-data-resolver-mixin.js

define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_Checkout/js/checkout-data',
    'Magento_Checkout/js/model/payment-service'
], function ($, wrapper, checkoutData, paymentService) {
    'use strict';

    return function (resolver) {
        resolver.resolvePaymentMethod = wrapper.wrap(resolver.resolvePaymentMethod, function (_super) {
            let availablePaymentMethods = paymentService.getAvailablePaymentMethods(),
                selectedPaymentMethod = checkoutData.getSelectedPaymentMethod(),
                defaultPaymentMethod = 'cashondelivery';
            if (!selectedPaymentMethod) {
                availablePaymentMethods.some(function (payment) {
                    if (payment.method == defaultPaymentMethod) {
                        checkoutData.setSelectedPaymentMethod(defaultPaymentMethod);
                    }
                });
            }

            _super();
        });

        return resolver;
    };
});

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.