[英]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.