1

In list.phtml (product listing) I am showing requistition lsit for every product using type="text/x-magento-init" in loop as:

<script type="text/x-magento-init">
{
    "*": {
        "Magento_Ui/js/core/app": {
            "components": {
                "requisition_<?= $block->escapeJs($block->getComponentId()) . ' - ' . $_product->getId(); ?>": {
                    "component": "Magento_RequisitionList/js/requisition/action/product/view/add",
                    "editModuleName": "requisition_<?= $block->escapeJs($block->getComponentId()) . ' - ' . $_product->getId(); ?>.edit",
                    "title": "<?= __('Add to Requisition List') ?>",
                    "action": "<?= $block->getUrl('requisition_list/item/add') ?>",
                    "sku": "<?= $block->escapeJs($_product->getSku()) ?>",
                    "productFormSelector": "#product_addtocart_form<?= $_product->getId() ?>"
                }
            }
        }
    }
}
</script>

Below this phtml at the end I created a simple javascript

<script type="text/javascript">
        require([
            'jquery',
            'lazypage'
        ], function($, scrollPagination) {
            $(document).ready(function(){
                $(window).scroll(function() {
                    var totItem = parseInt($('#totalitem').val());
                    var proLoaded = parseInt($('#productdata li').last().attr("rel"));
                    console.log('toitem'+totItem);
                    console.log('proload'+proLoaded);
                    if ((totItem > proLoaded) && (totItem != proLoaded)){
                        console.log('in ifffffff');
                    } else {
                        console.log('in elseeee');
                    }
                });
            });
        });
</script>

The issue is that when I keep both script type="text/x-magento-init" and type="text/javascript" then always getting console.log('in elseeee').

And when I am removing script type="text/x-magento-init" then everything works fine, I am getting console.log('in ifffffff');

Whats wrong I am doing ???

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.