属性未加载到product_list和分层导航上
-
16-10-2019 - |
题
我有一个开发系统,这是所有符合预期的工作。而且我有一个登台系统,此处没有加载属性。感觉,系统不知道,该属性在商店/attribute_set/...中不存在?
我有一个属性 artist_id
而且此属性未加载。
这些收藏品是用属性初始化的:
if (!is_null($this->_productCollection)) {
return $this->_productCollection;
}
$collection = parent::_getProductCollection();
$collection->addAttributeToSelect('artist_id');
我检查了该属性在集合中,它是:
[_selectAttributes:protected] => Array
(
[name] => 71
[short_description] => 73
[price] => 75
[special_price] => 76
[special_from_date] => 77
[special_to_date] => 78
[small_image] => 86
[thumbnail] => 87
[news_from_date] => 93
[news_to_date] => 94
[status] => 96
[url_key] => 97
[required_options] => 110
[image_label] => 112
[small_image_label] => 113
[thumbnail_label] => 114
[msrp_enabled] => 118
[msrp_display_actual_price_type] => 119
[msrp] => 120
[tax_class_id] => 122
[price_type] => 124
[weight_type] => 126
[price_view] => 127
[shipment_type] => 128
[links_purchased_separately] => 129
[links_exist] => 132
[artist_id] => 146
)
但是当我尝试得到 $_product->getArtistId()
没有ID。
对该系统进行调试真的很难。我试图找到构建查询但尚未找到的部分。
更新: :平桌子熄灭。
现在不好的部分:一点
<?php $_product->load($_product->getId()); ?>
在里面 foreach
的 product/list.phtml
解决问题;-)
老实说:我认为我在桌子中直接更改设置时在数据库中打破了一些东西。
属性和商店之间有任何联系吗?
对这个问题有什么想法吗?
解决方案 4
我绝对不知道这是怎么回事,这是故事的结尾:
这 backend_type
曾是 varchar
代替 int
.
对我来说很明显,该系列无法加载 artist_id
如果Magento不知道在哪里寻找值,但是为什么 $_product->load()
能够获得价值?我必须调查这个。
其他提示
查看属性设置,请确保“在前端的产品查看页面上可见”是肯定的,并且“在分层导航中使用”也是肯定的(仅当属性是下拉列表时)
更新:
您可以尝试的另一件事是添加:
<product>
<collection>
<attributes>
<artist_id/>
</attributes>
</collection>
</product>
在模块的config.xml中u003Cfrontend>部分。
如果它可以在开发人员上使用,但在舞台上不起作用 - 代码库是确切的副本 - 那么您的问题是您的数据库本身。
您可以通过用开发数据库的分期DB替换分期DB来轻松确认,并查看是否仍然发生。
除非您在DB中进行手动编辑,否则您所描述的内容不应发生 - 或者在两个站点上代码不同。
EAV表中的该属性是否有默认值?看看这个查询:
SELECT
`t_d`.`entity_id`,
`t_d`.`attribute_id`,
`t_d`.`value` AS `default_value`,
`t_s`.`value` AS `store_value`,
IF(t_s.value_id IS NULL, t_d.value, t_s.value) AS `value`
FROM `catalog_product_entity_varchar` AS `t_d`
LEFT JOIN `catalog_product_entity_varchar` AS `t_s`
ON t_s.attribute_id = t_d.attribute_id AND t_s.entity_id = t_d.entity_id AND t_s.store_id = 3
...
这就是Magento在集合中加载每个EAV属性的方式。如您所见,如果没有为默认存储设置的值设置(数据库中没有输入,则NULL会很好),则查询的第一部分将不返回结果,左JOIN无法正常工作,您的属性won' t加载 - 即使您有特定于商店的价值。
不幸的是,我曾经遇到过这件事,我们在进口方面做错了什么,我不得不进行很多调试,直到我最终意识到发生了什么。也许检查您的数据库。
也许尝试:
$product->getData('artist_id');
检查是否添加了属性('Artist_id') 属性集 特定产品所属的。