如何在将一个项目添加到购物车后重定向用户? 让我说我希望他选择一个项目并转到结帐/一页,我该怎么做?
答案 0 :(得分:14)
你可以创建一个观察者来监听checkout_cart_add_product_complete事件,你可以在那里做类似以下的事情
public function addToCartComplete(Varien_Event_Observer $observer) {
// Send the user to the Item added page
$response = $observer->getResponse();
$request = $observer->getRequest();
$response->setRedirect(Mage::getUrl('checkout/onepage'));
Mage::getSingleton('checkout/session')->setNoCartRedirect(true);
}
您的配置看起来像这样
<frontend>
<events>
<checkout_cart_add_product_complete>
<observers>
<packagename_modulename_observer>
<type>singleton</type>
<class>packagename_modulename/observer</class>
<method>addToCartComplete</method>
</packagename_modulename_observer>
</observers>
</checkout_cart_add_product_complete>
</events>
</frontend>
答案 1 :(得分:1)
使用checkout_cart_add_product_complete,您将错过产品addtocart成功消息,请检查此
Mage::dispatchEvent('checkout_cart_add_product_complete',
array('product' => $product, 'request' => $this->getRequest(), 'response' => $this->getResponse())
);
if (!$this->_getSession()->getNoCartRedirect(true)) {
if (!$cart->getQuote()->getHasError()) {
$message = $this->__('%s was added to your shopping cart.', Mage::helper('core')->escapeHtml($product->getName()));
$this->_getSession()->addSuccess($message);
}
$this->_goBack();
}
如果您不想发布会话消息,请再次从产品页面传递其他参数
<input type="hidden" name="return_url" value="<?php echo $this->getUrl('checkout/onepage')?>"/>
无需任何其他自定义或模块创建,其magento的默认功能