简体   繁体   中英

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. It replaces available.phtml with some new shipping methods etc.

I want to include this available in a new cashier (module2) that is not based on the onepage checkout. 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. However, available.phtml does not behave as it should.

The first line in available.phtml is:

<?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.

So in your context there is no method getShippingRates for it to find.

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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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