0
votes

Overview:

On my product called Test Product has 10 quantity.

enter image description here

So when I put 40 quantity and press add to cart. (Remember, the quantity of the product is 10, so it should prompt an error)

enter image description here

The output is correct, the user got notified by the system that they put greater than the quantity than the actual quantity of the product.

enter image description here

If you look at the URL closely, before the user click the add to cart, the URL is

enter image description here

When the error has been shown, the URL is

enter image description here

Meaning, magento removes the category link and redirects to the actual product link.

Question Is there any way for magento to redirect to the current category instead of the product link?

1

1 Answers

0
votes

Both redirecting to the category or the product with category included in the url is not possible by default. You need to write a module for that.

Let's have a look where the redirection is done in the code, so the behaviour can be modified. Starting from the cart controller products are added to cart in Mage_Checkout_CartController::addAction(). The product is added with

$cart   = $this->_getCart();
...
$cart->addProduct($product, $params);

Having a closer look at Mage_Checkout_Model_Cart::addProduct() the redirection url for products with insufficient stock amount is set here:

/**
* String we can get if prepare process has error
*/
if (is_string($result)) {
$redirectUrl = ($product->hasOptionsValidationFail())
    ? $product->getUrlModel()->getUrl(
        $product,
        array('_query' => array('startcustomization' => 1))
    )
    : $product->getProductUrl();
$this->getCheckoutSession()->setRedirectUrl($redirectUrl);
if ($this->getCheckoutSession()->getUseNotice() === null) {
    $this->getCheckoutSession()->setUseNotice(true);
}
Mage::throwException($result);
}

The product here is loaded without the category information so the categories aren't part of this url.