添加到购物车错误,产品重定向问题 - Magento

时间:2014-02-10 06:46:28

标签: php magento

概述:

我的名为测试产品的产品数量 10

enter image description here

所以,当我输入 40 数量并按添加到购物车。 (请记住,产品数量为10,因此应提示错误)

enter image description here

输出正确,系统通知用户他们输入的数量大于产品的实际数量。

enter image description here

如果仔细查看网址,在用户点击添加到购物车之前,网址为

enter image description here

显示错误后,网址为

enter image description here

含义,magento删除类别链接并重定向到实际的产品链接。

问题 有没有办法让magento重定向到当前类别而不是产品链接?

1 个答案:

答案 0 :(得分:0)

默认情况下,无法重定向到类别或包含在网址中的类别的产品。你需要为此编写一个模块。

让我们看看在代码中完成重定向的位置,以便可以修改行为。 从购物车控制器开始,产品将添加到Mage_Checkout_CartController::addAction()中的购物车中。该产品添加了

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

仔细查看Mage_Checkout_Model_Cart::addProduct()此处设置库存量不足的产品的重定向网址:

/**
* 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);
}

此处的产品在没有类别信息的情况下加载,因此类别不属于此网址的一部分。