我们遇到了所见即所得的编辑器混乱了我们的视频嵌入代码的问题。从另一产品属性中获取产品属性?
我们提出的一个解决方案是使嵌入代码具有自己的属性,然后从产品描述中调用该属性。
这可能吗?
我们不想将它添加到.phtml中,我们宁愿将它放在描述中。
我们遇到了所见即所得的编辑器混乱了我们的视频嵌入代码的问题。从另一产品属性中获取产品属性?
我们提出的一个解决方案是使嵌入代码具有自己的属性,然后从产品描述中调用该属性。
这可能吗?
我们不想将它添加到.phtml中,我们宁愿将它放在描述中。
如果您打算在没有任何代码修改的情况下执行此操作,则这是不可能。
但是,如果你想通过调用Mage_Catalog_Model_Product
一个全新的功能来处理在描述的东西,说喜欢
$_product = Mage::getModel('catalog/product');
$_product->getProcessedDescription(); // assuming this is the function you will be using in stead of $_product->getDescription(); in your PHTML files
然后说你喜欢你的产品的描述是这样的:
Lorem Ipsum Dolor Test Description
See our video below!
[[video]]
其中video
是一个自定义产品属性
您可以重写Mage_Catalog_Model_Product类以获得你的新功能。为此,创建一个模块!
应用的/ etc /模块/ Electricjesus_Processeddescription.xml:
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Processeddescription>
<active>true</active>
<codePool>local</codePool>
<version>0.0.1</version>
</Electricjesus_Processeddescription>
</modules>
</config>
应用程序/代码/本地/ Electricjesus/Processeddescription的/ etc/config.xml中
<?xml version="1.0"?>
<config>
<modules>
<Electricjesus_Processeddescription>
<version>0.0.1</version>
</Electricjesus_Processeddescription>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product>Electricjesus_Processeddescription_Model_Product</product>
</rewrite>
</catalog>
</models>
</global>
</config>
应用程序/代码/本地/ Electricjesus /Processeddescription/Model/Product.php:
<?php
class Electricjesus_Processeddescription_Model_Product extends Mage_Catalog_Model_Product {
public function getProcessedDescription() {
$desc = $this->getDescription();
return preg_replace("/\[\[video\]\]/", $this->getVideo(), $desc);
}
}
//NEVER close <?php tags in Magento class files!
然后你应该可以使用$_product->getProcessedDescription()
在您的.phtml文件中。
很明显,有很多东西丢失,似乎它几乎是一个黑客(我甚至不知道我的preg_replace声明),但你明白了。我们在这里做的是制作一个模块,只是为了重写一个magento核心类来做更多的处理!
此外,您可能还想获得Magento Cheatsheet的副本以获取有关重写的更多信息。
祝你好运!
Seth