Magento 2 – Mini Cart Delete Confirmation Popup

magento2.1.0mini-cart

How to add the popup(when you click on delete item) to a custom button, Screenshot Belowcart Pop up

    <?php
$orderStatus = $_order->getStatusLabel();

if ($orderStatus == 'Pending' || $orderStatus == 'Processing')
    {
?>
   <a href="<?php /* @escapeNotVerified */
    echo $block->getBaseUrl() . 'ordercancel/index/ordercancel?orderId=' .       $_order->getId(); ?>" class="action view">
    <span><?php /* @escapeNotVerified */
    echo __('Cancel Order') ?></span>
                                </a>
                            <?php
    } ?>

Want to add this popup when customer click order cancel

Best Answer

You can try with below code,

require(['jquery','Magento_Ui/js/modal/confirm'], function ($, confirm) {
    $('.view').on("click",function(event){
        event.stopPropagation();
        getId = $(this).attr('data-order');
        confirm({
            content: 'Are you sure you would like to remove this item from the shopping cart?',
            actions: {
                confirm: function () {
                    _removeItem(getId);
                },
                always: function (event) {
                    event.stopImmediatePropagation();
                }
            }
        });
    });

    function _removeItem(orderId) {
            var itemId = orderId;
            //ajax call here..
    },
 }

data-order with order id is added in anchor tag.

<a href="<?php /* @escapeNotVerified */
echo $block->getBaseUrl() . 'ordercancel/index/ordercancel?orderId=' .       $_order->getId(); ?>" class="action view" data-order="<?php echo $_order->getId(); ?>">
<span><?php /* @escapeNotVerified */
echo __('Cancel Order') ?></span>
                            </a>
Related Topic