We are displaying Products in My account section & gave an option to add product to cart once user click on Add to cart. now we want to provide an option to delete the products once we click on "Delete" button.
Edit
After using below code, once i click on "Delete" button, all products are deleting instead of one product :
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $collections = $this->getCollection(); ?>
<?php $_product = $this->getProduct(); ?>
<div id="messages_product_view">
<?php $buttonTitle = Mage::helper('core')->quoteEscape($this->__('Add to Cart')); ?>
</div>
<?php foreach ($collections as $key => $product) {
echo $product->getName().' <br>';
echo $product->getId().'<br />';
$_product = Mage::getModel('catalog/product')->load($product->getId());
?>
<?php
$itemRemoveUrl=$this->getUrl('checkout/cart/delete',array('id'=>$_product->getId(),
Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED=>$this->helper('core/url')->getEncodedUrl())
);
?>
<!-- delete -->
<form
action="<?php
Mage::register('isSecureArea', true);
$_product = Mage::getModel('catalog/product')->load($product->getId());
try
{
$product->delete();
Mage::unregister('isSecureArea');
}
catch(Exception $e)
{
echo "write";
}
?>" method="post">
<div class="add-to-cart-buttons">
<button type="submit" title="Delete" class="button btn-cart" >
<span><span>Delete</span></span>
</button>
</div>
</form>
<!-- delete code end-->
<?php
}
?>
try { $product->delete(); Mage::unregister(‘isSecureArea’); } catch(Exception $e) { echo “Product #”.$product->getId().” could not be remvoved: “.$e->getMessage(); }
, but it didt worked for me , may be i done something wrong in placing code...... please guide me on this.....Product #195652 could not be remvoved: Cannot complete this operation from non-admin area.
seems there is no link b/w Delete button and that code, so only it didt worked, please tell me how to link to delete button....