[英]Magento: how to include a .phtml from one module in another
我安装了两个模块。
为单页结账开发的一个模块(module1),工作正常。 它用一些新的运输方法取代了available.phtml等。
我希望将此功能包含在一个不基于单页结账的新收银台(module2)中。 所以我尝试这样做:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>
它成功地包含了available.phtml。 但是,available.phtml的行为并不像它应该的那样。
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...
问题是,我没有得到任何运费等,就像我在一页结账时那样。 我还手动输入以下内容:
<?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);
?>
所以我的问题是我需要做些什么来使以下行正常工作,以便代码实际上获得可用的运输方法等...,就像当模块包含在一个页面结帐时一样。
$_shippingRateGroups = $this->getShippingRates()
我不确定这是否足以解决这个问题,但我想我试一试并发布它,看看是否有人知道我做错了什么。 :)
干杯!
您正在包含core/template
类型的基本块,所有块都基于此。
因此,在您的上下文中,没有方法getShippingRates
可供查找。
因此,将以下内容更改为:
<?php echo $this->getLayout()->createBlock('unifaun_onepage/the_block_name')->setTemplate('unifaun/checkout/onepage/shipping_method/available.phtml')->toHtml(); ?>
其中the_block_name
是模块块中的文件夹,例如/Block/The/Block/Name.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.