1
  1. Go to cart page and click on [Edit] link. You will be now in product page.

  2. Change quantity to zero and click on [Update] button

    This should remove the product from cart. You will get again cart page with quantity unchanged.

  3. Now change in cart page quantity to zero and update it. The product will be remove from cart which is a correct behavior.

Maintenance team - Please change the script to allow zero quantities in product page then delete the product from cart.

2 Answers 2

9

This page, is not the product page, its actually a special page used to adjust a product, notice the URL for example in this its product ID 5

checkout/cart/configure/id/5/

That is a custom page, that has a special controller and action

Mage_Checkout_CartController

/**
 * Action to reconfigure cart item
 */
public function configureAction()
{
    // Extract item and product to configure
    $id = (int) $this->getRequest()->getParam('id');
    $quoteItem = null;
    $cart = $this->_getCart();
    if ($id) {
        $quoteItem = $cart->getQuote()->getItemById($id);
    }

    if (!$quoteItem) {
        $this->_getSession()->addError($this->__('Quote item is not found.'));
        $this->_redirect('checkout/cart');
        return;
    }

    try {
        $params = new Varien_Object();
        $params->setCategoryId(false);
        $params->setConfigureMode(true);
        $params->setBuyRequest($quoteItem->getBuyRequest());

        Mage::helper('catalog/product_view')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params);
    } catch (Exception $e) {
        $this->_getSession()->addError($this->__('Cannot configure product.'));
        Mage::logException($e);
        $this->_goBack();
        return;
    }
}

this Helper is the actual source of the save configuration

Mage::helper('catalog/product_view')->prepareAndRender($quoteItem->getProduct()->getId(), $this, $params);

What I think is the actual problem is that the QTY is being set to 0, or false, and is ignored as a change, when its passed through this Helper. So, its not really a bug, its more of a matter of trying to use a method to remove a product, that its not intended for. The trash can on the cart is the right use. Now, if you wanted, you could do a rewrite of the helper and manage this yourself by checking the $params and then removing it from the cart:

/**
 * Prepares product view page - inits layout and all needed stuff
 *
 * $params can have all values as $params in Mage_Catalog_Helper_Product - initProduct().
 * Plus following keys:
 *   - 'buy_request' - Varien_Object holding buyRequest to configure product
 *   - 'specify_options' - boolean, whether to show 'Specify options' message
 *   - 'configure_mode' - boolean, whether we're in Configure-mode to edit product configuration
 *
 * @param int $productId
 * @param Mage_Core_Controller_Front_Action $controller
 * @param null|Varien_Object $params
 *
 * @return Mage_Catalog_Helper_Product_View
 */
public function prepareAndRender($productId, $controller, $params = null)
{

    // Prepare data
    $productHelper = Mage::helper('catalog/product');
    if (!$params) {
        $params = new Varien_Object();
    }

    // Standard algorithm to prepare and rendern product view page
    $product = $productHelper->initProduct($productId, $controller, $params);
    if (!$product) {
        throw new Mage_Core_Exception($this->__('Product is not loaded'), $this->ERR_NO_PRODUCT_LOADED);
    }
   /*
    * Do some fancy stuff to remove the product from the cart
    * now that we know there is a product and we have the $params
    * sorry no really fancy logic here is just for an example
    * also you may want to verify the start/stop of the if(!(int)$params->getData('qty'))
    *
    *
    */
    if(!(int)$params->getData('qty'))
    {
       // remove product from cart

    }
    else
    {

        $buyRequest = $params->getBuyRequest();
        if ($buyRequest) {
            $productHelper->prepareProductOptions($product, $buyRequest);
        }

        if ($params->hasConfigureMode()) {
            $product->setConfigureMode($params->getConfigureMode());
        }

        Mage::dispatchEvent('catalog_controller_product_view', array('product' => $product));

        if ($params->getSpecifyOptions()) {
            $notice = $product->getTypeInstance(true)->getSpecifyOptionMessage();
            Mage::getSingleton('catalog/session')->addNotice($notice);
        }

    } // end logic if we are removing item from cart

    Mage::getSingleton('catalog/session')->setLastViewedProductId($product->getId());

    $this->initProductLayout($product, $controller);

    $controller->initLayoutMessages(array('catalog/session', 'tag/session', 'checkout/session'))
        ->renderLayout();

    return $this;
}
1
  • Thank you. I will continue my investigation based on your ideas.
    – ADDISON74
    Commented Jan 3, 2016 at 21:28
1

Magento has never removed product from the cart via the product view page, that is a function of the cart view page.

Putting that as a change request here on magento.stackexchange won't really affect anything.

You might try putting it through as a change request on github, but you'll have to write your own module to add product removal through product view quantity as a custom feature if you want Magento to behave that way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.