首页 文章

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

提问于
浏览
0

Overview:

在我的产品 Test Product 上有 10 数量 .

enter image description here

所以当我把 40 数量并按添加到购物车 . (请记住,产品的数量是10,所以它应该提示错误)

enter image description here

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

enter image description here

如果仔细查看URL,在用户单击“添加到购物车”之前,URL就是

enter image description here

显示错误时,URL为

enter image description here

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

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

1 回答

  • 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);
    }
    

    此处的产品在没有类别信息的情况下加载,因此类别不是此URL的一部分 .

相关问题