1
getCartItems: function () {
                var items = this.getCartParam('items') || [];
                _.each(items, function (item, key) {
                    console.log(item.product_id);
                 // i have 1,2,3 product ids and need to add a check with minicart product ids and if 
                   exists then show custom popup.
                }, this);
                items = items.slice(parseInt(-this.maxItemsToDisplay, 10));
                return items;
            }

Anyone have any idea for this?

Thanks

1

You can use contains function of underscore js to check in array items. And after use Magento_Ui/js/modal/modal to show popup based on condition.

var myItems = ['1', '2', '3', '5'];
_.each(items, function (item, key) {
    if(_.contains(myItems, item.product_id)) {
       // productId available in myItems array
    }
}, this);

Here is the sample code with open modal:

define([
    'uiComponent',
    'jquery',
    'underscore',
    'Magento_Ui/js/modal/modal'
], function (Component, $, _, modal) {
    'use strict';

    ...
    ...

    getCartItems: function () {
        var items = this.getCartParam('items') || [];

        var myItems = ['1', '2', '3', '5'];
        _.each(items, function (item, key) {
            if(_.contains(myItems, item.product_id)) {
                $('body').append('<div id="modal">This is Model Content</div>');
                var options = {
                    type: 'popup',
                    responsive: true,
                    title: 'Main title',
                    buttons: [{
                        text: $.mage.__('Ok'),
                        class: '',
                        click: function () {
                            //After click code
                        }
                    }]
                };

                var popup = modal(options, $('#modal'));
                $('#modal').modal('openModal');
            }
        }, this);

        items = items.slice(parseInt(-this.maxItemsToDisplay, 10));

        return items;
    },

    ...
    ...
}

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.