在默认布局中,选项和添加到购物车按钮由调用
<?php echo $this->getChildChildHtml('container1', '', true, true) ?>
我想将可配置选项从添加到购物车和数量字段中拆分出来,以在我的布局中的不同位置显示它们。有什么想法或准备好使用的解决方案吗?
你可以很容易地拆分它(但我花了很多时间来找到它:)-如果你查看公共函数getChildChildHtml的app/code/core/Mage/core/Block/Abstract.php到PHPDoc,你会发现第二个参数决定了子块名称。因此,您可以在价格块渲染之前先调用
<?php echo $this->getChildChildHtml('container1', 'product.info.options.wrapper', true, true) ?>
在价格块呈现后,调用
<?php echo $this->getChildChildHtml('container1', 'product.info.options.wrapper.bottom', true, true) ?>
虽然您的最终解决方案将取决于这些块需要在布局中移动/插入的位置,但您绝对可以将"添加到购物车"product.info.options.wrapper.bottom
从可配置选项product.info.container1
或product.info.container2
中分离出来,如下所示:
<catalog_product_view>
<reference name="product.info.container1">
<action method="unsetChild"><name>product.info.options.wrapper.bottom</name></action>
</reference>
<reference name="product.info.container2">
<action method="unsetChild"><name>product.info.options.wrapper.bottom</name></action>
</reference>
</catalog_product_view>
然后单独显示"添加到购物车"按钮的最简单方法是注释掉catalog/product/view.phtml
中的条件,该条件允许显示product.info.addtocart
块,无论产品是否有选项:
<?php if (!$this->hasOptions()): // Remove this condition ?>
<div class="add-to-box">
<?php if($_product->isSaleable()): ?>
<?php echo $this->getChildHtml('addtocart') ?>
...
<?php endif; ?>
</div>
...
<?php endif; ?>
希望这能帮助你理解这些块的结构。可能有帮助的其他资源:
- 在Magento的产品视图页面中,container1和container2是什么
- 如何纯粹通过local.xml移动breadcrumb块