2

i'm trying to read the attribute set id from a product on a custom page. So if the article belongs to attribute set named "Hose" i want to get the custom attribute gtabelle_hose. if the article belongs to the attribute set named "Rock" the custom attribute "gtabelle_rock".

At this time i'm using this code

$product = Mage::getModel('catalog/product')->load(16);

$eavConfig = Mage::getModel('eav/config');
/* @var $eavConfig Mage_Eav_Model_Config */

$attributes = $eavConfig->getEntityAttributeCodes(
    Mage_Catalog_Model_Product::ENTITY,
    $product
);

but all of my attribute sets are in the array $attributes.

Thanks for your help.

1
9

Try this.

     // Get product.
        $product = Mage::getModel('catalog/product')->load(16);

        // Get attribute set model.
        $model = Mage::getModel('eav/entity_attribute_set');

        // Get attribute set id.
        $attributeSetId = $product->getAttributeSetId();
        $attributeSet = $model->load($attributeSetId);

// This is attribute set name.
        $attributeSetName = $attributeSet->getAttributeSetName();
4
  • This doesn't work to :( Maybe its my fault, i have to add this code to my phtml file, hadn't i?
    – AndreS
    Oct 21 '13 at 15:47
  • @AndreS : Did you check the above code after I edited it? I tested this code. It worked. If you are sure about your code put it here. We'll check what is the issue.
    – Sukeshini
    Oct 21 '13 at 16:40
  • This is my code. With echo i get no message and with var_dump($attributeSetName) i get NULL How get i the code displayed like you? code <?php // Get product. $product = Mage::getModel('catalog/product')->load(16); // Get attribute set model. $model = Mage::getModel('eav/entity_attribute_set'); // Get attribute set id. $attributeSetId = $product->getAttributeSetId(); $attributeSet = $model->load($attributeSetId); // This is attribute set name. $attributeSetName = $attributeSet->getAttributeSetName(); var_dump($attributeSetName); $_name = $this->getProduct()->getName(); ?>code`
    – AndreS
    Oct 21 '13 at 17:16
  • 2
    @AndreS : I tested your code. It prints 'Deafalut'. Make sure that there is a product with id 16. Just var_dump($product->getData()) and see.
    – Sukeshini
    Oct 22 '13 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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