对于自定义产品类型,自定义选项不会出现在view.phtml上

时间:2012-12-14 13:20:03

标签: magento

我有maden定制产品类型(酒店)。它在后端有自定义选项选项卡。

我在某个产品(酒店)中添加了一些自定义选项。我已经将html添加到我的自定义主题的view.phtml中以输出自定义选项。

<?php if ($this->hasOptions()):?> <?php echo $this->getChildHtml('container1','', true, true) ?> <?php endif;?> 

此外,我已将块添加到我的布局中。

            <block type="core/template_facade" name="product.info.container1" as="container1">
                <action method="setDataByKey"><key>alias_in_layout</key><value>container1</value></action>
                <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                <action method="append"><block>product.info.options.wrapper</block></action>
                <action method="append"><block>product.info.options.wrapper.bottom</block></action>
            </block>
            <block type="core/template_facade" name="product.info.container2" as="container2">
                <action method="setDataByKey"><key>alias_in_layout</key><value>container2</value></action>
                <action method="setDataByKeyFromRegistry"><key>options_container</key><key_in_registry>product</key_in_registry></action>
                <action method="append"><block>product.info.options.wrapper</block></action>
                <action method="append"><block>product.info.options.wrapper.bottom</block></action>
            </block>

<action method="unsetCallChild"><child>container1</child><call>ifEquals</call><if>0</if>   <key>alias_in_layout</key><key>options_container</key></action>
<action method="unsetCallChild"><child>container2</child><call>ifEquals</call><if>0</if><key>alias_in_layout</key><key>options_container</key></action> 

<?php echo $this->getChildHtml('container1','', true, true) ?>返回空。

如何显示选项块?

1 个答案:

答案 0 :(得分:1)

我已经解决了这个问题并在帮助器中创建了函数来呈现自定义选项。代码如下:

  public function getHotelCustomOptionsHtml(Mage_Catalog_Model_Product $product)
{

    $blockOption = Mage::app()->getLayout()->createBlock("Mage_Catalog_Block_Product_View_Options");
    $blockOption->addOptionRenderer("default","catalog/product_view_options_type_default","catalog/product/view/options/type/default.phtml");
    $blockOption->addOptionRenderer("text","catalog/product_view_options_type_text","inchoo_catalog/product/view/options/type/text.phtml");
    $blockOption->addOptionRenderer("file","catalog/product_view_options_type_file","catalog/product/view/options/type/file.phtml");
      $blockOption->addOptionRenderer("select","catalog/product_view_options_type_select","catalog/product/view/options/type/select.phtml");

    $blockOption->addOptionRenderer("date","catalog/product_view_options_type_date","catalog/product/view/options/type/date.phtml") ;
    $blockOptionsHtml = null;
     if($product->getTypeId() =="hotel")
     {
        $blockOption->setProduct($product);
        if($product->getOptions())
        {
            foreach ($product->getOptions() as $o)
            {
                $blockOptionsHtml .= $blockOption->getOptionHtml($o);
            };
        }
     }

     return $blockOptionsHtml;
}