I am trying to get attribute value "barcode" for child product in magento2.

Below code working for cofigurable parent product.

$_product = $this->getProduct();
$_barcattr = $_product->getResource()->getAttribute('barcode');
$_barcode = $_barcattr->getFrontend()->getValue($_product);
echo $_barcode;

But i'm trying to get barcode for child product. Below code shows error.

$_children = $_product->getTypeInstance()->getUsedProducts($_product);
foreach ($_children as $child){ 
$_childbar = $child->getResource()->getAttribute('barcode');
$childatt = $_childbar->getFrontend()->getValue($child);

Please le me know how to get barcode value..

1 Answer 1


Mark the attribute "barcode" as "Used in product listing": "Yes" and you should be able to get it as you are already trying. When retrieving the simple products from a configurable product, only the attributes marked as "used in product listing" are loaded

  • Thank you @Marius
    – Priya
    Jul 19, 2021 at 13:02

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.