Magento自定义模块从后端获取详细信息


Magento custom module get details from backend

我在从后端获取数据时遇到问题,所以我可以在控制器中显示它。

例如,我有这个模块: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>

控制器(CompanyName/NewModule/controllers/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();
    }
}

阻止(CompanyName/NewModule/Block/Rerect.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块中使用它。以及如何获得客户想要购买的产品详细信息。

我知道我需要包括模型,这样我就可以得到详细信息,当我打印这个时

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

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

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

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

查看这篇文章了解更多:-Magento:获取所有购物车项目和总

希望这能有所帮助。谢谢

您可以在您的区块中执行类似的操作,以获得报价和使用的支付方法实例

$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();