How to: Call parent function from mixin in Magento 2

How to: Call parent function from mixin in Magento 2

Mixin declaration.

File: vendor/magento/module-checkout-agreements/view/frontend/requirejs-config.js

* Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
/*jshint browser:true jquery:true*/
/*global alert*/
var config = {
    config: {
        mixins: {
            'Magento_Checkout/js/action/place-order': {
                'Magento_CheckoutAgreements/js/model/place-order-mixin': true
            },
            'Magento_Checkout/js/action/set-payment-information': {
                'Magento_CheckoutAgreements/js/model/set-payment-information-mixin': true
            }
        }
    }
};

Call parent function from mixin.

File: vendor/magento/module-checkout-agreements/view/frontend/web/js/model/set-payment-information-mixin.js

/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
/*jshint browser:true jquery:true*/
/*global alert*/
define([
    'jquery',
    'mage/utils/wrapper',
    'Magento_CheckoutAgreements/js/model/agreements-assigner'
], function ($, wrapper, agreementsAssigner) {
    'use strict';

    return function (placeOrderAction) {

        /** Override place-order-mixin for set-payment-information action as they differs only by method signature */
        return wrapper.wrap(placeOrderAction, function (originalAction, messageContainer, paymentData) {
            agreementsAssigner(paymentData);

            return originalAction(messageContainer, paymentData);
        });
    };
});

Software engineer and consultant

Leave a Reply

Your email address will not be published. Required fields are marked *

*