0

i need show value the hardness attribute is type text

The code:

<?php

require_once("app/Mage.php");

Mage::app();

$products = Mage::getModel('catalog/product')->getCollection();

foreach($products as $product)  
{

    $sku = $product->getSku();
    if($sku == '5555')
    {
        echo '<pre>';

        $x = $product->getResource();
        $y = $x->getAttribute('name');
        $z = $y->getSource();
        $attr = $z->getAttribute('name');
        echo get_class($attr);
        echo "Nombre: ".$attr->getName()." ID: ".$attr->getId();
        echo "<br />-----------------------------------------------------------------------------------------------<br />";
        echo '</pre>';
    }
}
3
  • can not understand your question>plz explaing
    – Amit Bera
    Oct 2, 2015 at 8:16
  • Do you want hardness product attribute value or do you want all details of an attribute hardness? Oct 2, 2015 at 9:02
  • I need the attribute value Oct 7, 2015 at 13:18

2 Answers 2

0
$products =Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('hardness');

foreach($products as $product)  
{
  echo $product->getHardness();     
}
0

you have to load product to get product attribute.

<?php

    require_once("app/Mage.php");

    Mage::app();

    $products = Mage::getModel('catalog/product')->getCollection();

    foreach($products as $product)  
    {
    $product=Mage::getModel('catalog/product')->load($product->getId());

        $sku = $product->getSku();
        if($sku == '5555')
        {
            echo '<pre>';

            $x = $product->getResource();
            $y = $x->getAttribute('name');
            $z = $y->getSource();
            $attr = $z->getAttribute('name');
            echo get_class($attr);
            echo "Nombre: ".$attr->getName()." ID: ".$attr->getId();
            echo "<br />-----------------------------------------------------------------------------------------------<br />";
            echo '</pre>';
        }
    }

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.