2010-10-29 80 views

回答

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> 
+0

作品真的很好,由于通过额外的参数! – arithran 2017-03-20 11:56:56

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的默认功能

相关问题