Xabby February 2016

How to add a custom empty cart button on configurable product page:Magento

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>

Answers


Andre Ferraz February 2016

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.


b.enoit.be February 2016

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>

Post Status

Asked in February 2016
Viewed 3,308 times
Voted 6
Answered 2 times

Search




Leave an answer