2012-05-16 50 views
0

我們遇到了所見即所得的編輯器混亂了我們的視頻嵌入代碼的問題。從另一產品屬性中獲取產品屬性?

我們提出的一個解決方案是使嵌入代碼具有自己的屬性,然後從產品描述中調用該屬性。

這可能嗎?

我們不想將它添加到.phtml中,我們寧願將它放在描述中。

回答

1

如果您打算在沒有任何代碼修改的情況下執行此操作,則這是不可能

但是,如果你想通過調用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