Magento静态块无法正常显示。

时间:2014-04-16 12:27:31

标签: php magento

我根据尝试显示不同块的类别ID创建了一些静态块

  • 有时会显示该块的问题,而有时则不会显示。

  • 我猜代码有问题吗?或者磁铁显示静止块的方式不确定?

CODE:

<?php

<?php $_description = $this->getProduct()->getDescription(); ?>
<?php if ($_description): ?>
    <div class="std">
        <?php echo $this->helper('catalog/output')->productAttribute($this->getProduct(), $_description, 'description') ?>
        <?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
<?php if($category->getId()==14): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==15): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==16): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==18): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==19): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==86): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==25): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==13): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information')->toHtml();?>
<?php elseif($category->getId()==98): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_fbyz')->toHtml();?>
<?php else: ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('products_information_others')->toHtml();?>
<?php endif; ?>

    </div>
<?php endif; ?>

请解决我的问题。

1 个答案:

答案 0 :(得分:0)

如果您将此代码放在product view page中,则无法正确获取产品页面中的当前类别。 使用Mage::registry("current_category")代替Mage::getModel('catalog/layer')->getCurrentCategory();

如果您直接进入类别,则可以获取当前的类别ID产品页面。然后您将获取当前的产品类别ID。

    $categoryIds = Mage::registry('current_product')->getCategoryIds();
    if(Mage::registry("current_category"))
    {
    $category = Mage::getModel('catalog/category')
->load(Mage::registry("current_category")->getId());
    }elseif(is_array($categoryIds )){
        //multiple categories id of product. that way i was taken on list category
        $category = Mage::getModel('catalog/category')->load($categoryIds[0]);
    }
    elseif(!is_null($categoryIds)){
            $category = Mage::getModel('catalog/category')->load($categoryIds);

    }
    else{
        //no categoies
    }