Pregunta

Tengo un sistema de desarrollo, aquí está todo funcionando como se esperaba. Y tengo un sistema de estadificación, aquí el atributo no está cargado. Se siente como el Inglés no sé, que el atributo no existe en la tienda / attribute_set / ...?

Tengo una artist_id atributo y este atributo no está cargado.

Las colecciones se inicializa con el atributo:

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

he comprobado wether el atributo está en la colección y es:

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

Pero cuando trato de conseguir $_product->getArtistId() existe ningún id.

Depuración en este sistema es muy duro. He intentado encontrar la parte en que la consulta se construye, pero no lo encontró todavía.

Actualizar . Tablas planas son OFF

Y ahora la parte mala: Un poco

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

en la foreach de las correcciones product/list.phtml problema; -)

Para ser honesto:. Creo que he roto algo en la base de datos mientras se cambia la configuración o directamente en las tablas

¿Hay alguna conexión entre atributos y tiendas
Cualquier ideas sobre este problema?

¿Fue útil?

Solución 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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top