2

I found that sku is not being displayed in product listing nor product view page. I checked and found that the template is checking whether to display the attribute by using:

$_product->getResource()->getAttribute('sku')->getUsedInProductListing()

Which results with null for sku but not for, lets say, description. I found out that more attributes have very short list of options (name also has this problem).

I have dumped the $_data in Varien_Object and for sku it is suprisingly short:

array (
  'attribute_id' => '68',
  'entity_type_id' => '4',
  'attribute_code' => 'sku',
  'attribute_model' => 'catalog/resource_eav_attribute',
  'backend_model' => 'catalog/product_attribute_backend_sku',
  'backend_type' => 'static',
  'backend_table' => NULL,
  'frontend_model' => NULL,
  'frontend_input' => 'text',
  'frontend_label' => 'SKU',
  'frontend_class' => NULL,
  'source_model' => NULL,
  'is_required' => '1',
  'is_user_defined' => '0',
  'default_value' => NULL,
  'is_unique' => '1',
  'note' => NULL,
  'store_label' => 'Product code',
)

However, the same dump for description attribute has much more options:

array (
  'attribute_id' => '66',
  'entity_type_id' => '4',
  'attribute_code' => 'description',
  'attribute_model' => 'catalog/resource_eav_attribute',
  'backend_model' => NULL,
  'backend_type' => 'text',
  'backend_table' => NULL,
  'frontend_model' => NULL,
  'frontend_input' => 'textarea',
  'frontend_label' => 'Description',
  'frontend_class' => NULL,
  'source_model' => NULL,
  'is_required' => '0',
  'is_user_defined' => '0',
  'default_value' => NULL,
  'is_unique' => '0',
  'note' => NULL,
  'frontend_input_renderer' => NULL,
  'is_global' => '0',
  'is_visible' => '1',
  'is_searchable' => '1',
  'is_filterable' => '0',
  'is_comparable' => '1',
  'is_visible_on_front' => '0',
  'is_html_allowed_on_front' => '1',
  'is_used_for_price_rules' => '0',
  'is_filterable_in_search' => '0',
  'used_in_product_listing' => '0',
  'used_for_sort_by' => '0',
  'is_configurable' => '1',
  'apply_to' => NULL,
  'is_visible_in_advanced_search' => '0',
  'position' => '0',
  'is_wysiwyg_enabled' => '1',
  'is_used_for_promo_rules' => '0',
  'entity_type' => 
  Mage_Eav_Model_Entity_Type::__set_state(array(
     '_attributes' => NULL,
     '_attributesBySet' => 
    array (
    ),
     '_sets' => NULL,
     '_eventPrefix' => 'core_abstract',
     '_eventObject' => 'object',
     '_resourceName' => 'eav/entity_type',
     '_resource' => NULL,
     '_resourceCollectionName' => 'eav/entity_type_collection',
     '_cacheTag' => false,
     '_dataSaveAllowed' => true,
     '_isObjectNew' => NULL,
     '_data' => 
    array (
      'entity_type_id' => '4',
      'entity_type_code' => 'catalog_product',
      'entity_model' => 'catalog/product',
      'attribute_model' => 'catalog/resource_eav_attribute',
      'entity_table' => 'catalog/product',
      'value_table_prefix' => NULL,
      'entity_id_field' => NULL,
      'is_data_sharing' => '1',
      'data_sharing_key' => 'default',
      'default_attribute_set_id' => '4',
      'increment_model' => NULL,
      'increment_per_store' => '0',
      'increment_pad_length' => '8',
      'increment_pad_char' => '0',
      'additional_attribute_table' => 'catalog/eav_attribute',
      'entity_attribute_collection' => 'catalog/product_attribute_collection',
    ),
     '_hasDataChanges' => true,
     '_origData' => NULL,
     '_idFieldName' => 'entity_type_id',
     '_isDeleted' => false,
     '_oldFieldsMap' => 
    array (
    ),
     '_syncFieldsMap' => 
    array (
    ),
  )),
)

Any ideas why this happens? I am using Magento 1.9.1.0

4
  • Have you set "Visible on Product View Page on Front-end" to "Yes"? Seems it's not returning 'sku' because getUsedInProductListing() == false Commented May 16, 2015 at 15:09
  • As I said, getUsedInProductListing() returns null because such option of attribute sku doesn't even exist in $_data for some reason. But yes, everything is set to 'YES' in sku attribute and the list of options in $_data is still shorter than in any other attribute.
    – Cleankod
    Commented May 16, 2015 at 16:22
  • Go to your admin, Catalog >> Attributes >> Manage Attributes. Then edit the 'sku' attribute. Change the "Used in Product Listing" from 'No' to 'Yes'. You will then have access to it from the product object Commented May 16, 2015 at 16:36
  • As I said, this setting is turned on for this attribute. And anyway, it should return either '1' or '0', not null. Take a closer look at the variable dumps in my post - it clearly means that sku is missing some options that other attributes normally have.
    – Cleankod
    Commented May 16, 2015 at 22:00

1 Answer 1

0

The difference in values is because the SKU and the Description are attributes with different back-end models. The SKU is a Static attribute, its value is stored directly in the catalog_product_entity table. The description is a text attribute its values are stored in the catalog_product_entity_text table.

If you switch the Used in Product Listing to yes the below snippet will return a value of 1.

used in product listing can be found in Catalog-> Attributes->Manage Attribute under the Frontend properties of the selected attribute

$_product->getResource()->getAttribute('sku')->getUsedInProductListing()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.