Magento:如何在产品编辑器的描述中插入PHP调用


Magento: How to insert a PHP call in the description of a product editor

我有一个下面的代码

<?php echo Mage::helper('stockstatus')->getListStatus(01); ?>

此代码返回特定产品的库存状态。当我将它插入到magento中的. php文件中时,效果非常好。

但是我也想在产品描述中使用它。问题是,如果我把这个代码放在一个产品的描述中,它不会返回任何东西。在前端,它只显示实际的代码。

我的问题是如何使它在插入产品的描述编辑器时工作?请帮忙

我不认为这里有一个真正理想的解决方案-您可以在.phtml文件中使用str_replace来处理一些特定的字符串,如[[stock_status]]。

$description = $_product->getDescription();
$description = str_replace('[[stock_status]]', Mage::helper('stockstatus')->getListStatus($_product->getId()), $description);

这样做的问题是,如果你要在其他任何地方使用产品描述,你要么不得不继续做字符串替换,要么在你的描述中结束这些标签。