AD0-E724 · Question #62
A developer is tasked with programmatically updating the stock level of 5,000 products. Direct SQL updates are forbidden. What is the most performant, recommended Adobe Commerce pattern for this type
The correct answer is B. Use the '\Magento\Catalog\Model\Product\Action' class and its 'updateAttributes' method to update. \Magento\Catalog\Model\Product\Action::updateAttributes is correct because it performs a single bulk SQL UPDATE under the hood - it accepts an array of product IDs, an array of attribute changes, and a store ID, updating all records in one efficient operation without loading indi
Question
A developer is tasked with programmatically updating the stock level of 5,000 products. Direct SQL updates are forbidden. What is the most performant, recommended Adobe Commerce pattern for this type of mass update on a single entity attribute?
Options
- AUse the REST API to send 5,000 individual 'PUT /V1/products/{sku}' requests.
- BUse the '\Magento\Catalog\Model\Product\Action' class and its 'updateAttributes' method to update
- CCreate a data patch that iterates through each product, loads it, and saves the stock data.
- DLoop through each product ID, load the full product object via the 'ProductRepository', set the new
How the community answered
(28 responses)- A7% (2)
- B75% (21)
- C4% (1)
- D14% (4)
Explanation
\Magento\Catalog\Model\Product\Action::updateAttributes is correct because it performs a single bulk SQL UPDATE under the hood - it accepts an array of product IDs, an array of attribute changes, and a store ID, updating all records in one efficient operation without loading individual product objects. This is Adobe Commerce's purpose-built mechanism for mass attribute updates when direct SQL is off-limits.
Why the distractors fail:
- A - 5,000 individual REST calls means 5,000 round trips plus full request/response overhead per product; REST is designed for external integrations, not internal bulk ops.
- C - A data patch iterating + loading + saving each product triggers the full product save pipeline (observers, indexers, validators) 5,000 times, making it extremely slow and resource-intensive.
- D - Loading via
ProductRepositoryhydrates the entire product object (all EAV attributes, extension attributes, etc.) per product - same problem as C, just worse memory usage.
Memory tip: Think of Product\Action::updateAttributes as the "surgical scalpel" - it touches only the columns you specify across all rows at once, while repository load/save is the "full-body exam" you don't need when you're just updating one field.
Topics
Community Discussion
No community discussion yet for this question.