简体   繁体   English

Magento:如何在另一个模块中包含.phtml

[英]Magento: how to include a .phtml from one module in another

I have two modules installed. 我安装了两个模块。

One module (module1) that was developed for onepage checkout and it is working fine. 为单页结账开发的一个模块(module1),工作正常。 It replaces available.phtml with some new shipping methods etc. 它用一些新的运输方法取代了available.phtml等。

I want to include this available in a new cashier (module2) that is not based on the onepage checkout. 我希望将此功能包含在一个不基于单页结账的新收银台(module2)中。 So I tried doing this: 所以我尝试这样做:

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>

It successfully includes the available.phtml. 它成功地包含了available.phtml。 However, available.phtml does not behave as it should. 但是,available.phtml的行为并不像它应该的那样。

The first line in available.phtml is: available.phtml的第一行是:

<?php if (!($_shippingRateGroups = $this->getShippingRates())): ?>
    <p><?php echo Mage::helper('unifaun')->__('No shipping methods that suit your order were found. Please contact customer service.') ?></p>
<?php else: ?>
etc... 

The problem is that I don't get any shipping rates etc as I do in onepage checkout. 问题是,我没有得到任何运费等,就像我在一页结账时那样。 I have also manually entered the following: 我还手动输入以下内容:

<?php       
    $country = Mage::getStoreConfig('shipping/origin/country_id');
    $postcode = Mage::getStoreConfig('shipping/origin/postcode');
    $city = Mage::getStoreConfig('shipping/origin/city');

    $quote = Mage::getSingleton('checkout/session')->getQuote();
    $quote->getShippingAddress()
        ->setCountryId($country)
        ->setCity($city)
        ->setPostcode($postcode)
        ->setCollectShippingRates(true);        
?>

So my question is what I need to do to make the following line work correctly so that the code actually gets the availaable shipping methods etc..., as it does when the module is included in onepage checkout. 所以我的问题是我需要做些什么来使以下行正常工作,以便代码实际上获得可用的运输方法等...,就像当模块包含在一个页面结帐时一样​​。

$_shippingRateGroups = $this->getShippingRates()

I'm not sure if this is enough information to solve this problem, but I thought I make it a try and post it and see if anyone know what I'm doing wrong. 我不确定这是否足以解决这个问题,但我想我试一试并发布它,看看是否有人知道我做错了什么。 :) :)

Cheers! 干杯!

You are including a basic block of type core/template , all blocks are based of that. 您正在包含core/template类型的基本块,所有块都基于此。

So in your context there is no method getShippingRates for it to find. 因此,在您的上下文中,没有方法getShippingRates可供查找。

So change the following to something like: 因此,将以下内容更改为:

<?php echo $this->getLayout()->createBlock('unifaun_onepage/the_block_name')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>

Where the_block_name is the folder in the modules block, eg /Block/The/Block/Name.php 其中the_block_name是模块块中的文件夹,例如/Block/The/Block/Name.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM