문제

I have a development system, here is everything working as expected. And I have a staging system, here the attribute is not loaded. It feels like, the sytem don't know, that the attribute doesn't exist in the store/attribute_set/...?

I have an attribute artist_id and this attribute is not loaded.

The collections are initialized with the attribute:

if (!is_null($this->_productCollection)) {
    return $this->_productCollection;
}
$collection = parent::_getProductCollection();
$collection->addAttributeToSelect('artist_id');

I checked wether the attribute is in the collection and it is:

[_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
    )

But when I try to get $_product->getArtistId() there is no id.

Debugging on this system is really hard. I tried to find the part where the query is built but didn't find it yet.

UPDATE: Flat tables are OFF.

And now the bad part: A little

<?php $_product->load($_product->getId()); ?>

in the foreach of the product/list.phtml fixes the problem ;-)

To be honest: I think I broke something in the database while changing settings directy in the tables.

Is there any connection between attributes and stores?
Any ideas on this problem?

도움이 되었습니까?

해결책 4

I have abssolutely NO idea how this happend, here is the end of the story:

The backend_type was varchar instead of int.

It is obvious to me, that the collection can not load the artist_id if magento don't know where to look for the value, but why is a $_product->load() able to get the value? I have to investigate this.

다른 팁

Take a look at attribute settings, make sure that 'Visible on Product View Page on Front-end' is yes and 'Use In Layered Navigation' is yes too (only if attribute is dropdown)

UPDATE:

Another thing you can try is adding:

    <product>
        <collection>
            <attributes>
                <artist_id/>
            </attributes>
        </collection>
    </product>

In config.xml of a module, in the <frontend> section.

If it works on dev but not on staging - and the code base is an exact copy - then your issue is your DB itself.

You could very easily confirm by replacing your staging DB with that of your development DB and see if it still happens.

What you are describing just shouldn't happen unless you've been making manual edits in the DB - or the code is different on your two sites.

Is there a default value for that attribute in the EAV table? Have a look at this query:

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
...

This is how Magento loads every EAV attribute in collections. As you see, if there is no value set for the default store (no entry in the database, NULL would be fine), the first part of the query will return no result, the LEFT JOIN won't work and your attribute won't get loaded - even if you have a store-specific value.

Unfortunately I ran into this once already, we did something wrong with an import and I had to debug quite a lot until I finally realised what happened. Maybe check your DB.

Maybe try:

$product->getData('artist_id');

Check whether the attribute('artist_id') is added to the Attribute set to which the particular product belongs.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top