2

I have to get some attributes for each product I've gotten most of them but I don't know how to get manufacturer name and the upc or ean barcode value in adminhtml.

I've tried with this code

         $name = 'Manufacturer';
         $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
         $attributeId = $attributeInfo->getAttributeId(81);
         $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
         $attributeOptions = $attribute ->getSource()->getAllOptions(false);
         var_dump($attribute);

But I can Just print (like in the image) $attribute level and then the $attributeOptions goes empty.

enter image description here

4
  • From where do you need to get manufacturer name?
    – John
    Jun 29, 2017 at 5:48
  • @John I try to get collection (catalog/product) I can get sku, size, price, stock, description, name,qty... but I need to get also Brand/manufacturer and UPC/EAN barcode those I don't know how to can get them in magento 1.9
    – javaTodev
    Jun 29, 2017 at 14:48
  • Are you using flat catalog? Is the attribute set to be visible in product list? Did you reindex?
    – ProxiBlue
    Jun 29, 2017 at 23:14
  • @javaTodev, did you try using Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
    – John
    Jun 30, 2017 at 3:41

3 Answers 3

4
$productId='your_product_id';
$product=Mage::getModel('catalog/product')->load($productId);

$manufaturer=$product->getAttributeText('manufacturer');
3
  • I put it like this $produit = Mage::getModel('catalog/product')->load(231); var_dump($produit->getAttributeText('manufacturer')); but result I receive is bool(false) only.
    – javaTodev
    Jun 29, 2017 at 14:45
  • @javaTodev I think your attribute named manufaturer is yes/no attribute. If your manufacturer attribute is having different code then you have to put that code in the qoutes. Jun 30, 2017 at 8:57
  • I've updated the post to see how I can get with a similar code.
    – javaTodev
    Jul 3, 2017 at 14:49
2
$name = 'manufacturer';

    $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($name)->getFirstItem();
    $attributeId = $attributeInfo->getAttributeId();
    $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
    $attributeOptions = $attribute ->getSource()->getAllOptions(false);

    foreach ($attributeOptions as $_option){
        echo $_option['label'];

        $productcollection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter($name, $_option['value']);

        foreach ($productcollection as $_product){
            echo $_product->getName();
        }
    }
5
  • as mentioned in the comment up I cannot get the manufacturer like this.
    – javaTodev
    Jun 29, 2017 at 14:46
  • @javaTodev - now you can check my updated code above
    – Jjo
    Jun 29, 2017 at 14:52
  • Nothing . The field should be created or something like that? because I download a local version magento v1.9 but I didn't change nothing. In which table can I find the Manufacturer/brand value in Database?
    – javaTodev
    Jun 29, 2017 at 15:16
  • @javatodev Did you assign the attribute to attribute set?
    – Jjo
    Jun 29, 2017 at 16:52
  • Is it the "attribute_set_id" ? because using this I doesn't work for me. I use a default version of magento1.9 That I have in localhost. So I don't know if you are sure about the manufacturer exist already for default products, and in which table I can find them?
    – javaTodev
    Jul 2, 2017 at 23:41
1

Try:

<?php $attributes = $_product->getAttributes(); $Manufacturer = $attributes['manufacturer']->getFrontend()->getValue($_product); echo $Manufacturer; ?>

Your Answer

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

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