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

时间:2011-05-04 02:34:20

标签: php 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>

控制器( 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 / 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 个答案:

答案 0 :(得分:2)

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

查看此文章了解更多信息: - Magento: Get all shopping cart items and totals

希望这会有所帮助。感谢。

答案 1 :(得分: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();
相关问题