0

I'm trying to override Magento\Checkout\view\frontend\web\js\action\place-order.js which contain the code below

define([
    'jquery',
    'Magento_Checkout/js/model/quote',
    'Magento_Checkout/js/model/url-builder',
    'Magento_Customer/js/model/customer',
    'Magento_Checkout/js/model/place-order'
], function ($, quote, urlBuilder, customer, placeOrderService) {  
    'use strict';
    console.log($(this).parent(".payment-method-content"));
    return function (paymentData, messageContainer) {
        var serviceUrl, payload, subscribe;

        payload = {
            cartId: quote.getQuoteId(),,
            billingAddress: quote.billingAddress(),
            paymentMethod: paymentData,
            isSubscribe: subscribe
        };

        if (customer.isLoggedIn()) {
            alert("Inside the custom module");
            serviceUrl = urlBuilder.createUrl('/carts/mine/payment-information', {});
        } else {
            alert("Inside the custom module");
            serviceUrl = urlBuilder.createUrl('/guest-carts/:quoteId/payment-information', {
                quoteId: quote.getQuoteId()
            });
            payload.email = quote.guestEmail;
        }

        return placeOrderService(serviceUrl, payload, messageContainer);
};
});

So basically I just want to target the value of an element within the div container .payment-method-content. So I'm assuming that when I click the submit button I will be able to get it's parents which is the div.payment-method-content. Within this parent div it contains an element of .chk_subscription now I want to get the value of this checkbox. But whenever I do the

var source = $(this);

This returns null so I think this is not defined? But in jquery whenever we use $(this) we are referring to the source of the action which is the button in this situation. But why is it it's returning null? How can I get the value of this element?

To have a better idea of the html element below is the possible structure

enter image description here

As you can see the button which is located below the screenshot is the one that trigger the placeorder function. Now I want to target it's parent which is the .payment-method-content and then target the child of that parent which is the .checkout-input-subscription but when retrieving the source element it returns null. How do I achieve this? Via Jquery or Knockout. But I don't know knockout so it's much appreciated if it's achievable via JQuery

Your Answer

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

Browse other questions tagged or ask your own question.