How to Delete Particular Item from Cart Pop Up in Magento

cart

I just want to remove a single item from the Cart pop up.Here is my code to display the product image, name, Quantity, price and Remove icon in cart pop up.

<?php foreach($items as $_item): ?>
<?php $isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();?>
<?php $product = $_item->getProduct(); ?>
<?php echo "<ul> <li class='item'>"; ?>
<span class="cart-img"><a href="<?php echo $product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(50, 50); ?>" width="50" height="50" alt="<?php echo $this->stripTags($this->getImageLabel($product, 'small_image'), null, true) ?>" /></a></span>
<span class="cart-name"><?php echo $_item->getName();?></span>
<span class="cart-qty"><?php echo $_item->getQty();?></span>
<span class="cart-price"><?php echo $this->helper('checkout')->formatPrice($_item->getCalculationPrice()+$_item->getWeeeTaxAppliedAmount()+$_item->getWeeeTaxDisposition()); ?></span>
<?php $_item = $this->getItem(); 
$url=$this->getUrl('checkout/cart/delete', array('id' => $_item->getProductId())); ?>
<span class="cart_item_delete" ><a href="<?php echo $url ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a></span> 
<?php echo "</li></ul>" ?>  
<?php endforeach; ?>

When I add the product to the cart everything is going blank. When I remove the three lines of code written for removing the item from the cart pop up,everything is displayed perfectly but the remove icon is not working & the product is not getting removed.The page is refreshed and nothing happens.

This is that three lines of code snippet from above code for removing an item from cart pop up:

<?php $_item = $this->getItem();
$url=$this->getUrl('checkout/cart/delete', array('id' => $_item->getProductId())); ?>
<span class="cart_item_delete" ><a href="<?php echo $url ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a></span>

please someone tell me where I went wrong?

Best Answer

 <?php $_item = $this->getItem();
    $url=$this->getUrl('checkout/cart/delete',array('id'=>$_item->getId())); ?>
    <span class="cart_item_delete" ><a href="<?php echo $url ?>" title="<?php echo $this->__('Remove This Item') ?>" onclick="return confirm('<?php echo $this->__('Are you sure you would like to remove this item from the shopping cart?') ?>');" class="btn-remove"><?php echo $this->__('Remove This Item') ?></a></span>
Related Topic