Search code examples
magentomagento2magento2.2

Magento 2.2: Child product of Configurable product missing attributes


When I examine the contents of $product->getData() for a regular product, all the attributes I set in the admin appear to be there. But when I examine the contents of $product->getData() for a child product inside a configurable product, many of the values set in the admin seem to be missing.

Is there something obvious that I'm missing?

For the product class, I'm referring to \Magento\Catalog\Model\Product.

Edit: If I make the child product visible on its own and navigate to its page, I can see that all of its attributes are loaded. By contrast, when I get a list of all child products (classes which don't seem to contain all the attributes I set in the admin), this is the way I'm loading them from within a class that overrides \Magento\Swatches\Block\Product\Renderer\Configurable:

$this->getProduct()->getTypeInstance()->getUsedProducts($this->getProduct())

I'm guessing there's something different that occurs when the product classes get instantiated this way that's causing my issue.

Please forgive my newbness. I'm still very new to Magento and am trying to find my way around. Thanks!


Solution

  • After a lot of digging, I found this function definition in the Configurable Product model:

    public function getUsedProducts($product, $requiredAttributeIds = null)
    

    It looks like I have to pass in the desired attribute ids in order to load the data I'm later trying to read in my template.