从另一个产品属性中获取产品属性? [英] Getting a product attribute from within another product attribute?

查看:83
本文介绍了从另一个产品属性中获取产品属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到的WYSIWYS编辑器将我们的视频嵌入代码弄乱了.

We are having issues with the WYSIWYS editor messing up our embed codes for videos.

我们想到的一种解决方案是使嵌入代码具有自己的属性,然后在产品说明中调用该属性.

One solution we came up with is to make the embed code its own attribute, then call that attribute from within the product description.

那有可能吗?

我们不想将其添加到.phtml中,我们希望将其放置在说明中.

We don’t want to add it to the .phtml, We would rather place it in the description.

推荐答案

实际上,如果您打算完全不进行任何代码修改就这样做不可能.

As it is, this is impossible if you plan to do it without any code modification at all.

但是,如果您想通过在Mage_Catalog_Model_Product中调用一个全新的函数来处理描述中的某些内容,请像

However, if you want to process something in the description by calling a whole new function in Mage_Catalog_Model_Product, say like

$_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

然后说您喜欢产品说明,例如:

then say you like your product descriptions to be like:

Lorem Ipsum Dolor Test Description
See our video below!
[[video]]

其中video是自定义产品属性

您可以重写Mage_Catalog_Model_Product类以获取新功能.为此,请创建一个模块!

you can rewrite the Mage_Catalog_Model_Product class in order to get your new function in. To do that, create a module!

app/etc/modules/Electricjesus_Processeddescription.xml:

app/etc/modules/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>

app/code/local/Electricjesus/Processeddescription/etc/config.xml

app/code/local/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> 

app/code/local/Electricjesus/Processeddescription/Model/Product.php:

app/code/local/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!

然后,您应该可以在.phtml文件中使用$_product->getProcessedDescription().

Then you should be able to use $_product->getProcessedDescription() in your .phtml files.

很明显,有很多东西丢失了,这似乎完全是个hack(我甚至不确定我的preg_replace语句),但是您明白了.我们在这里所做的是仅制作一个模块来重写magento核心类以进行更多处理!

Obviously there are alot of stuff missing and it all seems that it is pretty much a hack (I'm not even sure about my preg_replace statement) but you get the idea. What we did here is to make a module solely just to rewrite a magento core class to do some more processing!

此外,您可能还希望获取一份 Magento备忘单的副本,以获取更多信息关于重写.

Additionally, you might also want to get a copy of a Magento Cheatsheet for more information about rewriting.

祝你好运!

塞思

这篇关于从另一个产品属性中获取产品属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆