When removing an item from the cart, Magento redir

2020-07-30 02:51发布

问题:

I'm setting up a Magento 1.4.2 cart to replace an older version (1.1.6). I'm currently working on a development machine, and when I have multiple items in my cart and use the "delete" button on one of the products the item is removed and I am redirected via a 302 response code to the base URL of the store, instead of to '/checkout/cart/' (which is how the older version cart works).

I'm stuck trying to figure out what is different between the two carts that is causing this redirect. Some notes on my setup that may or may not be relevant:

  • There are 2 websites/stores/store views
  • The store view I'm currently working with is accessed via a sub-URL and separate index.php file. The main store URL is https://www.thestore.com/ and the store I'm working with is accessed at https://www.thestore.com/second-store/index.php/. If you're unfamiliar with this approach, here is how it is done: Store views by index.php
  • The old cart (running 1.1.6) is running on a slightly different server setup, and you can safely assume anything is possible in the setup - modifications of core Mage code is possible, for example.

I'm looking for any hints on where to look - Magento configurations via the admin panel, local.xml changes, Apache rewrite rules...any tips on how to find out WHY this new cart isn't redirecting to /store/checkout/cart/ when I delete a product from my cart.

If you need more details, I'd be happy to provide them. We have a kinda funky setup that has been truly hacked together, and I'm also open to suggestions on how to set things up if it sounds like we're doing something wrong. Thanks!

回答1:

This may be old news, but I had the same issue in magento 1.5.10 in December 2011. and I successfully addressed it by editing

CartController.php:

in

function deleteAction

replace

$this->_redirectReferer(Mage::getUrl('*/*'));

with

$this->_redirect('checkout/cart');

Don't copy and paste this, make sure you type it, and use single quotes around checkout/cart



回答2:

if you've checked the setting that B00MER suggested, then I think that your next step needs to be to live debug your way through the request handling flow. Have a read of my previous answer for some pointers on getting your Magento debug environment setup.

That answer is also relevant because it involves the updatePostAction in the CartController, the same method that is responsible in this situation.



回答3:

For rewriting the core file we need to create a module and make the following change.

public function deleteAction()
{
    if ($this->_validateFormKey()) {
        $id = (int)$this->getRequest()->getParam('id');
        if ($id) {
            try {
                $this->_getCart()->removeItem($id)
                    ->save();
            } catch (Exception $e) {
                $this->_getSession()->addError($this->__('Cannot remove the item.'));
                Mage::logException($e);
            }
        }
    } else {
        $this->_getSession()->addError($this->__('Cannot remove the item.'));
    }

    $this->_redirect('checkout/cart');
}

Please refer my tutorial for step by step explanation.

http://www.pearlbells.co.uk/remove-item-magento-cart-redirects-homepage/