I have a configurable product with two option and i want to add an empty cart button on that page to empty the items:
i have copied the button from cart page and embed it but its not worked. please suggest a way to add a button.
<button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Empty Cart'); ?>" class="button2 btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Empty Cart'); ?></span></span></button>
You will need to create a new controller and then add the action of the controller to the button you just created.
Then create a model to empty the $quote
which is the current items. Thats the basic theory.
Inchoo created something similar to what you want check it out here .
If you look at the updatePostAction
function of Mage_Checkout_CartController
, you should indeed be able to do that the way you want it. But right now your button is not linked to a form, so it does nothing.
But you will also need a valid form key for that to work.
Extract of Mage_Checkout_CartController
:
public function updatePostAction()
{
if (!$this->_validateFormKey()) {
$this->_redirect('*/*/');
return;
}
$updateAction = (string)$this->getRequest()->getParam('update_cart_action');
switch ($updateAction) {
case 'empty_cart':
$this->_emptyShoppingCart();
break;
case 'update_qty':
$this->_updateShoppingCart();
break;
default:
$this->_updateShoppingCart();
}
$this->_goBack();
}
So this should be something working :
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="post">
<?php echo $this->getBlockHtml('formkey'); ?>
<button type="submit" name="update_cart_action" value="empty_cart" title="<?php echo $this->__('Empty Cart'); ?>" class="button2 btn-empty" id="empty_cart_button"><span><span><?php echo $this->__('Empty Cart'); ?></span></span></button>
</form>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.