2
我只是創建一個模塊名稱引用。現在我想將推薦塊放置到另一個模塊模板文件名稱success.phtml。可以做到嗎?調用另一個模板中的塊
referral.xml(在推薦模塊)
<?xml version="1.0"?>
<layout version="0.1.0">
<checkout_onepage_success>
<reference name="checkout.success">
<block type="referral/referral" name="referralCallLink"><action method="referralCallLink"></action></block>
</reference>
</checkout_onepage_success>
<!--block type="referral/referral" name="referralAddSession"><action method="referralAddSession"></action></block-->
</layout>
success.phtml
<?php if($hasBoughtMCash): ?>
<div> Your
<?php echo implode(', ',$hasBoughtMCash); ?>
purchase is successful.
</div>
<?php endif; ?>
<h2>Share in Facebook and Earn for Free MCash!</h2>
<?php echo $this->getChildHtml(); ?>
Referral.php(塊)
public function referralCallLink() //success page
{
...
$collection7 = Mage::getModel('referral/referrallink')->getCollection();
$collection7->addFieldToFilter('customer_id', array('eq' => $cust_id));
$collection7->addFieldToFilter('grouped', array('eq' => $grouped));
foreach($collection7 as $data3)
{
$product = $data3->getData('product');
$link = $data3->getData('link');
$imageurl = $data3->getData('url');
//facebook
$title=urlencode('Shop, Save and Get Rewarded at MRuncit.com');
$url=urlencode($link);
$summary=urlencode('I just bought '.$product.' from MRuncit.com and earned some MReward Points!');
$image=urlencode($imageurl);
?>
<p>
<a href="http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325');" target="_blank">
<img src="<?php echo $imageurl;?>" width="30">
I just bought <?php echo $product; ?> from MRuncit.com and earned some MReward Points!
</a>
</p>
<?php
}
}
結果
嗨,這就像Checkout.xml和success.phtml我修改上面?它顯示致命錯誤:調用未定義的函數getChildHtml() – 2013-03-11 14:47:36
對不起,應該是'$ this-> getChildHtml()' - 我更新了代碼。 – 2013-03-11 14:55:18
另外,我從發佈的checkout.xml添加了佈局句柄和引用塊名稱。但請不要編輯checkout.xml,將XML代碼添加到您自己的佈局文件中! – 2013-03-11 14:59:15