1

Faced with strange issue : trying to get all product attributes with:

Mage::getModel('catalog/product')->getAttributes();

but can't see some of them which was created in backend by user, although I can see them with

Mage::getResourceModel('catalog/product_attribute_collection')->getItems();

What is the difference, and what makes these custom attributes created in backed so special ?

Also, I exported these attributes (with Alan Storm script) in install script for purpose to use them in testing (EcomDev Phpunit), and they where created, but still having issue with "seeing" them.

exported attribute example code:

       $attr = array (
            'attribute_model' => NULL,
            'backend' => NULL,
            'type' => 'varchar',
            'table' => NULL,
            'frontend' => NULL,
            'input' => 'text',
            'label' => 'The money will not be returned',
            'frontend_class' => 'validate-digits',
            'source' => NULL,
            'required' => '0',
            'user_defined' => '1',
            'default' => NULL,
            'unique' => '0',
            'note' => NULL,
            'input_renderer' => NULL,
            'global' => '1',
            'visible' => '1',
            'searchable' => '0',
            'filterable' => '0',
            'comparable' => '0',
            'visible_on_front' => '0',
            'is_html_allowed_on_front' => '1',
            'is_used_for_price_rules' => '0',
            'filterable_in_search' => '0',
            'used_in_product_listing' => '0',
            'used_for_sort_by' => '0',
            'is_configurable' => '0',
            'apply_to' => 'virtual',
            'visible_in_advanced_search' => '0',
            'position' => '0',
            'wysiwyg_enabled' => '0',
            'used_for_promo_rules' => '0',
            'option' =>
                array (
                    'values' =>
                        array (
                        ),
                ),
        );
        $this->addAttribute('catalog_product','no_moneyback_before_event',$attr);

var dump of this example custom created, "magic" attribute. :

object(Mage_Catalog_Model_Resource_Eav_Attribute)[80]
      protected '_eventPrefix' => string 'catalog_entity_attribute' (length=24)
      protected '_eventObject' => string 'attribute' (length=9)
      protected '_cacheTag' => string 'EAV_ATTRIBUTE' (length=13)
      protected '_name' => null
      protected '_entity' => null
      protected '_backend' => null
      protected '_frontend' => null
      protected '_source' => null
      protected '_attributeIdCache' => 
        array (size=0)
          empty
      protected '_dataTable' => null
      protected '_resourceName' => string 'catalog/attribute' (length=17)
      protected '_resource' => null
      protected '_resourceCollectionName' => string 'catalog/attribute_collection' (length=28)
      protected '_dataSaveAllowed' => boolean true
      protected '_isObjectNew' => null
      protected '_data' => 
        array (size=35)
          'entity_type_id' => string '4' (length=1)
          'attribute_code' => string 'no_moneyback_before_event' (length=25)
          'attribute_model' => null
          'backend_model' => null
          'backend_type' => string 'varchar' (length=7)
          'backend_table' => null
          'frontend_model' => null
          'frontend_input' => string 'text' (length=4)
          'frontend_label' => string 'The money will not be returned' (length=30)
          'frontend_class' => string 'validate-digits' (length=15)
          'source_model' => null
          'is_required' => string '0' (length=1)
          'is_user_defined' => string '1' (length=1)
          'default_value' => null
          'is_unique' => string '0' (length=1)
          'note' => null
          'attribute_id' => string '163' (length=3)
          'frontend_input_renderer' => null
          'is_global' => string '1' (length=1)
          'is_visible' => string '1' (length=1)
          'is_searchable' => string '0' (length=1)
          'is_filterable' => string '0' (length=1)
          'is_comparable' => string '0' (length=1)
          'is_visible_on_front' => string '0' (length=1)
          'is_html_allowed_on_front' => string '1' (length=1)
          'is_used_for_price_rules' => string '0' (length=1)
          'is_filterable_in_search' => string '0' (length=1)
          'used_in_product_listing' => string '0' (length=1)
          'used_for_sort_by' => string '0' (length=1)
          'is_configurable' => string '0' (length=1)
          'apply_to' => string 'virtual' (length=7)
          'is_visible_in_advanced_search' => string '0' (length=1)
          'position' => string '0' (length=1)
          'is_wysiwyg_enabled' => string '0' (length=1)
          'is_used_for_promo_rules' => string '0' (length=1)

Would love to hear any explanations or hints, where to dig.

Thank you !

1 Answer 1

1

It was required to add attribute to specific attribute_set (for product it this case).

$attribute = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product', 'no_moneyback_before_event'); $attribute->setStoreLabels(array()); $attribute->save(); $this->addAttributeToSet($entityTypeId, 4, "General", $attribute->getId());

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.