2011-05-04 101 views
0

我从后端获取数据时遇到问题,因此我可以在控制器中显示它。Magento自定义模块从后端获取详细信息

例如我有这样的模块:http://www.magentocommerce.com/wiki/5_-_modules_and_development/payment/create-payment-method-module

config.xml中我会添加一个路由器控制器

<frontend> 
    <routers> 
     <custompay> 
      <use>standard</use> 
      <args> 
       <module>CompanyName_NewModule</module> 
       <frontName>newmodule</frontName> 
      </args> 
     </custompay> 
    </routers> 
</frontend> 

控制器(公司名称/ NewModule /控制器/ IndexController.php

class CompanyName_NewModule_IndexController extends Mage_Core_Controller_Front_Action { 

    protected $_order; 

    public function getOrder() { 
     if ($this->_order == null) { 

     } 
     return $this->_order; 
    } 

    public function indexAction(){ 
     $session = Mage::getSingleton('checkout/session'); 
     $session->setCompanyNameNewModuleQuoteId($session->getQuoteId()); 
     $this->getResponse()->setBody($this->getLayout()->createBlock('newmodule/redirect')->toHtml()); 
     $session->unsQuoteId(); 
     $session->unsRedirectUrl(); 
    } 

} 

块(公司名称/ NewModule /砌块/ Redirect.php

class CompanyName_NewModule_Block_Redirect extends Mage_Core_Block_Abstract { 

    protected function _toHtml() { 
     $html = '<html><body>'; 
     $html.= $this->__('You will be redirected to the payment website in a few seconds.'); 
     $html.= '</body></html>'; 

     return $html; 
    } 
} 

这是问题所在。我没有关于如何从后端获取详细信息的想法,我将在redirect.php块中使用它。以及如何获得顾客想要购买的产品细节。

我知道我需要包括模型,以便我能得到的细节,当我的print_r这个

Mage::getSingleton('checkout/session'); 

我没有看到任何产品的详细信息。

请分享一些知识或链接。你的帮助将是对magento开发者初学者的一大贡献。谢谢。

回答

2

,你可以做你的块类似的东西来获得报价和使用的支付方法实例

$quote = Mage::getSingleton('checkout/session')->getQuote(); 

//to assure that you don't initiate a new instance with Mage::getModel('yourextension/model'); and always use the same instance 
$paymentMethod = $quote->getPayment()->getMethodInstance(); 

//assuming that this is implemented and returns Mage::getStoreConfig('your/config/path'); 
$paymentMethodConfig = $paymentMethod()->getConfig(); 

$products = $quote->getAllItems();