I need to get several info from each single product in the catalog, so I used the Magento\Catalog\Model\ResourceModel\Product\CollectionFactory to get a collection of products.
Iterating through them I notice I cannot get all the data related to each product.
E.g.
In the last example $product->getData('quantity_and_stock_status'), if I load the product with Magento\Catalog\Model\Product, then instead of returning 1, I get an array with 2 values qty and is_in_stock, which is what I want.
Just a quick note, loading each product with `Magento\Catalog\Model\Product` is taking ages, so I'd avoid it.
Is it possible having all the info related to the product with the Product\CollectionFactory?
You can use Magento\Catalog\Api\ProductRepositoryInterface
public function __construct( \Magento\Catalog\Api\ProductRepositoryInterface $productRepository ) { $this->productRepository = $productRepository; }
Now get the product data by get($sku) method.
Check link by SKU, https://www.rakeshjesadiya.com/how-to-get-product-collection-by-product-sku-in-magento-2/
By Product Id load product object,
https://www.rakeshjesadiya.com/how-to-get-product-collection-by-product-id-in-magento-2/
Hey Rakesh,
Thanks for your reply.
Unfortunately, loading products one by one, will take ages for loading and processing a big catalog.
As far as you know, is there any way I can do get all the info of all the products with less DB calls as possible?