我正在尝试如何在新模块中使用Magento的本机函数。 所以对于一个简单的例子,假设我有一个基本的外壳,比如:
app/code/local/Me/Test/Block/Container.php
<?php
class Me_Test_Block_Container extends Mage_Core_Block_Template
{
}
在布局中.xml我插入了类别和产品页面独有的设计块:
<catalog_category_layered>
<reference name="after_body_start">
<block type="test/container" name="test.container" template="test/category_container.phtml"/>
</reference>
</catalog_category_layered>
<catalog_product_view>
<reference name="after_body_start">
<block type="test/container" name="test.container" template="test/product_container.phtml"/>
</reference>
</catalog_product_view>
</catalog_category_layered>
在这些 phtml 中,我尝试使用函数在类别页面上获取当前类别,并在产品页面上获取产品 SKU。 因此,对于我的 category_container.phtml 中的类别页面,我正在尝试使用该函数
<?php $_category = $this->getCurrentCategory();?>
但它返回空白。 有人可以帮我更多地了解这一点吗? 我将getCurrentCategory
函数复制到容器中.php但这不起作用。 我应该更改布局中的块类型.xml以便能够使用该函数还是正确的方法?
你可以这样得到类别:
$_category = Mage::registry('current_category');
而产品是这样的:
$_product = Mage::registry('current_product');
在使用它之前,请检查它们的值不是 null
.