Magento - 附加信息选项卡 - 将No替换为其他内容

时间:2014-03-05 18:31:42

标签: php magento

在Magento中,有一个默认选项卡,将产品属性中的信息显示为附加信息。

目前显示它们为例如:

Brands  Brandname
Serie   Seriename
Designer    Mr Designer
Delivery time   No
Finishing   No
Height  227 mm.
Width   -
Depth   -
Projection  212,5 mm.
Download Manual -
Download Technical Specifications   No

我的问题是,如果有配置,或者我是否可以编辑代码,那么当它找不到值时,它会显示像' - '那样的短划线,而不是上面的例子中看到的?

宽度和深度似乎显示破折号,但交货时间和完成例如没有。宽度/深度与交货时间/精加工之间的差异在于宽度/深度是文本字段,交货/精加工是下拉。

1 个答案:

答案 0 :(得分:0)

Magento中影响此显示行为的代码是

//file: app/code/core/Mage/Catalog/Block/Product/View/Attributes.php
//class:Mage_Catalog_Block_Product_View_Attributes
public function getAdditionalData(array $excludeAttr = array())
//...
if (!$product->hasData($attribute->getAttributeCode())) {
    $value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
    $value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
    $value = Mage::app()->getStore()->convertPrice($value, true);
}
//...

我们可以从此代码中看到,评估为false==''的任何属性数据将分别获得$value 'N/A''No'。< / p>

这确实提出了一个重要问题:宽度和高度何时设置为$value='-'

我认为将'No'更改为'-'的最简单方法是使用Magento管理区域在每个属性的下拉列表中添加'-'作为属性选项并告诉您的数据-entry运算符使用它而不是空白。 如果您不知道如何,Shivam上面的链接将帮助您做到这一点。

如果您想编写解决方案,我建议:

a)找出宽度和深度为'-'而非'0''No''N/A'的原因,因为如果您已经更改了代码'0'或{ {1}}到''那么这也是'-'更改为'No'

的地方

或 b)添加或创建自己的模块,扩展'-'类并覆盖Mage_Catalog_Block_Product_View_Attributes

或 c)通过将字符串public function getAdditionalData(array $excludeAttr = array())替换为字符串app/design/frontend/base/default/template/catalog/product/view/attributes.phtml来隐藏phtml文件str_replace()以在$_helper->productAttribute($_product, $_data['value'], $_data['code'])上包含'>No<'(注意搜索字符串是唯一的,并且在你破解之前将该文件复制到'>-<'

我的意思是:

在文件app/design/frontend/yourtheme/default/template/catalog/product/view/attributes.phtml

替换

app/design/frontend/yourtheme/default/template/catalog/product/view/attributes.phtml

<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>

但这不是一个严格的解决方案。

相关问题