1

My template is located in src/app/design/frontend/MySite/default/Magento_Checkout/templates/cart/item/default.phtml

There is a select and in this select I'm adding an event.

<select id="cart-<?= /* @escapeNotVerified */ $_item->getId() ?>-qty"
        name="cart[<?= /* @escapeNotVerified */ $_item->getId() ?>][qty]"
        data-cart-item-id="<?= $block->escapeHtml($_item->getSku()) ?>"
        title="<?= $block->escapeHtml(__('Quantity')) ?>"
        class="qty"
        data-role="cart-item-qty"
        data-bind="event:{ change: qtyChanged}">

Problem is when I load the page checkout/cart/ where the select id, I have this js error :

VM25008:3391 Uncaught ReferenceError: Unable to process binding "event: function(){return { change:qtyChanged} }" Message: qtyChanged is not defined at event (eval at createBindingsStringEvaluator (eval at req.exec (require.js:2063)), :3:74) at init (eval at req.exec (require.js:2063), :4241:30) at eval (eval at req.exec (require.js:2063), :3368:46) at Object.ignore (eval at req.exec (require.js:2063), :1480:33) at eval (eval at req.exec (require.js:2063), :3367:48) at Object.arrayForEach (eval at req.exec (require.js:2063), :159:17) at applyBindingsToNodeInternal (eval at req.exec (require.js:2063), :3353:22) at applyBindingsToNodeAndDescendantsInternal (eval at req.exec (require.js:2063), :3233:37) at applyBindingsToDescendantsInternal (eval at req.exec (require.js:2063), :3215:13) at applyBindingsToNodeAndDescendantsInternal (eval at req.exec (require.js:2063), :3242:13)

And here is the place I write the new file

src/app/code/Cam/Checkout/view/frontend/web/js/view/cart/item/default.js

And that's the content

define([
    'Cam_Checkout/cart/item/default'
], function (Form) {
    'use strict';

    return Form.extend({
        defaults: {
            template: 'Cam_Checkout/cart/item/default'
        },

        qtyChanged : function () {
            console.log("Qty changed called");
        }
    });
});

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.