【问题标题】:Add To Cart Error, product redirection issue - Magento添加到购物车错误,产品重定向问题 - Magento
【发布时间】:2014-02-10 06:46:28
【问题描述】:

概述:

在我的名为 Test Product 的产品上有 10 个数量。

所以当我输入 40 数量并按添加到购物车时。 (记住,产品的数量是10个,所以应该会提示错误)

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

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

显示错误后,URL 为

意思是,magento 删除了类别链接并重定向到实际的产品链接。

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

【问题讨论】:

    标签: php magento


    【解决方案1】:

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

    让我们看看代码中重定向是在哪里完成的,所以可以修改行为。 从购物车控制器产品开始添加到购物车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 的一部分。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-10
      • 2014-08-30
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多