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 !!!
2 Answers
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>
-
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..– namikazeCommented Jul 8, 2020 at 6:43
-
can you please share your code which you added for popup Commented Jul 8, 2020 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)– namikazeCommented Jul 8, 2020 at 7:38
-
-
I not sure I mention it where. I think I will mention in index.php\function download(): if (have file) -> download, else -> popup– namikazeCommented Jul 9, 2020 at 2:02
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
}
?>
-
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..– namikazeCommented Jul 8, 2020 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– namikazeCommented Jul 8, 2020 at 9:23
-
how can that show popup content and button OK? :( your recommend doesn't work for me– namikazeCommented Jul 8, 2020 at 9:53
-
-
and an other question @Msquare :D I'm a newbie so tell me how can I "accpet" as green tik mark for you?– namikazeCommented Jul 8, 2020 at 10:01