I want to cart item remove in minicart using custom URL.

Below code in magento1 I want to magento2 code

 * Get item delete url
 * @return string
public function getDeleteUrl()
    return $this->getUrl(
            Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->helper('core/url')->getEncodedUrl()

You can find the call to this in template/checkout/cart/item/default.phtml:

<td class="a-center">
<a href="<?php echo $this->getDeleteUrl()?>" title="<?php echo $this->__('Remove item')?>" class="btn-remove btn-remove2">
<?php echo $this->__('Remove item')?></a>

How can I achieve that?


you block funciton code:

public function getDeleteUrl($item)
        // use construct method inject Magento\Checkout\Helper\Cart
        $postJson = $this->cart->getDeletePostJson($item);
        return $postJson;

you default.phtml code:

<a href="#"
   title="<?= $block->escapeHtml(__('Remove item')) ?>"
   class="action action-delete"
   data-post='<?= $this->getDeleteUrl($_item) ?>'>
        <?= /* @escapeNotVerified */ __('Remove item') ?>
| improve this answer | |

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.