Magento自定义属性默认值未显示在前端

时间:2022-05-14 20:36:17

I have added some custom attributes to the products in the admin section of our Magento 1.3.2.1 installation and I've given some of those attributes default values. The problem is that the default values aren't being returned when I try to get the attribute from the product object as follows:

我在Magento 1.3.2.1安装的admin部分为产品添加了一些自定义属性,并且我已经给出了一些属性默认值。问题是当我尝试从产品对象获取属性时,不会返回默认值,如下所示:

$_product->getCode()

Logically, I would imagine that the default value gets returned if there isn't one stored against the product, but this doesn't seem to be the case (unless I'm plainly missing something).

从逻辑上讲,我会想象如果没有一个存储对产品存在,则会返回默认值,但事实并非如此(除非我明显遗漏了一些东西)。

The list below is all the current settings for one of the attributes that isn't returning the default value set.

下面的列表是未返回默认值集的其中一个属性的所有当前设置。

Attribute Properties:

Attribute Code: code

属性代码:代码

Scope: Store View

范围:商店视图

Catalog Input Type for Store Owner: Text Field

商店所有者的目录输入类型:文本字段

Default value: value

默认值:值

Unique Value: No

独特价值:没有

Values Required: No

所需值:否

Input Validation for Store Owner: None

商店所有者的输入验证:无

Apply To: All Product Types

适用于:所有产品类型

Frontend Properties:

Use in quick search: No

用于快速搜索:没有

Use in advanced search: No

在高级搜索中使用:否

Comparable on Front-end: No

可比较的前端:没有

Use In Layered Navigation: No

在分层导航中使用:否

Use In Search Results Layered Navigation: No

在搜索结果中使用分层导航:否

Use for Price Rule Conditions: No

用于定价规则条件:否

Position: 0

Allow HTML-tags on Front-end: Yes

在前端允许HTML标记:是的

Visible on Product View Page on Front-end: Yes

在前端的产品视图页面上可见:是的

Used in product listing: Yes

用于产品清单:是的

Used for sorting in product listing: No

用于产品列表中的分类:否

Thanks for your help! Remy

谢谢你的帮助!雷米

2 个解决方案

#1




echo $_product->getMyAttribute()

echo $_product->getAnotherCustomAttribute()
For  eg Attribute Label : Short Description
Then you must write code like     
echo $_product->getShortDescription()
if Attribute Label : Weight Then
echo $_product->getWeight()


echo $_product->getAttributeText('attribute_code') 
For  eg Attribute Label : Size and Attribute Code : size Then
echo $_product->getAttributeText('size')

#2


It seams that the Mage_Core_Model_Abstract class will not check for attributes in the __get magic method. Try using the getData method instead:

它接缝Mage_Core_Model_Abstract类不会检查__get魔术方法中的属性。请尝试使用getData方法:

$_product->getData('code');

#1




echo $_product->getMyAttribute()

echo $_product->getAnotherCustomAttribute()
For  eg Attribute Label : Short Description
Then you must write code like     
echo $_product->getShortDescription()
if Attribute Label : Weight Then
echo $_product->getWeight()


echo $_product->getAttributeText('attribute_code') 
For  eg Attribute Label : Size and Attribute Code : size Then
echo $_product->getAttributeText('size')

#2


It seams that the Mage_Core_Model_Abstract class will not check for attributes in the __get magic method. Try using the getData method instead:

它接缝Mage_Core_Model_Abstract类不会检查__get魔术方法中的属性。请尝试使用getData方法:

$_product->getData('code');