1

I have a module to download a file on S3 by magento 2. When I click button download, it will down a file csv, now I want if this file does not exist so display a popup message on screen by 1 notification sentence and 1 button OK. How can I do that? Help me!!! Tks !!!

1

You need to check csv file is exist or not into if condition And for call Popup use this code init.

 if (file exist){

        //ADD your Doownload Logic

 } else {

?>
 <div id='popup-modal'>
        <h1> Hi I'm here.... </h1>
    </div>
    <script>
        require(
            [
                'jquery',
                'Magento_Ui/js/modal/modal'
            ],
            function(
                $,
                modal
            ) {
                var options = {
                    type: 'popup',
                    responsive: true,
                    innerScroll: true,
                    title: 'popup modal title',
                    buttons: [{
                        text: $.mage.__('Continue'),
                        class: '',
                        click: function () {
                            this.closeModal();
                        }
                    }]
                };
    
                var popup = modal(options, $('#popup-modal'));
    
                $('#popup-modal').modal('openModal');
            }
        );
    </script>
<?php
 
 }

?>

    
7
  • sorry I'm newbie so I can't do it yet, my work is: when I go on module, nothing to happen, when I select option and click button download that thing to do: if file exist, file is downloaded, if doesn't exist show alert popup.. – namikaze Jul 8 '20 at 6:43
  • :( I can't. I follow like you, but when I click button download, the popup display about 1s and then back to this screen – namikaze Jul 8 '20 at 9:23
  • how can that show popup content and button OK? :( your recommend doesn't work for me – namikaze Jul 8 '20 at 9:53
  • Sorry, I replaced but it isn't work – namikaze Jul 8 '20 at 9:58
  • and an other question @Msquare :D I'm a newbie so tell me how can I "accpet" as green tik mark for you? – namikaze Jul 8 '20 at 10:01
0

You need to call showcartPopup(msg) this function to show a popup with a message when file not found. You just need to pass a message with a function. you can update class and function name according to you. I used this code for cart product success/failed message show

<div id="popup-modal" style="display:none;">
    <h2 id="cartmessagecustome" ></h2>
</div>

<script>
    require(
        [
            'jquery',
            'Magento_Ui/js/modal/modal'
        ],
        function(
            $,
            modal
        ) {
            var options = {
                type: 'popup',
                responsive: true,
                innerScroll: true,
                buttons: [{
                    text: $.mage.__('Continue'),
                    class: '',
                    click: function () {
                        this.closeModal();
                    }
                }]
            };

            var popup = modal(options, $('#popup-modal'));
            $("#popup-modal").on('click',function(){
                $("#popup-modal").modal("openModal");
            });

        }
    );
    function showcartPopup(msg){
        require([ 'jquery', 'jquery/ui'], function($){
            $('#cartmessagecustome').empty();
            $('#cartmessagecustome').append(msg);
            $('#popup-modal').click();
         });
    }

</script>
11
  • sorry I'm newbie so I can't do it yet, my work is: when I go on module, nothing to happen, when I select option and click button download that thing to do: if file exist, file is downloaded, if doesn't exist show alert popup.. – namikaze Jul 8 '20 at 6:43
  • can you please share your code which you added for popup – Pushpendra Singh Jul 8 '20 at 7:14
  • codepad.org/7mW0evmX (this is app/code/vender/module/view/adminhtml/templates/download.phtml) codepad.org/KQZrsXTQ (this is app/code/vender/module/Controller/Adminhtml/Download/index.php) – namikaze Jul 8 '20 at 7:38
  • Where did you mention popup code – Pushpendra Singh Jul 8 '20 at 10:40
  • I not sure I mention it where. I think I will mention in index.php\function download(): if (have file) -> download, else -> popup – namikaze Jul 9 '20 at 2:02

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.