Skip to content

Parameter $requiredAttributeIds of getUsedProducts() on configurable product type is not used, custom attribute loading does not work #24483

@sippsolutions

Description

@sippsolutions

Preconditions (*)

  1. Magento Version 2.3.2

Steps to reproduce (*)

  1. Try to load custom attribute's value from \Magento\ConfigurableProduct\Model\Product\Type\Configurable::getUsedProducts()
    Parameters are $product, $requiredAttributeIds

Expected result (*)

  1. The attributes in $requiredAttributeIds get loaded and their values are accessible after loading

Actual result (*)

  1. You only have to look at the code to know the parameter does not get used for loading, it just gets used for the cache key!
    /**
     * Returns array of sub-products for specified configurable product
     *
     * $requiredAttributeIds - one dimensional array, if provided
     *
     * Result array contains all children for specified configurable product
     *
     * @param  \Magento\Catalog\Model\Product $product
     * @param  array $requiredAttributeIds
     * @return ProductInterface[]
     */
    public function getUsedProducts($product, $requiredAttributeIds = null)
    {
        $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
        $keyParts = [
            __METHOD__,
            $product->getData($metadata->getLinkField()),
            $product->getStoreId(),
            $this->getCustomerSession()->getCustomerGroupId()
        ];
        if ($requiredAttributeIds !== null) {
            sort($requiredAttributeIds);
            $keyParts[] = implode('', $requiredAttributeIds);
        }
        $cacheKey = $this->getUsedProductsCacheKey($keyParts);
        return $this->loadUsedProducts($product, $cacheKey);
    }

Metadata

Metadata

Assignees

Labels

Component: ConfigurableProductComponent: Framework/CodeFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions