这是自从我开始为我的网上商店测试Magento以来我发现的最重要的问题之一。毫无疑问,在付款确认之前清空对销售是绝对不必要和有害的,不幸的是,Magento确实如此。
如果用户选择PayPal(网站标准)付款方式,并且出于某种原因,在PayPal付款页面上单击“返回xxxx”(您的公司名称为PayPal)而不付款,则PayPal会重定向用户返回http://www.example.com/checkout/cart/,现在是EMPTY购物车。
我认为应该在付款确认/ PayPal IPN之后将购物车清空,而不是之前的任何一点。
即使用户想要再次继续,他或她也会厌倦搜索并再次添加所有产品,很可能只是离开。
我知道如何解决这个问题吗?
答案 0 :(得分:6)
这对我有用:
档案:~/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));
答案 1 :(得分:4)
对于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');
}
它对我来说非常好,并且没有必要为此更改任何其他地方。
它将当前订单标记为已取消并使用该订单恢复购物车并再次将用户重定向到购物车。
答案 2 :(得分:0)
自Magento 1.6.0.0版(juli 2011)起,您可以启用" Persistent Shopping Cart"
下
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
祝你好运:)
答案 3 :(得分:0)
/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 :(得分:-1)
您的问题与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));