【问题标题】:Stop Magento from emptying the shopping cart before payment confirmation?在付款确认之前阻止 Magento 清空购物车?
【发布时间】:2012-03-06 15:53:01
【问题描述】:

自从我开始为我的网上商店测试 Magento 以来,这是我发现的最重要的问题之一。 在确认付款之前清空购物车是绝对没有必要和有害的,这对销售来说是毫无必要的,不幸的是,Magento 做到了。

如果用户选择 PayPal(网站标准)作为付款方式,并且由于某种原因在 PayPal 付款页面上点击“返回 xxxx”(您在 PayPal 的公司名称)未付款,则 PayPal 将重定向用户回到http://www.example.com/checkout/cart/,现在是一个空购物车。

我认为应该在付款确认/PayPal IPN 之后清空购物车,而不是之前的任何时间。

即使用户想再次继续,他或她也会因为再次搜索和添加所有产品而烦恼,并且很可能会离开。

知道如何解决这个问题吗?

【问题讨论】:

  • 嘿,您能否确认以下哪种解决方案对您有效,因为它将帮助像我这样的其他人测试并获得解决方法。谢谢
  • @echoashu,尝试了所有方法,但对我没有任何效果。
  • @echoashu,对我来说也没有用。我正在使用单页结帐。

标签: magento e-commerce


【解决方案1】:

这对我有用:

文件:~/app/code/core/Mage/Checkout/controllers/OnepageController.php

替换这个:

$this->getOnepage()->getQuote()->save();
/**
 * when there is redirect to third party, we don't want to save order yet.
 * we will save the order in return action.
 */
if (isset($redirectUrl)) {
    $result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

有了这个:

/**
 * when there is redirect to third party, we don't want to save order yet.
 * we will save the order in return action.
 */
if (isset($redirectUrl)) {
    $result['redirect'] = $redirectUrl;
    $this->getOnepage()->getQuote()->setIsActive(1) ;
}
$this->getOnepage()->getQuote()->save();
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

【讨论】:

  • 不应更改核心文件。您应该始终覆盖控制器。
  • 我正在使用 IWD 单页结帐。这段代码对我不起作用。请告诉我该怎么做?
  • 此解决方案是在尝试付款之前创建订单。但是如果你取消了几次,然后去 MyAccount/MyOrders 你会看到所有的尝试,所有的订单。我只想保留报价而不是订单。对我没用...
【解决方案2】:

对于 Paypal,我在 app/code/core/Mage/Paypal/controllers/StandardController.php cancelAction 中找到了取消操作

我为取消操作更改了类似的代码

public function cancelAction()
{
    $session = Mage::getSingleton('checkout/session');
    $cart = Mage::getSingleton('checkout/cart');
    $session->setQuoteId($session->getPaypalStandardQuoteId(true));
    if ($session->getLastRealOrderId()) {
        $incrementId = $session->getLastRealOrderId();
        if (empty($incrementId)) {
            $session->addError($this->__('Your payment failed, Please try again later'));
            $this->_redirect('checkout/cart');
            return;
        }
        $order = Mage::getModel('sales/order')->loadByIncrementId($session->getLastRealOrderId());
        $session->getQuote()->setIsActive(false)->save();
        $session->clear();
        try {
            $order->setActionFlag(Mage_Sales_Model_Order::ACTION_FLAG_CANCEL, true);
            $order->cancel()->save();
        } catch (Mage_Core_Exception $e) {
            Mage::logException($e);
        }
        $items = $order->getItemsCollection();
        foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (Mage_Core_Exception $e) {
                $session->addError($this->__($e->getMessage()));
                Mage::logException($e);
                continue;
            }
        }
        $cart->save();
        $session->addError($this->__('Your payment failed. Please try again later'));
    }
    $this->_redirect('checkout/cart');
}

它对我来说效果很好,没有必要为此改变任何其他地方。

它将当前订单标记为已取消并使用该订单恢复购物车并将用户再次重定向到购物车。

【讨论】:

    【解决方案3】:

    /app/code/core/Mage/Checkout/controllers/OnepageController.php 此文件是实际的控制器文件,但取决于付款方式扩展名,它将随 Namespace/Modulename/Checkout/controllers/OnepageController.php

    查找函数 saveOrderAction()

    找到这些行

    $this->getOnepage()->getQuote()->save();
            /**
             * when there is redirect to third party, we don't want to save order yet.
             * we will save the order in return action.
             */
            if (isset($redirectUrl)) {
                $result['redirect'] = $redirectUrl;
            }
    
            $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    

    评论此行//$this->getOnepage()->getQuote()->save(); 并在 if 条件中添加以下代码,使条件看起来像..

    //$this->getOnepage()->getQuote()->save();
            if (isset($redirectUrl)) {
                        $result['redirect'] = $redirectUrl;
                        $this->getOnepage()->getQuote()->setIsActive(1) ;
                    }
            $this->getOnepage()->getQuote()->save();
           $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
    

    这是我通过第三方支付扩展完成的。

    【讨论】:

      【解决方案4】:

      从 Magento 1.6.0.0 版(2011 年 7 月)开始,您可以启用 “持久购物车”

      System > Configuration > Customers > Persistent Shopping Cart
      

      这应该可以解决这个问题。

      使用这些设置使其工作

      Enable Persistence = Yes
      Persistence Lifetime (seconds) = 31536000
      Enable "Remember Me" = Yes
      "Remember Me" Default Value = Yes
      Clear Persistence on Log Out = No
      Persist Shopping Cart = Yes
      

      祝你好运:)

      【讨论】:

      • 但是这个购物车不是在结账时也被清空了吗? (点击支付进入PSP页面)
      【解决方案5】:

      您的问题在于 Mage_Checkout_OnepageController::saveOrderAction() 的行为方式。

      更具体:打开app/code/core/Mage/Checkout/controllers/OnepageController.php

          $this->getOnepage()->getQuote()->save();//this makes the cart empty (sets the quote as converted to order)
          if (isset($redirectUrl)) {
              $result['redirect'] = $redirectUrl;
          }
      
          $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
      }
      

      你可以替换最后一部分:

      $this->getOnepage()->getQuote()->save();//....
      

      与:

      if (isset($redirectUrl)) {
          $result['redirect'] = $redirectUrl;
          $this->getOnepage()->getQuote()->setIsActive(1) ;
      }
      $this->getOnepage()->getQuote()->save();
      $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
      

      【讨论】:

      • 这是什么文件?
      • @AryehArmon,我已插入此文件的路径。检查一次。
      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2011-04-09
      • 2023-04-02
      • 2012-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      相关资源
      最近更新 更多