Skip to content

[\Magento\ConfigurableProduct\Model\Product\Type\Configurable] PHP error unoticed #39641

@bhennesAdv

Description

@bhennesAdv

Summary

Hello,

My phpstorm detected an error in a Preference I had to declare copying the entire \Magento\ConfigurableProduct\Model\Product\Type\Configurable.
The following function has an issue because $product variable is used by the loop as looping element erasing the given variable.
The function is deprecated but I still think it's a quick correction.

public function getUsedProductIds($product) // <= $product is defined here { if (!$product->hasData($this->_usedProductIds)) { $usedProductIds = []; foreach ($this->getUsedProducts($product) as $product) { // <= $product is overriden by loop $usedProductIds[] = $product->getId(); } $product->setData($this->_usedProductIds, $usedProductIds); // $product here is the last used product of the given product } return $product->getData($this->_usedProductIds); // Returned list is OK but the "cache" effect never occurs as the data is not set on the given product }

Examples

Not sure if an example is relevant as the only thing that would change is the time consumed by the calls when multiple calls are made on the same object

Proposed solution

Just change the variable name is the loop ?

Release note

Correction of cache usage on configurable product models when getUsedProductIds is used multiple times on the same model

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Labels

Area: CatalogComponent: ConfigurableProductIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReported on 2.4.xIndicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions