2013-05-22 83 views
0

我试图在产品的属性字段中添加'a href'/链接。 但是,我正在使用的方法不起作用 - 尽管它们在CMS页面内容中工作。当我查看产品,将显示该链接的属性,但实际的URL似乎不正确生成(404错误)magento链接到产品属性不起作用的cms页面

我已经试过如下:

1. <a href="<?php echo Mage::getBaseUrl(); ?>test-page">Test link 1</a> 
2. <a href="{{store url='test-page'}}">Test link 2</a> 
3. <a href="index.php/test-page">Test link 3</a> 

我是什么做错了?

您的帮助是预先感谢

谢谢!

+0

实际产生什么URL(查看页面源)?此外,请确保您的属性允许在前端使用html标签(您可以通过后端的属性管理来确保这一点)。 –

+0

什么是您的字段类型? – Mufaddal

+0

字段类型:文本字段。前端的HTML标签:是的。 – user2381937

回答

2

Magento EAV属性值不会被PHP自己解析。为了向用户显示,它们通过前端模型呈现。示例见eav_attribute表。

根据“我们不想显示整个网址,只是文本链接”评论,您需要一个具有自定义前端模型的属性。我猜测它是通过管理面板添加的,它不允许添加自定义的前端模型。尽管添加前端模型需要脚本,但我建议首先通过脚本添加属性。

要正确安装此属性,Magento需要执行安装脚本,这是一个Magento术语,用于(通常)PHP代码,它只能执行一次操作数据库的能力。运行这些先决条件的模块存在:

应用的/ etc /模块/ Your_Module.xml

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <Your_Module> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Your_Module> 
    </modules> 
</config> 

应用程序/代码/本地/你/模块的/ etc/config.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <Your_Module> 
      <version>1.0.0.0</version> 
     </Your_Module> 
    </modules> 
    <global> 
     <models> 
      <your_module> 
       <class>Your_Module_Model</class> 
      </your_module> 
     </models> 
     <resources> 
      <your_module_setup> 
       <setup> 
        <module>Your_Module</module> 
       </setup> 
      </your_module_setup> 
     </resources> 
    </global> 
</config> 

应用程序/代码/地方/你/模块/ SQL/your_module_setup /安装-1.0.0.0.php

<?php 

$installer = Mage::getResourceModel('catalog/setup','catalog_setup'); 
/* @var $installer Mage_Catalog_Model_Resource_Setup */ 

$installer->startSteup(); 

$installer->addAttribute(
    'catalog_product', 
    'unique_attr_code', 
    array(
     'label'  => 'Link to Product', 
     'required' => 'false',    //or true if appropriate 
     'group'  => 'General',   //Adds to all sets 
     'frontend' => 'your_module/frontend_url' 
    ) 
); 

$installer->endSetup(); 

应用程序/代码/地方/你/模块/型号/前端/ Url.php

class Your_Module_Model_Frontend_Url 
    extends Mage_Eav_Model_Entity_Attribute_Frontend_Abstract 
{ 
    public function getUrl($object) 
    { 
     $url = false; 
     if ($path = $object->getData($this->getAttribute()->getAttributeCode())) { 
      $url = Mage::getUrl('path'); 
     } 
     return $url; 
    } 
}