2

I tried to create my own custom payment module in Magento2.1.1 CE, and there is one thing I just can't figure out.

In many of the out-of-box modules, there is a property "this.item", for example vendor/magento/module-offline-payments/view/frontend/web/js/view/payment/method-renderer/banktransfer-method.js : line 22, which were often used for getTitle() or getCode(), and the most importantly for selectPaymentMethod().

However, "this.item" in my method renderer is always undefined, and I just can't find where & what I should do to assign it the desired value.

My js code is attached below:

define(
[
    'uiComponent',
    'Magento_Checkout/js/model/payment/renderer-list'
],
function (Component,rendererList) {
    'use strict';
    rendererList.push(
            {
                type: 'pay2go',
                component: 'Logic_Pay2go/js/view/payment/method-renderer/pay2go-renderer'
    });
    return Component.extend({});
});

And the method renderer:

define(
[
    'jquery',
    'Magento_Checkout/js/view/payment/default'
],
function ($, Component, quote, additionalValidators) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'Logic_Pay2go/payment/pay2go'
        },
        redirectAfterPlaceOrder: false,

        afterPlaceOrder: function () {
            console.log(this.item); // Undefined.
            $.mage.redirect(window.checkoutConfig.payment.pay2go.redirectUrl);
        }
    });
});

The other behaviors were inherited from Magento_Checkout/js/view/payment/default. Can any one please enlight me? Thanks.

  • Please check my answer and let me know it works or not. – Ashish Jagnani Nov 3 '16 at 13:30
0

You have to initialize this._super()

Like :

define(
[
    'jquery',
    'Magento_Checkout/js/view/payment/default'
],
function ($, Component, quote, additionalValidators) {
    'use strict';

    return Component.extend({
    defaults: {
        template: 'Logic_Pay2go/payment/pay2go'
    },
    initialize: function () {
            var self = this;
            this._super();

    },
    redirectAfterPlaceOrder: false,

    afterPlaceOrder: function () {
        console.log(this.item); // Undefined.
        $.mage.redirect(window.checkoutConfig.payment.pay2go.redirectUrl);
    }
    });
});
  • Hi Ashish, it turns out that I wasn't writing <module root>/etc/config.xml correctly, in which "this.item" is being configured. Calling _super() here seems to make no difference, and many of the core payment modules didn't do so either. But still, thanks for providing your idea. – Tienyi Chi Nov 4 '16 at 3:20

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.