Get custom attribute from product in Magento 1.9

Get custom attribute from product in Magento 1.9

July 12, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Get custom attribute from product in Magento 1.9

Fetching Custom Attributes from Products in Magento 1.9

In Magento 1.9, retrieving product data based on SKU is a straightforward process. However, when it comes to fetching custom attributes like ‘sku_supplier’, the method requires some additional steps.

Understanding Your Current Code Structure

Your current code effectively loads a product collection filtered by SKU and status. It then retrieves basic product information such as name and SKU using the getName() and getSku() methods, respectively. However, when attempting to access the custom attribute ‘sku_supplier’ with $product->getSku_Supplier(), Magento fails to recognize it because the attribute is not being explicitly selected.

Selecting Custom Attributes in Magento

To retrieve a custom attribute like ‘sku_supplier’, you need to tell Magento that you want this specific attribute included in your collection. This can be done by adding the attribute to the select statement using the addAttributeToSelect() method.

Here’s how you can modify your code:

require $_SERVER['DOCUMENT_ROOT'] . "/app/Mage.php";
Mage::app();

$sku = '748547';

// Initialize the product collection and select required attributes
$products = Mage::getResourceModel('catalog/product_collection');
$products->addAttributeToSelect(array('name', 'sku', 'sku_supplier')); // Add the custom attribute here

// Filters remain unchanged for simplicity
$products->addAttributeToFilter('visibility', array('neq' => 1));
$products->addAttributeToFilter('status', 1);
$products->addAttributeToFilter('sku', $sku);

$products->setCurPage(1)->setPageSize(1);

// Load the collection
$products->load();

// Check if a product was found
if ($products->getFirstItem()) {
    $product = $products->getFirstItem();

    // Now you can access the custom 'sku_supplier' attribute
    $strProdName   = $product->getName();
    $strProdSku    = $product->getSku();
    $strProdSkuSup = $product->getSkuSupplier(); 

    // Note: The naming convention for getting an attribute is 'getAttributeName()'
}else{
    $addError          = 'true';
    $addErrorMessage[] = 'Error...';
}

A Word on Performance Optimization

While this approach works, it’s important to note that loading all product attributes can be resource-intensive. In a production environment with many products and numerous custom attributes, consider using Magento’s Index Management system for better performance.

For more advanced use cases and best practices in Magento 1.x development, I recommend exploring the official documentation.

Conclusion

Retrieving a product’s custom attribute like ‘sku_supplier’ requires explicitly selecting that attribute when building your collection. With this modification to your code, you should now be able to fetch and display the desired supplier SKU alongside other product details.

Remember, understanding Magento’s data models and how it selects attributes is key to efficient development. For more complex needs or if you’re looking to upgrade to a modern platform like Laravel for backend services, check out our comprehensive guides at LaravelCompany.com.

Magento 1 Catalog

Our network