2

我只是创建一个模块名称引用。现在我想将引用块放置到另一个模块模板文件名success.phtml。可以做到吗?

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

成功.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(); ?>

推荐人.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&amp;p[title]=<?php echo $title;?>&amp;p[summary]=<?php echo $summary;?>&amp;p[url]=<?php echo $url; ?>&amp;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

        }
    }

结果 在此处输入图像描述

4

1 回答 1

0

您应该在布局 XML 中将该块创建为成功块的子代:

<layout_handle_of_the_success_page>
    <reference name="name_of_the_success_block_in_layout">
        <block type="your/referral_block" />
    </reference>
</layout_handle_of_the_success_page>

然后您可以在success.phtml中插入以下行:

<?php echo $this->getChildHtml('referral'); ?>

您必须将示例 XML 中的一些名称替换为您自己的名称:

  • layout_handle_of_the_success_page- 您将在相应模块的布局 XML 中找到它。它的格式应该是module_controller_action --> checkout_onepage_success
  • name_of_the_success_block_in_layout- 同样从布局 XML 中,查找带有 success.phtml 模板及其name属性的块--> checkout.success
  • your/referral_block- 这是您要在表单中插入的块的类别名module/class --> 推荐/推荐
于 2013-03-11T13:38:30.727 回答